Example #1
0
        public async Task CreateLoginAttempts_ExecutionTimeLessThan400Milliseconds
            (int loginAttemptId, string ipAddress, int loginCounter, string suspensionEndTime, long expectedMaxExecutionTime)
        {
            // Arrange
            ILoginAttemptsRepository loginAttemptsRepository = new LoginAttemptsRepository
                                                                   (new SQLServerGateway(), new ConnectionStringData());

            LoginAttemptsModel loginAttemptsModel = new LoginAttemptsModel();

            loginAttemptsModel.Id                = loginAttemptId;
            loginAttemptsModel.IpAddress         = ipAddress;
            loginAttemptsModel.LoginCounter      = loginCounter;
            loginAttemptsModel.SuspensionEndTime = DateTimeOffset.Parse(suspensionEndTime);

            // Act
            var timer = Stopwatch.StartNew();
            await loginAttemptsRepository.CreateLoginAttempts(loginAttemptsModel);

            timer.Stop();

            var actualExecutionTime = timer.ElapsedMilliseconds;

            Debug.WriteLine("Actual Execution Time: " + actualExecutionTime);

            // Assert
            Assert.IsTrue(actualExecutionTime <= expectedMaxExecutionTime);
        }
Example #2
0
        public async Task CreateLoginAttempts_IpAddressDoesntExist_DataIsAccurate
            (int expectedId, string expectedIpAddress, int expectedLoginCounter, string expectedSuspensionEndTime)
        {
            // Arrange
            ILoginAttemptsRepository loginAttemptsRepository = new LoginAttemptsRepository
                                                                   (new SQLServerGateway(), new ConnectionStringData());

            LoginAttemptsModel loginAttemptsModel = new LoginAttemptsModel();

            loginAttemptsModel.Id                = expectedId;
            loginAttemptsModel.IpAddress         = expectedIpAddress;
            loginAttemptsModel.LoginCounter      = expectedLoginCounter;
            loginAttemptsModel.SuspensionEndTime = DateTimeOffset.Parse(expectedSuspensionEndTime);

            // Act
            await loginAttemptsRepository.CreateLoginAttempts(loginAttemptsModel);

            var actualLoginAttempt = await loginAttemptsRepository.GetLoginAttemptsById(expectedId);

            // Assert
            Assert.IsTrue
            (
                actualLoginAttempt.Id == expectedId &&
                actualLoginAttempt.IpAddress == expectedIpAddress &&
                actualLoginAttempt.LoginCounter == expectedLoginCounter &&
                actualLoginAttempt.SuspensionEndTime == DateTimeOffset.Parse(expectedSuspensionEndTime)
            );
        }
Example #3
0
        public async Task Init()
        {
            await TestCleaner.CleanDatabase();

            var numTestRows = 10;

            IDataGateway             dataGateway             = new SQLServerGateway();
            IConnectionStringData    connectionString        = new ConnectionStringData();
            ILoginAttemptsRepository loginAttemptsRepository = new LoginAttemptsRepository(dataGateway, connectionString);

            for (int i = 1; i <= numTestRows; ++i)
            {
                LoginAttemptsModel loginAttemptsModel = new LoginAttemptsModel();
                loginAttemptsModel.Id                = i;
                loginAttemptsModel.IpAddress         = "127.0.0." + i;
                loginAttemptsModel.LoginCounter      = i;
                loginAttemptsModel.SuspensionEndTime = DateTimeOffset.Parse("3/28/2007 7:13:50 PM +00:00");

                await loginAttemptsRepository.CreateLoginAttempts(loginAttemptsModel);
            }
        }