Example #1
0
        public void When_CreatUser_is_called_with_an_emailAddress_that_already_exists_then_the_MembershipCreateStatus_is_DuplicateEmail()
        {
            UserProcess
            .Expect(process => process.GetUserByLoginName(Arg <string> .Is.Anything))
            .Return(null)
            .Repeat.Once();
            UserProcess
            .Expect(process => process.GetUserByEmailAddress(Arg <string> .Is.Anything))
            .Return(UserCreator.CreateSingle())
            .Repeat.Once();
            UserProcess.Replay();

            MembershipCreateStatus createStatus;
            var result = CustomMembershipProvider.CreateUser(
                string.Empty,
                string.Empty,
                string.Empty,
                string.Empty,
                string.Empty,
                false,
                Guid.Empty,
                out createStatus);

            Assert.IsNull(result);
            Assert.AreEqual(MembershipCreateStatus.DuplicateEmail, createStatus);
        }
Example #2
0
        public void When_BlogArticle_is_mapped_to_a_BlogArticleDetailsModel_then_no_data_is_retrieved_from_process_classes()
        {
            BlogProcess
            .Expect(process =>
                    process.GetBlogArticle(Arg <Guid> .Is.Anything))
            .Repeat.Never();
            BlogProcess.Replay();

            UserProcess
            .Expect(process =>
                    process.GetUser(Arg <Guid> .Is.Anything))
            .Repeat.Never();
            UserProcess.Replay();

            var blogArticle = BlogArticleCreator.CreateSingle();
            var user        = UserCreator.CreateSingle();

            blogArticle.AuthorId = user.Id;

            var result = Mapper.MapToDetail(blogArticle, user);

            Assert.AreEqual(blogArticle.Id, result.Id);
            Assert.AreEqual(blogArticle.ModificationDate, result.ModificationDate);
            Assert.AreEqual(blogArticle.PublishDate, result.PublishDate);
            Assert.AreEqual(blogArticle.Title, result.Title);
            Assert.AreEqual(blogArticle.Content, result.Content);
            Assert.AreEqual(blogArticle.CreationDate, result.CreationDate);
            Assert.AreEqual(user.Login.LoginName, result.AuthorName);
        }
        public void When_User_is_mapped_to_a_MembershipUser_then_the_User_is_not_retrieved_from_the_IUserProcess()
        {
            var user = UserCreator.CreateSingle();

            UserProcess
            .Expect(process => process.GetUser(user.Id))
            .Return(user)
            .Repeat.Never();
            UserProcess.Replay();

            var result = Mapper.Map(user);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ProviderUserKey);
            Assert.AreEqual(user.Id, (Guid)result.ProviderUserKey);
            //Assert.AreEqual(user.BandId, result.BandId);
            Assert.AreEqual(user.Login.CreationDate, result.CreationDate.ToUniversalTime());
            Assert.AreEqual(user.Login.EmailAddress, result.Email);
            Assert.AreEqual(user.Login.IsApproved, result.IsApproved);
            Assert.AreEqual(user.Login.IsLockedOut, result.IsLockedOut);
            Assert.AreEqual(user.Login.IsOnline, result.IsOnline);
            Assert.AreEqual(user.Login.LastActivityDate, result.LastActivityDate.ToUniversalTime());
            Assert.AreEqual(user.Login.LastLockoutDate, result.LastLockoutDate.ToUniversalTime());
            Assert.AreEqual(user.Login.LastLoginDate, result.LastLoginDate.ToUniversalTime());
            Assert.AreEqual(user.Login.LastPasswordChangedDate, result.LastPasswordChangedDate.ToUniversalTime());
            //Assert.AreEqual(user.ModificationDate, result.ModificationDate);
            //Assert.AreEqual(user.Name, result.Name);

            UserProcess.VerifyAllExpectations();
        }
