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(); }
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(); }
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(); }
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(); }
protected override void AdditionalSetup() { base.AdditionalSetup(); Mapper = new BlogArticleMapper(CatalogsContainer); }