Exemplo n.º 1
0
        public virtual User GetNewOrExistingVisitor(User user)
        {
            if (user == null) throw new ArgumentNullException("user");

            if (string.IsNullOrEmpty(user.Email))
                throw new ArgumentException("User should have a valid email");

            User existingUser = userRepository.GetUserByEmail(user.Email);

            if(existingUser == null)
            {
                user.Id = 0;
                user.Role = UserRole.Visitor;
                user.DateCreated = DateTime.Now;
                return user;
            }
            else
            {
                if (user.Name != existingUser.Name)
                    existingUser.Name = user.Name;

                if (user.WebSite != existingUser.WebSite)
                    existingUser.WebSite = user.WebSite;

                return existingUser;
            }
        }
Exemplo n.º 2
0
        public void GetNewOrExistingUser_when_user_doesnot_exists_new_user_should_be_created_with_proper_fields()
        {
            //Arrange
            User user = new User
            {
                Email = "*****@*****.**",
                Name = "newuser",
                Id = 5,
                DateCreated = DateTime.Now.AddDays(-1),
                Role = UserRole.Reviewer
            };

            //Act
            User ret = service.GetNewOrExistingVisitor(user);

            //Assert
            Assert.AreEqual("newuser", ret.Name);
            Assert.AreEqual(0, ret.Id);
            Assert.AreEqual("*****@*****.**", ret.Email);
            Assert.AreEqual(UserRole.Visitor, ret.Role);
            Assert.IsTrue((ret.DateCreated - DateTime.Now).Seconds < 5);
        }
        private void SetupMocks()
        {
            var serviceMock = new MoqAutoMocker<CommentServices>();

            commentRepositoryMock = Mock.Get(serviceMock.Get<ICommentRepository>());
            appConfigProviderMock = Mock.Get(serviceMock.Get<IAppConfigProvider>());
            userRepository = Mock.Get(serviceMock.Get<IUserRepository>());
            userServicesMock = Mock.Get(serviceMock.Get<UserServices>());

            SetupUserRepositoryMocks();
            SetupCommentRepositoryMocks();
            SetupUserServiceMocks();
            SetupAppConfigMocks();

            service = serviceMock.ClassUnderTest;

            _AddedComment = null;
            user = new User{DateCreated = DateTime.Now, Email = "*****@*****.**", Name = "testuser"};
        }
Exemplo n.º 4
0
 public virtual void AddUser(User user)
 {
     User = user;
     user.Comments.Add(this);
 }
Exemplo n.º 5
0
        private Comment GetComment(CommentDetails commentDetails)
        {
            Comment comment = new Comment { Text = commentDetails.Text };
            User user = new User { Email = commentDetails.UserEmail, Name = commentDetails.UserName, WebSite = commentDetails.UserWebSite };
            comment.User = user;

            return comment;
        }
Exemplo n.º 6
0
        public void GetNewOrExistingUser_when_user_doesnot_have_an_email_it_should_throw_ArgumentException()
        {
            //Arrange
            User user = new User();

            //Act
            service.GetNewOrExistingVisitor(user);

            //Assert
        }
Exemplo n.º 7
0
        public void SetupTest()
        {
            var serviceMock = new MoqAutoMocker<UserServices>();

            userRepositoryMock = Mock.Get(serviceMock.Get<IUserRepository>());
            appConfigProviderMock = Mock.Get(serviceMock.Get<IAppConfigProvider>());

            existingUser = CreateNewUser();

            SetupUserRepository(userRepositoryMock);

            service = serviceMock.ClassUnderTest;
        }
Exemplo n.º 8
0
        public void GetNewOrExistingUser_when_user_exists_it_should_return_the_existing_user()
        {
            //Arrange
            User user = new User { Email = "*****@*****.**" };

            //Act

            User ret = service.GetNewOrExistingVisitor(user);

            //Assert
            Assert.AreEqual(existingUser.Id, ret.Id);
        }