Example #4
0
        public void When_ValidateUser_is_called_with_a_valid_UserName_and_a_valid_Password_then_true_is_returned()
        {
            const string decryptedPassword = "******";
            var          user = UserCreator.CreateSingle();

            UserProcess
            .Expect(process =>
                    process.GetUserByLoginName(user.Login.LoginName))
            .Return(user)
            .Repeat.Once();
            UserProcess.Replay();

            CryptographyProcess
            .Expect(process => process.Decrypt(user.Login.Password))
            .Return(decryptedPassword)
            .Repeat.Once();
            CryptographyProcess.Replay();

            var result = CustomMembershipProvider.ValidateUser(user.Login.LoginName, decryptedPassword);

            UserProcess.VerifyAllExpectations();
            CryptographyProcess.VerifyAllExpectations();

            Assert.IsTrue(result);
        }
Example #5
0
        public void When_Index_is_called_GetBlogArticles_on_IBlogProcess_is_called_and_the_result_is_mapped_with_BlogArticleMapper()
        {
            var user         = UserCreator.CreateSingle();
            var blogArticles = BlogArticleCreator.CreateCollection();

            foreach (var blogArticle in blogArticles)
            {
                blogArticle.AuthorId = user.Id;
            }

            UserProcess
            .Expect(process =>
                    process.GetUser(user.Id))
            .Return(user)
            .Repeat.Once();
            UserProcess.Replay();

            BlogProcess
            .Expect(process =>
                    process.GetBlogArticles())
            .Return(blogArticles)
            .Repeat.Once();
            BlogProcess.Replay();

            var blogArticleDetailsModelcollection = CreateBlogArticleDetailsModelCollection();

            BlogArticleMapper
            .Expect(mapper =>
                    mapper.Map(
                        Arg <IEnumerable <BlogArticle> > .Matches(articles =>
                                                                  blogArticles.All(blogArticle =>
                                                                                   articles.Any(article =>
                                                                                                article.Id == blogArticle.Id))),
                        Arg <IEnumerable <User> > .Matches(users => users.Any(u => u == user))))
            .Return(blogArticleDetailsModelcollection)
            .Repeat.Once();
            BlogArticleMapper.Replay();

            var result = Controller.Index().Result as ViewResult;

            Assert.IsNotNull(result);

            var model = result.Model as ItemListModel <BlogArticleDetailsModel>;

            Assert.IsNotNull(model);

            UserProcess.VerifyAllExpectations();
            BlogProcess.VerifyAllExpectations();
            BlogArticleMapper.VerifyAllExpectations();
        }
Example #6
0
        public void When_GetUser_is_called_with_a_valid_Guid_then_GetUser_on_the_BandRepository_is_called_with_that_Guid()
        {
            var user = UserCreator.CreateSingle();

            BandRepository
            .Expect(repository =>
                    repository.GetUser(user.Id))
            .Return(user)
            .Repeat.Once();
            BandRepository.Replay();

            Process.GetUser(user.Id);

            BandRepository.VerifyAllExpectations();
        }
Example #7
0
        public void When_AddUser_is_called_with_then_the_User_with_is_added_to_the_collection()
        {
            var user = UserCreator.CreateSingle();

            BandCatalog
            .Expect(catalog => catalog.Add(user))
            .Return(user)
            .Repeat.Once();
            BandCatalog.Replay();

            user = Repository.AddUser(user);

            Assert.IsNotNull(user);

            BandCatalog.VerifyAllExpectations();
        }
