1
プライベートメソッドを呼び出し、パブリックメソッドを呼び出すビジネスロジック:テスト内部で、私はそうのようなインタフェースのメソッドを持って
Task<bool> IsStudentAuthorizedAsync(StudentEntity studentEntity);
実装:
public async Task<bool> IsStudentAuthorizedAsync(StudentEntity studentEntity)
{
// Check if the Student is activated for course
var checkStudentForCourseTask = await this.CheckIfStudentIsEnabledForCourseAsync(studentEntity).ConfigureAwait(false);
return checkStudentForCourseTask;
}
private async Task<bool> CheckIfStudentIsEnabledForCourseAsync(StudentEntity studentEntity)
{
var result = await this.tableStorage.RetrieveAsync<StudentTableEntity>(StudentEntity.Id, StudentEntity.CourseId, this.tableName).ConfigureAwait(false);
return result != null && result.IsActivated;
}
CheckIfStudentIsEnabledForCourseAsyncがプライベートな方法であることAzure Table Storageを照会してチェックします。
私はユニットテストIsStudentAuthorizedAsyncを試みていますが、初期セットアップコールの後には移動できません。
[TestClass]
public class AuthorizeStudentServiceBusinessLogicTests
{
private Mock<IAuthorizeStudentServiceBusinessLogic> authorizeStudentServiceBusinessLogic;
[TestMethod]
public async Task IsStudentAuthorizedForServiceAsyncTest()
{
this.authorizeStudentServiceBusinessLogic.Setup(
x => x.IsStudentAuthorizedAsync(It.IsAny<StudentEntity>()))
.Returns(new Task<bool>(() => false));
// What to do next!!!
}
}
ご協力いただきまして誠にありがとうございます。 ありがとうございます。
よろしくお願いいたします。