Example #1
0
        public async Task IncrementLoginCounterByIpAddress_IpExists_ReturnTrue(string ipAddress)
        {
            // Arrange
            IDataGateway             dataGateway             = new SQLServerGateway();
            IConnectionStringData    connectionString        = new ConnectionStringData();
            ILoginAttemptsRepository loginAttemptsRepository = new LoginAttemptsRepository(dataGateway, connectionString);

            var oldLoginAttemptsModel = await loginAttemptsRepository.GetLoginAttemptsByIpAddress(ipAddress);

            var expectedResult = true;

            ILoginAttemptsService loginAttemptsService = new LoginAttemptsService(loginAttemptsRepository);

            // Act
            var actualResult = await loginAttemptsService.IncrementLoginCounterByIpAddress(ipAddress);

            var newLoginAttemptsModel = await loginAttemptsRepository.GetLoginAttemptsByIpAddress(ipAddress);

            // Assert
            Assert.IsTrue
            (
                actualResult == expectedResult &&
                newLoginAttemptsModel.LoginCounter == (oldLoginAttemptsModel.LoginCounter + 1)
            );
        }
Example #2
0
        public async Task IncrementLoginCounterByIpAddress_LoginCounterIsAccurate(string ipAddress)
        {
            // Arrange
            ILoginAttemptsRepository loginAttemptsRepository =
                new LoginAttemptsRepository(new SQLServerGateway(), new ConnectionStringData());

            // Act
            var oldLoginAttempt = await loginAttemptsRepository.GetLoginAttemptsByIpAddress(ipAddress);

            await loginAttemptsRepository.IncrementLoginCounterByIpAddress(ipAddress);

            var newLoginAttempt = await loginAttemptsRepository.GetLoginAttemptsByIpAddress(ipAddress);

            // Assert
            Assert.IsTrue(newLoginAttempt.LoginCounter == (oldLoginAttempt.LoginCounter + 1));
        }
Example #3
0
        public async Task GetLoginAttemptsByIpAddress_LoginAttemptExists_IpAddressIsCorrect
            (string expectedIpAddress)
        {
            // Arrange
            ILoginAttemptsRepository loginAttemptsRepository =
                new LoginAttemptsRepository(new SQLServerGateway(), new ConnectionStringData());

            // Act
            var loginAttemptModel = await loginAttemptsRepository.GetLoginAttemptsByIpAddress(expectedIpAddress);

            var actualIpAddress = loginAttemptModel.IpAddress;

            // Assert
            Assert.IsTrue(actualIpAddress == expectedIpAddress);
        }
Example #4
0
        public async Task UpdateSuspensionEndTimeByIpAddress_SuspensionEndtimeIsAccurate(string ipAddress,
                                                                                         string expectedSuspensionEndTime)
        {
            // Arrange
            ILoginAttemptsRepository loginAttemptsRepository =
                new LoginAttemptsRepository(new SQLServerGateway(), new ConnectionStringData());

            // Act
            await loginAttemptsRepository.UpdateSuspensionEndTimeByIpAddress(ipAddress,
                                                                             DateTimeOffset.Parse(expectedSuspensionEndTime));

            var newLoginAttempt = await loginAttemptsRepository.GetLoginAttemptsByIpAddress(ipAddress);

            var actualSuspensionEndTime = newLoginAttempt.SuspensionEndTime;

            // Assert
            Assert.IsTrue(actualSuspensionEndTime == DateTimeOffset.Parse(expectedSuspensionEndTime));
        }