Example #8
0
        public void When_AddBlogArticle_is_mapped_to_a_BlogArticle_then_the_User_is_retrieved_from_the_IUserProcess()
        {
            var user = UserCreator.CreateSingle();

            var addBlogArticleModel = new AddBlogArticleModel
            {
                Content = "content",
                Title   = "title"
            };

            var result = Mapper.Map(addBlogArticleModel, user.Id);

            Assert.AreEqual(user.Id, result.AuthorId);
            Assert.AreEqual(addBlogArticleModel.Title, result.Title);
            Assert.AreEqual(addBlogArticleModel.Content, result.Content);
        }
        public void When_MembershipUser_is_mapped_to_a_User_then_the_User_is_retrieved_from_the_IUserProcess()
        {
            var lastActivityDate = DateTime.Now.AddMilliseconds(30);
            var user             = UserCreator.CreateSingle();

            UserProcess
            .Expect(process => process.GetUser(user.Id))
            .Return(user)
            .Repeat.Once();
            UserProcess.Replay();

            var membershipUser = new MembershipUser(
                "CustomMembershipProvider",
                user.Login.LoginName,
                user.Id,
                user.Login.EmailAddress,
                "",
                "",
                true,
                false,
                user.Login.CreationDate,
                user.Login.LastLoginDate,
                lastActivityDate,
                user.Login.LastPasswordChangedDate,
                user.Login.LastLockoutDate);

            var result = Mapper.Map(membershipUser);

            Assert.IsNotNull(membershipUser.ProviderUserKey);
            Assert.AreEqual((Guid)membershipUser.ProviderUserKey, result.Id);
            //Assert.AreEqual(user.BandId, result.BandId);
            Assert.AreEqual(user.Login.CreationDate, result.Login.CreationDate);
            Assert.AreEqual(user.Login.EmailAddress, result.Login.EmailAddress);
            Assert.AreEqual(user.Login.IsApproved, result.Login.IsApproved);
            Assert.AreEqual(user.Login.IsLockedOut, result.Login.IsLockedOut);
            Assert.AreEqual(user.Login.IsOnline, result.Login.IsOnline);

            Assert.AreEqual(lastActivityDate, result.Login.LastActivityDate);

            Assert.AreEqual(user.Login.LastLockoutDate, result.Login.LastLockoutDate);
            Assert.AreEqual(user.Login.LastLoginDate, result.Login.LastLoginDate);
            Assert.AreEqual(user.Login.LastPasswordChangedDate, result.Login.LastPasswordChangedDate);
            //Assert.AreEqual(user.Login.ModificationDate, result.Login.ModificationDate);
            //Assert.AreEqual(user.Name, result.Name);

            UserProcess.VerifyAllExpectations();
        }
Example #10
0
        public void When_UpdateUser_is_called_with_a_valid_User_then_UpdateUser_on_the_BandRepository_is_called_with_that_User()
        {
            var user = UserCreator.CreateSingle();

            BandRepository
            .Expect(repository =>
                    repository.UpdateUser(user))
            .Return(user)
            .Repeat.Once();
            BandRepository.Replay();

            var result = Process.UpdateUser(user);

            Assert.AreEqual(user.Id, result.Id);

            BandRepository.VerifyAllExpectations();
        }
Example #11
0
        public void When_UpdateUser_is_called_with_a_valid_User_then_the_User_with_is_updated_in_the_collection()
        {
            var user = UserCreator.CreateSingle();

            BandCatalog
            .Expect(catalog => catalog.Update(user))
            .Return(user)
            .Repeat.Once();
            BandCatalog.Replay();

            var result = Repository.UpdateUser(user);

            Assert.IsNotNull(result);
            Assert.AreEqual(user.Id, result.Id);

            BandCatalog.VerifyAllExpectations();
        }
        public void When_MembershipUser_is_mapped_to_a_User_and_id_of_the_MembershipUser_is_null_then_an_ArgumentNullException_is_thrown()
        {
            var user = UserCreator.CreateSingle();

            var membershipUser = new MembershipUser(
                "CustomMembershipProvider",
                user.Login.LoginName,
                null,
                user.Login.EmailAddress,
                "",
                "",
                true,
                false,
                user.Login.CreationDate,
                user.Login.LastLoginDate,
                user.Login.LastActivityDate,
                user.Login.LastPasswordChangedDate,
                user.Login.LastLockoutDate);

            Mapper.Map(membershipUser);
        }
Example #13
0
        public void When_a_list_of_BlogArticles_is_mapped_to_a_BlogArticleDetailsModels_then_no_data_is_retrieved_from_process_classes()
        {
            BlogProcess
            .Expect(process =>
                    process.GetBlogArticle(Arg <Guid> .Is.Anything))
            .Repeat.Never();
            BlogProcess.Replay();

            UserProcess
            .Expect(process =>
                    process.GetUser(Arg <Guid> .Is.Anything))
            .Repeat.Never();
            UserProcess.Replay();

            var blogArticles = BlogArticleCreator.CreateCollection();
            var user         = UserCreator.CreateSingle();

            foreach (var blogArticle in blogArticles)
            {
                blogArticle.AuthorId = user.Id;
            }

            var result = Mapper.Map(blogArticles, new[] { user });

            foreach (var blogarticleDetailsModel in result.Items)
            {
                Assert.AreEqual(user.Login.LoginName, blogarticleDetailsModel.AuthorName);
            }

            foreach (var blogArticle in blogArticles)
            {
                Assert.IsTrue(result.Items.Single(model =>
                                                  model.Id == blogArticle.Id &&
                                                  model.ModificationDate == blogArticle.ModificationDate &&
                                                  model.PublishDate == blogArticle.PublishDate &&
                                                  model.Title == blogArticle.Title &&
                                                  model.Content == blogArticle.Content &&
                                                  model.CreationDate == blogArticle.CreationDate) != null);
            }
        }
