public async Task GetUserAccountCodeByAccountId_AccountIdExists_ReturnBusinessUserAccountCodeModel(int id, string code, string expirationTime, int accountId) { // Arrange IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserAccountCodeRepository userAccountCodeRepository = new UserAccountCodeRepository(dataGateway, connectionString); var expectedResult = new BusinessUserAccountCodeModel(); expectedResult.Id = id; expectedResult.Code = code; expectedResult.ExpirationTime = DateTimeOffset.Parse(expirationTime); expectedResult.UserAccountId = accountId; IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(userAccountCodeRepository); // Act var actualResult = await userAccountCodeService.GetUserAccountCodeByAccountId(accountId); // Assert Assert.IsTrue ( actualResult.Id == expectedResult.Id && actualResult.Code == expectedResult.Code && actualResult.ExpirationTime == expectedResult.ExpirationTime && actualResult.UserAccountId == expectedResult.UserAccountId ); }
public async Task GetUserAccountCodeByAccountId_AccountIdDoesntExists_ReturnNull(int accountId) { // Arrange IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserAccountCodeRepository userAccountCodeRepository = new UserAccountCodeRepository(dataGateway, connectionString); IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(userAccountCodeRepository); // Act var actualResult = await userAccountCodeService.GetUserAccountCodeByAccountId(accountId); // Assert Assert.IsNull(actualResult); }
public async Task GetUserAccountCodeByAccountId_AccountIdNotFound_ReturnNull(int accountId) { // Arrange // Setting up each dependency of LoginAttemptsService as a Mock Mock <IUserAccountCodeRepository> mockUserAccountCodeRepository = new Mock <IUserAccountCodeRepository>(); UserAccountCodeModel userAccountCodeModel = null; mockUserAccountCodeRepository.Setup(x => x.GetUserAccountCodeByAccountId(accountId)).Returns (Task.FromResult(userAccountCodeModel)); IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(mockUserAccountCodeRepository.Object); // Act var actualResult = await userAccountCodeService.GetUserAccountCodeByAccountId(accountId); // Assert Assert.IsNull(actualResult); }
public async Task GetUserAccountCodeByAccountId_AccountIdFound_ReturnBusinessUserAccountCodeModel(int id, string code, string expirationTime, int accountId) { // Arrange // Setting up each dependency of LoginAttemptsService as a Mock Mock <IUserAccountCodeRepository> mockUserAccountCodeRepository = new Mock <IUserAccountCodeRepository>(); var userAccountCodeModel = new UserAccountCodeModel(); userAccountCodeModel.Id = id; userAccountCodeModel.Code = code; userAccountCodeModel.ExpirationTime = DateTimeOffset.Parse(expirationTime); userAccountCodeModel.UserAccountId = accountId; var expectedResult = new BusinessUserAccountCodeModel(); expectedResult.Id = id; expectedResult.Code = code; expectedResult.ExpirationTime = DateTimeOffset.Parse(expirationTime); expectedResult.UserAccountId = accountId; mockUserAccountCodeRepository.Setup(x => x.GetUserAccountCodeByAccountId(accountId)).Returns (Task.FromResult(userAccountCodeModel)); IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(mockUserAccountCodeRepository.Object); // Act var actualResult = await userAccountCodeService.GetUserAccountCodeByAccountId(accountId); // Assert Assert.IsTrue ( actualResult.Id == expectedResult.Id && actualResult.Code == expectedResult.Code && actualResult.ExpirationTime == expectedResult.ExpirationTime && actualResult.UserAccountId == expectedResult.UserAccountId ); }