示例#1
0
        public void GetByUserUserNameReturnsAValidUser()
        {
            var mock     = new Mock <IUserRepository>();
            var id       = 1;
            var username = "******";
            var password = "******";

            mock.Setup(e => e.GetSingleUser(username)).Returns(
                new UserModel
            {
                Id           = id,
                PassWord     = password,
                UserName     = username,
                Active       = true,
                Created      = new DateTime(),
                EmailAddress = "*****@*****.**",
                Updated      = new DateTime()
            });

            var service = new UsersLogic(mock.Object);
            var sut     = service.GetByUserName(username);

            Assert.Equal(sut.Id, id);
            Assert.Equal(sut.Username, username);
        }
示例#2
0
        public void UserThatIsNotFoundThrowsARecordNotFoundException()
        {
            var mock = new Mock <IUserRepository>();

            var username = "******";

            mock.Setup(e => e.GetSingleUser(username)).Returns((UserModel)null);

            var service = new UsersLogic(mock.Object);

            Assert.Throws <RecordNotFoundException>(() => service.GetByUserName(username));
        }
示例#3
0
        public void ShouldThrowExceptionWhenGetUserByUsernameFails()
        {
            _userRepository = new Mock<IUserRepository>();
            _userRepository.Setup(a => a.Find(It.IsAny<Expression<Func<User, bool>>>(),
                It.IsAny<Func<IQueryable<User>, IOrderedQueryable<User>>>(), It.IsAny<string>()))
                .Throws(new Exception());

            _addressRepository = new Mock<IAddressRepository>();
            _educationRepository = new Mock<IEducationRepository>();
            _mediaRepository = new Mock<IMediaRepository>();

            _usersLogic = new UsersLogic(_userRepository.Object, _addressRepository.Object,
                _educationRepository.Object, _mediaRepository.Object);

            Assert.Throws<BlogException>(() => _usersLogic.GetByUserName("foo"));
        }
示例#4
0
        public void ShouldErrorWhenGetUserByUsernameHasNoResult()
        {
            _userRepository = new Mock<IUserRepository>();
            _userRepository.Setup(a => a.Find(It.IsAny<Expression<Func<User, bool>>>(),
                It.IsAny<Func<IQueryable<User>, IOrderedQueryable<User>>>(), It.IsAny<string>()))
                .Returns(new List<User>());

            _addressRepository = new Mock<IAddressRepository>();
            _educationRepository = new Mock<IEducationRepository>();
            _mediaRepository = new Mock<IMediaRepository>();

            _usersLogic = new UsersLogic(_userRepository.Object, _addressRepository.Object,
                _educationRepository.Object, _mediaRepository.Object);

            var user = _usersLogic.GetByUserName("foo");

            Assert.IsNotNull(user.Error);
            Assert.AreEqual(user.Error.Id, (int)Constants.Error.RecordNotFound);
        }
示例#5
0
        public void ShouldGetUserByUsername()
        {
            const string username = "******";
            var educations = _educations.Where(a => a.UserId == 1).ToList();

            _userRepository = new Mock<IUserRepository>();
            _userRepository.Setup(a => a.Find(It.IsAny<Expression<Func<User, bool>>>(),
                It.IsAny<Func<IQueryable<User>, IOrderedQueryable<User>>>(), It.IsAny<string>()))
                .Returns(_users);

            _addressRepository = new Mock<IAddressRepository>();
            _addressRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Address, bool>>>(), false))
                .Returns(_addresses);

            _educationRepository = new Mock<IEducationRepository>();
            _educationRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Education, bool>>>(), true))
                .Returns(educations);

            _mediaRepository = new Mock<IMediaRepository>();
            _mediaRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Media, bool>>>(), null, string.Empty))
                .Returns(_mediae);

            _usersLogic = new UsersLogic(_userRepository.Object, _addressRepository.Object,
                _educationRepository.Object, _mediaRepository.Object);

            var user = _usersLogic.GetByUserName(username);

            Assert.NotNull(user);
            Assert.NotNull(user.Address);
            Assert.NotNull(user.Education);
            Assert.NotNull(user.Hobbies);
            Assert.NotNull(user.Picture);
            Assert.NotNull(user.Background);
            Assert.AreEqual(user.UserName, username);
        }