コード例 #1
0
        public void When_UpdateBlogArticle_is_mapped_to_a_BlogArticle_then_the_User_is_retrieved_from_the_IUserProcess_and_added_to_the_BlogArticle()
        {
            const string title   = "title";
            const string content = "content";

            var entity = BlogArticleCreator.CreateSingle();

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

            var updateBlogArticleModel = new UpdateBlogArticleModel
            {
                Title   = title,
                Content = content,
            };

            var result = Mapper.Map(updateBlogArticleModel, entity.Id);

            Assert.AreEqual(title, result.Title);
            Assert.AreEqual(content, result.Content);

            BlogProcess.VerifyAllExpectations();
        }
コード例 #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);
        }
コード例 #3
0
        public void When_Delete_is_called_with_an_Id_then_GetBlogArticle_on_IBlogArticleProcess_is_called_and_the_result_used_to_call_RemoveBlogArticle_on_IBlogArticleProcess()
        {
            var entity = BlogArticleCreator.CreateSingle();

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

            var result = Controller.Delete(entity.Id).Result as RedirectToRouteResult;

            Assert.IsNotNull(result);

            var routeValues = result.RouteValues;

            Assert.AreEqual(1, routeValues.Count);

            foreach (var routeValue in routeValues)
            {
                Assert.AreEqual("action", routeValue.Key);
                Assert.AreEqual("Index", routeValue.Value);
            }

            BlogProcess.VerifyAllExpectations();
        }
コード例 #4
0
        public void When_Edit_is_called_with_an_Id_then_GetBlogArticle_on_IBlogArticleProcess_is_called_and_the_result_is_mapped_with_BlogArticleMapper()
        {
            var entity = BlogArticleCreator.CreateSingle();

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

            var updateModel = CreateUpdateBlogArticleModel(Guid.NewGuid());

            BlogArticleMapper
            .Expect(mapper =>
                    mapper.MapToUpdate(
                        Arg <BlogArticle> .Matches(settings => settings.Id == entity.Id)))
            .Return(updateModel)
            .Repeat.Once();
            BlogArticleMapper.Replay();

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

            Assert.IsNotNull(result);

            var model = result.Model as UpdateBlogArticleModel;

            Assert.IsNotNull(model);

            BlogProcess.VerifyAllExpectations();
            BlogArticleMapper.VerifyAllExpectations();
        }
コード例 #5
0
ファイル: IndexTests.cs プロジェクト: Coilz/BandWebsite
        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();
        }
コード例 #6
0
        public void When_Edit_is_called_with_a_model_then_Map_on_BlogArticleMapper_is_called_and_the_result_is_used_to_call_UpdateBlogArticle_on_IBlogArticleProcess_with()
        {
            var entity = BlogArticleCreator.CreateSingle();

            BlogProcess
            .Expect(process =>
                    process.UpdateBlogArticle(
                        Arg <BlogArticle> .Matches(settings =>
                                                   settings.Id == entity.Id)))
            .Return(entity)
            .Repeat.Once();
            BlogProcess.Replay();

            var updateModel = CreateUpdateBlogArticleModel(entity.Id);

            BlogArticleMapper
            .Expect(mapper =>
                    mapper.Map(
                        Arg <UpdateBlogArticleModel> .Matches(m =>
                                                              m.Content == entity.Content &&
                                                              m.Title == entity.Title),
                        Arg <Guid> .Matches(guid => guid == entity.Id)))
            .Return(entity)
            .Repeat.Once();
            BlogArticleMapper.Replay();

            var result = Controller.Edit(entity.Id, updateModel) as RedirectToRouteResult;

            Assert.IsNotNull(result);

            var routeValues = result.RouteValues;

            Assert.AreEqual(1, routeValues.Count);

            foreach (var routeValue in routeValues)
            {
                Assert.AreEqual("action", routeValue.Key);
                Assert.AreEqual("Index", routeValue.Value);
            }

            BlogProcess.VerifyAllExpectations();
            BlogArticleMapper.VerifyAllExpectations();
        }
コード例 #7
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);
            }
        }
コード例 #8
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();
        }