Example #14
0
        public void When_Details_is_called_GetBlogArticle_on_IBlogProcess_is_called_with_the_correct_parameter_and_the_result_is_mapped_with_BlogArticleMapper()
        {
            var entity = BlogArticleCreator.CreateSingle();
            var author = UserCreator.CreateSingle();

            entity.AuthorId = author.Id;

            UserProcess
            .Expect(process =>
                    process.GetUser(entity.AuthorId))
            .Return(author)
            .Repeat.Once();
            UserProcess.Replay();

            BlogProcess
            .Expect(process =>
                    process.GetBlogArticle(entity.Id))
            .Return(entity)
            .Repeat.Once();
            BlogProcess.Replay();

            var detailsModel = CreateBlogArticleDetailsModel(entity.Id);

            BlogArticleMapper
            .Expect(mapper =>
                    mapper.MapToDetail(entity, author))
            .Return(detailsModel)
            .Repeat.Once();
            BlogArticleMapper.Replay();

            var result = Controller.Details(entity.Id).Result as ViewResult;;

            Assert.IsNotNull(result);

            BlogProcess.VerifyAllExpectations();
            UserProcess.VerifyAllExpectations();
            BlogArticleMapper.VerifyAllExpectations();
        }
Example #15
0
        public void When_CreatUser_is_called_then_the_User_is_created_and_registered_under_the_Band_that_is_provided_by_the_BandProcess()
        {
            var          band              = BandCreator.CreateSingle();
            var          user              = UserCreator.CreateSingle();
            var          login             = user.Login;
            const string encryptedPassword = "******";

            BandProcess
            .Expect(process => process.EnsureBandExists())
            .Return(band)
            .Repeat.Once();
            BandProcess.Replay();

            CryptographyProcess
            .Expect(process => process.Encrypt(login.Password))
            .Return(encryptedPassword)
            .Repeat.Once();
            CryptographyProcess.Replay();

            UserProcess
            .Expect(process => process.GetUserByLoginName(Arg <string> .Is.Anything))
            .Return(null)
            .Repeat.Once();
            UserProcess
            .Expect(process => process.GetUserByEmailAddress(Arg <string> .Is.Anything))
            .Return(null)
            .Repeat.Once();
            UserProcess
            .Expect(process =>
                    process.AddUser(Arg <User> .Matches(u =>
                                                        u.BandId == band.Id &&
                                                        u.Login.Password == encryptedPassword &&
                                                        u.Login.IsOnline &&
                                                        u.Login.LastLoginDate > DateTime.UtcNow.AddSeconds(-2) &&
                                                        u.Login.LastActivityDate > DateTime.UtcNow.AddSeconds(-2) &&
                                                        u.Login.LastPasswordChangedDate >
                                                        DateTime.UtcNow.AddSeconds(-2))))
            .Return(user)
            .Repeat.Once();
            UserProcess.Replay();

            var membershipUser = CreateMembershipUser(user);

            UserMapper
            .Expect(mapper => mapper.Map(user))
            .Return(membershipUser)
            .Repeat.Once();
            UserMapper.Replay();

            MembershipCreateStatus createStatus;
            var result = CustomMembershipProvider.CreateUser(
                login.LoginName,
                login.Password,
                login.EmailAddress,
                string.Empty,
                string.Empty,
                login.IsApproved,
                login.Id,
                out createStatus);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ProviderUserKey);
            Assert.AreEqual(user.Login.LoginName, result.UserName);
            Assert.AreEqual(MembershipCreateStatus.Success, createStatus);

            BandProcess.VerifyAllExpectations();
            CryptographyProcess.VerifyAllExpectations();
            UserProcess.VerifyAllExpectations();
            UserMapper.VerifyAllExpectations();
        }