public async Task GetLoginAttemptsByIpAddress_IpExists_ReturnBusinessLoginAttemptsModel(int id, string ipAddress, int loginCounter, string suspensionEndtime) { // Arrange IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); ILoginAttemptsRepository loginAttemptsRepository = new LoginAttemptsRepository(dataGateway, connectionString); var expectedResult = new BusinessLoginAttemptsModel(); expectedResult.Id = id; expectedResult.IpAddress = ipAddress; expectedResult.LoginCounter = loginCounter; expectedResult.SuspensionEndTime = DateTimeOffset.Parse(suspensionEndtime); ILoginAttemptsService loginAttemptsService = new LoginAttemptsService(loginAttemptsRepository); // Act var actualResult = await loginAttemptsService.GetLoginAttemptsByIpAddress(ipAddress); // Assert Assert.IsTrue ( actualResult.Id == expectedResult.Id && actualResult.IpAddress == expectedResult.IpAddress && actualResult.LoginCounter == expectedResult.LoginCounter && actualResult.SuspensionEndTime == expectedResult.SuspensionEndTime ); }
public async Task GetLoginAttemptsByIpAddress_IpDoesNotExists_ReturnNull(string ipAddress) { // Arrange IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); ILoginAttemptsRepository loginAttemptsRepository = new LoginAttemptsRepository(dataGateway, connectionString); ILoginAttemptsService loginAttemptsService = new LoginAttemptsService(loginAttemptsRepository); // Act var actualResult = await loginAttemptsService.GetLoginAttemptsByIpAddress(ipAddress); // Assert Assert.IsNull(actualResult); }
public async Task GetLoginAttemptsByIpAddress_IpAddressNotFoundFound_ReturnNull(string ipAddress) { // Arrange // Setting up each dependency of LoginAttemptsService as a Mock Mock <ILoginAttemptsRepository> mockLoginAttemptsRepository = new Mock <ILoginAttemptsRepository>(); LoginAttemptsModel loginAttemptsModel = null; mockLoginAttemptsRepository.Setup(x => x.GetLoginAttemptsByIpAddress(ipAddress)).Returns (Task.FromResult(loginAttemptsModel)); ILoginAttemptsService loginAttemptsService = new LoginAttemptsService(mockLoginAttemptsRepository.Object); // Act var actualResult = await loginAttemptsService.GetLoginAttemptsByIpAddress(ipAddress); // Assert Assert.IsNull(actualResult); }
public async Task GetLoginAttemptsByIpAddress_IpAddressFound_ReturnBusinessLoginAttemptsModel(int id, string ipAddress, int loginCounter, string suspensionEndTime) { // Arrange // Setting up each dependency of LoginAttemptsService as a Mock Mock <ILoginAttemptsRepository> mockLoginAttemptsRepository = new Mock <ILoginAttemptsRepository>(); var loginAttemptsModel = new LoginAttemptsModel(); loginAttemptsModel.Id = id; loginAttemptsModel.IpAddress = ipAddress; loginAttemptsModel.LoginCounter = loginCounter; loginAttemptsModel.SuspensionEndTime = DateTimeOffset.Parse(suspensionEndTime); var expectedResult = new BusinessLoginAttemptsModel(); expectedResult.Id = id; expectedResult.IpAddress = ipAddress; expectedResult.LoginCounter = loginCounter; expectedResult.SuspensionEndTime = DateTimeOffset.Parse(suspensionEndTime); mockLoginAttemptsRepository.Setup(x => x.GetLoginAttemptsByIpAddress(ipAddress)).Returns (Task.FromResult(loginAttemptsModel)); ILoginAttemptsService loginAttemptsService = new LoginAttemptsService(mockLoginAttemptsRepository.Object); // Act var actualResult = await loginAttemptsService.GetLoginAttemptsByIpAddress(ipAddress); // Assert Assert.IsTrue ( actualResult.Id == expectedResult.Id && actualResult.IpAddress == expectedResult.IpAddress && actualResult.LoginCounter == expectedResult.LoginCounter && actualResult.SuspensionEndTime == expectedResult.SuspensionEndTime ); }