예제 #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)
            );
        }
예제 #2
0
        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
            );
        }
예제 #3
0
        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);
        }
예제 #4
0
        public async Task AddIpAddress_IpDoesntExist_ReturnTrue(string ipAddress, int loginCounter)
        {
            // Arrange
            IDataGateway             dataGateway             = new SQLServerGateway();
            IConnectionStringData    connectionString        = new ConnectionStringData();
            ILoginAttemptsRepository loginAttemptsRepository = new LoginAttemptsRepository(dataGateway, connectionString);

            var expectedResult = true;

            ILoginAttemptsService loginAttemptsService = new LoginAttemptsService(loginAttemptsRepository);

            // Act
            var actualResult = await loginAttemptsService.AddIpAddress(ipAddress, loginCounter);

            // Assert
            Assert.IsTrue(actualResult == expectedResult);
        }
예제 #5
0
        public async Task SetSuspensionEndTimeByIpAddress_IpExists_ReturnTrue(string ipAddress, int suspensionHours)
        {
            // Arrange
            IDataGateway             dataGateway             = new SQLServerGateway();
            IConnectionStringData    connectionString        = new ConnectionStringData();
            ILoginAttemptsRepository loginAttemptsRepository = new LoginAttemptsRepository(dataGateway, connectionString);

            var expectedResult = true;

            ILoginAttemptsService loginAttemptsService = new LoginAttemptsService(loginAttemptsRepository);

            // Act
            var actualResult = await loginAttemptsService.SetSuspensionEndTimeByIpAddress(ipAddress, suspensionHours);

            // Assert
            Assert.IsTrue(actualResult == expectedResult);
        }
        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
            );
        }