示例#1
0
        public async Task ChangePassword_Succesfull()
        {
            //Arrange
            var users           = FakeModelsRepository.GetFakeUsers();
            var dbContextMock   = MockInjectedServices.GetMockDbContext(users);
            var memoryCacheMock = MockInjectedServices.GetMockmemoryCache();

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

            //Act
            var result = await service.ChangePassword(changePasswordModel, cancellationToken);

            //Assert
            Assert.True(result.Success);
        }
示例#2
0
        public async Task AddPassword_NotFoundUser()
        {
            //Arrange
            var users             = FakeModelsRepository.GetFakeUsers();
            var dbContextMock     = MockInjectedServices.GetMockDbContext(users);
            var memoryCacheMock   = MockInjectedServices.GetMockmemoryCache(null);
            var authorizationMock = new Mock <IAuthorizationService>();

            var service           = new WalletService(dbContextMock.Object, memoryCacheMock.Object, authorizationMock.Object);
            var addPasswordModel  = FakeModelsRepository.GetFakeAddNewPasswordModel();
            var cancellationToken = new CancellationToken();

            //Act
            var result = await service.AddNewPassowrd(addPasswordModel, FakeModelsRepository.UserNotExistLogin, cancellationToken);

            //Assert
            Assert.False(result.Success);
        }
示例#3
0
        public async Task DeletePassword_Success()
        {
            //Arrange
            var users             = FakeModelsRepository.GetFakeUsers();
            var passwords         = FakeModelsRepository.GetFakePasswords();
            var dbContextMock     = MockInjectedServices.GetMockDbContext(users, passwords);
            var memoryCacheMock   = MockInjectedServices.GetMockmemoryCache(null);
            var authorizationMock = new Mock <IAuthorizationService>();

            var service           = new WalletService(dbContextMock.Object, memoryCacheMock.Object, authorizationMock.Object);
            var cancellationToken = new CancellationToken();

            //Act
            var result = await service.DeletePassword(new Guid(), new System.Security.Claims.ClaimsPrincipal(), cancellationToken);

            //Assert
            Assert.False(result.Success);
        }
示例#4
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);
        }
示例#5
0
        public async Task Register_NewLogin()
        {
            //Arrange
            var users           = FakeModelsRepository.GetFakeUsers();
            var dbContextMock   = MockInjectedServices.GetMockDbContext(users);
            var memoryCacheMock = MockInjectedServices.GetMockmemoryCache();

            var service           = new AuthService(dbContextMock.Object, memoryCacheMock.Object);
            var registerModel     = FakeModelsRepository.GetFakeRegisterModel(FakeModelsRepository.UserNotExistLogin);
            var cancellationToken = new CancellationToken();

            //Act
            var result = await service.Register(registerModel, cancellationToken);

            //Assert
            Assert.True(result.Success);
            Assert.Equal("Succesfully sign up", result.Messege);
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
0
        public async Task Register_UserLoginExist()
        {
            //Arrange
            var users           = FakeModelsRepository.GetFakeUsers();
            var dbContextMock   = MockInjectedServices.GetMockDbContext(users);
            var memoryCacheMock = MockInjectedServices.GetMockmemoryCache();

            var service = new AuthService(dbContextMock.Object, memoryCacheMock.Object);

            var registerModel     = FakeModelsRepository.GetFakeRegisterModel(FakeModelsRepository.UserExistLogin);
            var cancellationToken = new CancellationToken();

            //Act
            var result = await service.Register(registerModel, cancellationToken);

            //Assert
            Assert.False(result.Success);
        }
示例#9
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);
        }
示例#10
0
        public async Task GetPassword_PasswordNotFound()
        {
            //Arrange
            var users             = FakeModelsRepository.GetFakeUsers();
            var passwords         = FakeModelsRepository.GetFakePasswords();
            var dbContextMock     = MockInjectedServices.GetMockDbContext(users, passwords);
            var memoryCacheMock   = MockInjectedServices.GetMockmemoryCache(null);
            var authorizationMock = new Mock <IAuthorizationService>();

            var service           = new WalletService(dbContextMock.Object, memoryCacheMock.Object, authorizationMock.Object);
            var cancellationToken = new CancellationToken();

            //Act
            var result = await service.GetPassword(new Guid("6a2c050a-29f8-4bcb-8a70-9bccc2d57aad"),
                                                   FakeModelsRepository.UserExistLogin,
                                                   cancellationToken);

            //Assert
            Assert.False(result.Success);
        }
示例#11
0
        public async Task AddPassword_Successfull()
        {
            //Arrange
            var users         = FakeModelsRepository.GetFakeUsers();
            var dbContextMock = MockInjectedServices.GetMockDbContext(users);

            object expectedValue     = HashHelper.SHA512("zdRpf^%f65V(0" + "testSALT" + "Password");
            var    memoryCacheMock   = MockInjectedServices.GetMockmemoryCache(expectedValue);
            var    authorizationMock = new Mock <IAuthorizationService>();

            var service           = new WalletService(dbContextMock.Object, memoryCacheMock.Object, authorizationMock.Object);
            var addPasswordModel  = FakeModelsRepository.GetFakeAddNewPasswordModel();
            var cancellationToken = new CancellationToken();

            //Act
            var result = await service.AddNewPassowrd(addPasswordModel, FakeModelsRepository.UserExistLogin, cancellationToken);

            //Assert
            Assert.True(result.Success);
        }