Exemplo n.º 1
0
        public async Task Login_BadPassword()
        {
            //Arrange
            var users           = FakeModelsRepository.GetFakeUsers();
            var ipAddress       = FakeModelsRepository.GetFakeIpAddress();
            var dbContextMock   = MockInjectedServices.GetMockDbContext(users, ipAddress);
            var memoryCacheMock = MockInjectedServices.GetMockmemoryCache();

            var service           = new AuthService(dbContextMock.Object, memoryCacheMock.Object);
            var loginModel        = FakeModelsRepository.GetFakeLoginModel(FakeModelsRepository.UserExistLogin, "BadPassword");
            var cancellationToken = new CancellationToken();

            //Act
            var result = await service.Login(loginModel, cancellationToken);

            //Assert
            Assert.False(result.Success);
        }
Exemplo n.º 2
0
        public async Task Login_ShouldSignInAfterBlockFor10Second()
        {
            //Arrange
            var users           = FakeModelsRepository.GetFakeUsers(3, DateTime.Now, DateTime.Now, DateTime.Now.AddSeconds(-10));
            var ipAddress       = FakeModelsRepository.GetFakeIpAddress();
            var dbContextMock   = MockInjectedServices.GetMockDbContext(users, ipAddress);
            var memoryCacheMock = MockInjectedServices.GetMockmemoryCache();

            var service           = new AuthService(dbContextMock.Object, memoryCacheMock.Object);
            var loginModel        = FakeModelsRepository.GetFakeLoginModel();
            var cancellationToken = new CancellationToken();

            //Act
            var result = await service.Login(loginModel, cancellationToken);

            //Assert
            Assert.True(result.Success);
        }
Exemplo n.º 3
0
        public async Task Login_IPBannedPermanently()
        {
            //Arrange
            var users           = FakeModelsRepository.GetFakeUsers(3, DateTime.Now, DateTime.Now, DateTime.Now.AddSeconds(-10));
            var ipAddress       = FakeModelsRepository.GetFakeIpAddress("10.10.10.10", 4, true);
            var dbContextMock   = MockInjectedServices.GetMockDbContext(users, ipAddress);
            var memoryCacheMock = MockInjectedServices.GetMockmemoryCache();

            var service           = new AuthService(dbContextMock.Object, memoryCacheMock.Object);
            var loginModel        = FakeModelsRepository.GetFakeLoginModel();
            var cancellationToken = new CancellationToken();

            //Act
            var result = await service.Login(loginModel, cancellationToken);

            //Assert
            Assert.False(result.Success);
        }
Exemplo n.º 4
0
        public async Task Login_BlockFor10Second()
        {
            //Arrange
            var users           = FakeModelsRepository.GetFakeUsers(3, DateTime.Now, DateTime.Now, DateTime.Now.AddSeconds(10));
            var ipAddress       = FakeModelsRepository.GetFakeIpAddress();
            var dbContextMock   = MockInjectedServices.GetMockDbContext(users, ipAddress);
            var memoryCacheMock = MockInjectedServices.GetMockmemoryCache();

            var service           = new AuthService(dbContextMock.Object, memoryCacheMock.Object);
            var loginModel        = FakeModelsRepository.GetFakeLoginModel(FakeModelsRepository.UserExistLogin, "BadPassword");
            var cancellationToken = new CancellationToken();

            //Act
            var result = await service.Login(loginModel, cancellationToken);

            //Assert
            Assert.False(result.Success);
            Assert.Equal("Your account is block for 10 seconds", result.Messege);
        }