Пример #1
0
        public void Invoke_EmptyUser_ReturnsNull()
        {
            // prepare
            var domain = new DataAccess.Models.Domain
            {
                Name = "Test Domain"
            };

            var mockedUserRepository = new Mock <IUserRepository>();

            var findByResult = new List <DataAccess.Models.Domain> {
                domain
            };
            var mockedDomainRepository = new Mock <IDomainRepository>();

            mockedDomainRepository.Setup(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.Domain, bool> > >()))
            .Returns(findByResult.AsQueryable);

            var action = new AuthenticateUser(mockedUserRepository.Object, mockedDomainRepository.Object);

            // action
            var user = action.Invoke("*****@*****.**", "test", "123");

            // check
            Assert.Null(user);
            mockedDomainRepository.Verify(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.Domain, bool> > >()), Times.Once);
            mockedUserRepository.Verify(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.User, bool> > >()), Times.Once);
        }
Пример #2
0
        public void Invoke_EmptyRepository_EmailIsEmpty()
        {
            // prepare
            var mockedUserRepository   = new Mock <IUserRepository>();
            var mockedDomainRepository = new Mock <IDomainRepository>();

            var action = new AuthenticateUser(mockedUserRepository.Object, mockedDomainRepository.Object);

            // action
            var user = action.Invoke("", "test", "123");

            // check
            Assert.Null(user);
            mockedDomainRepository.Verify(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.Domain, bool> > >()), Times.Never);
        }
Пример #3
0
        public void Invoke_WrongPassword_ReturnsNull()
        {
            // prepare
            var domain = new DataAccess.Models.Domain
            {
                Name = "Test Domain"
            };

            var dataUser = new DataAccess.Models.User
            {
                Email        = "*****@*****.**",
                PasswordSalt = "salt-generated",
                PasswordHash = "plain-hashed"
            };

            var findByResult = new List <DataAccess.Models.User> {
                dataUser
            };
            var mockedUserRepository = new Mock <IUserRepository>();

            mockedUserRepository.Setup(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.User, bool> > >()))
            .Returns(findByResult.AsQueryable);

            var mockedHasher = new Mock <IHasher>();

            mockedHasher.Setup(h => h.CreatePasswordHash("wrongPassword", "salt-generated")).Returns("wrong-hashed");

            var mockedDomainRepository = new Mock <IDomainRepository>();
            var findDomainResult       = new List <DataAccess.Models.Domain> {
                domain
            };

            mockedDomainRepository.Setup(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.Domain, bool> > >()))
            .Returns(findDomainResult.AsQueryable);

            var action = new AuthenticateUser(mockedUserRepository.Object, mockedDomainRepository.Object, mockedHasher.Object);

            // action
            var user = action.Invoke("*****@*****.**", "wrongPassword", "123");

            // check
            Assert.Null(user);
            mockedDomainRepository.Verify(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.Domain, bool> > >()), Times.Once);
            mockedUserRepository.Verify(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.User, bool> > >()), Times.Once);
        }
Пример #4
0
        public void Invoke_EmptyParameters_ReturnsNull(string email, string password, string domainName)
        {
            // prepare
            var findByResult         = new List <DataAccess.Models.User>();
            var mockedUserRepository = new Mock <IUserRepository>();

            mockedUserRepository.Setup(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.User, bool> > >()))
            .Returns(findByResult.AsQueryable);

            var mockedDomainRepository = new Mock <IDomainRepository>();

            var action = new AuthenticateUser(mockedUserRepository.Object, mockedDomainRepository.Object);

            // action
            var user = action.Invoke(email, password, domainName);

            // check
            Assert.Null(user);
            mockedDomainRepository.Verify(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.Domain, bool> > >()), Times.Never);
            mockedUserRepository.Verify(r => r.FindBy(It.IsAny <Expression <Func <DataAccess.Models.User, bool> > >()), Times.Never);
        }