public void UpdateTheContentOfThePageContentSubmissionToTheInitialPageContent() { //Arrange var mockedPageService = new Mock <IPageService>(); var mockedPageContentSubmissionRepository = new Mock <IContentSubmissionRepository>(); var mockedPageRepository = new Mock <IPageRepository>(); Func <IUnitOfWork> mockedUnitOfWorkFactory = () => { return(new Mock <IUnitOfWork>().Object); }; var submissionServiceUnderTest = new ContentSubmissionService(mockedPageContentSubmissionRepository.Object, mockedPageRepository.Object, mockedUnitOfWorkFactory, mockedPageService.Object); var expectedPageContent = "new content"; var expectedEditContent = "page old content"; var page = new Page() { Content = expectedEditContent, LastEdit = null, }; var edit = new PageContentSubmission() { Content = "edit old content", PageEdit = page, PageHistory = null }; mockedPageContentSubmissionRepository.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(edit); mockedPageService.Setup(x => x.GetPageByTitle(It.IsAny <string>())).Returns(page); //Act submissionServiceUnderTest.PublishEdit("title", expectedPageContent, Guid.NewGuid()); //Assert Assert.AreEqual(expectedEditContent, edit.Content); }
public void CallCommitMethodOfUnitOfWork() { //Arrange var mockedPageService = new Mock <IPageService>(); var mockedPageContentSubmissionRepository = new Mock <IContentSubmissionRepository>(); var mockedPageRepository = new Mock <IPageRepository>(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); Func <IUnitOfWork> mockedUnitOfWorkFactory = () => { return(mockedUnitOfWork.Object); }; var submissionServiceUnderTest = new ContentSubmissionService(mockedPageContentSubmissionRepository.Object, mockedPageRepository.Object, mockedUnitOfWorkFactory, mockedPageService.Object); var expectedPageContent = "new content"; var expectedEditContent = "page old content"; var page = new Page() { Content = expectedEditContent, LastEdit = null, }; var edit = new PageContentSubmission() { Content = "edit old content", PageEdit = page, PageHistory = null }; mockedPageContentSubmissionRepository.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(edit); mockedPageService.Setup(x => x.GetPageByTitle(It.IsAny <string>())).Returns(page); //Act submissionServiceUnderTest.PublishEdit("title", expectedPageContent, Guid.NewGuid()); //Assert mockedUnitOfWork.Verify(m => m.Commit(), Times.Once()); }
public void ReturnCorrectCollection() { //Arrange var mockedPageService = new Mock <IPageService>(); var mockedPageContentSubmissionRepository = new Mock <IContentSubmissionRepository>(); var mockedPageRepository = new Mock <IPageRepository>(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); Func <IUnitOfWork> mockedUnitOfWorkFactory = () => { return(mockedUnitOfWork.Object); }; var submissionServiceUnderTest = new ContentSubmissionService(mockedPageContentSubmissionRepository.Object, mockedPageRepository.Object, mockedUnitOfWorkFactory, mockedPageService.Object); var pendingEdits = new List <PageContentSubmission>(); var edit1 = new PageContentSubmission() { Content = "edit1", PageHistory = null }; var edit2 = new PageContentSubmission() { Content = "edit2", PageHistory = null }; pendingEdits.Add(edit1); pendingEdits.Add(edit2); mockedPageContentSubmissionRepository.Setup(x => x.GetSubmissions(It.IsAny <string>())).Returns(pendingEdits); //Act var result = submissionServiceUnderTest.GetSubmissions("tuturutka"); //Assert CollectionAssert.AreEqual(pendingEdits, result); }
public void CallCommitMethodOfUnitOfWork() { //Arrange var mockedPageService = new Mock <IPageService>(); var mockedPageContentSubmissionRepository = new Mock <IContentSubmissionRepository>(); var mockedPageRepository = new Mock <IPageRepository>(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); Func <IUnitOfWork> mockedUnitOfWorkFactory = () => { return(mockedUnitOfWork.Object); }; var submissionServiceUnderTest = new ContentSubmissionService(mockedPageContentSubmissionRepository.Object, mockedPageRepository.Object, mockedUnitOfWorkFactory, mockedPageService.Object); var edit = new PageContentSubmission() { Content = "edit old content", PageHistory = null }; //Act submissionServiceUnderTest.GetPageContentSubmissionById(Guid.NewGuid()); //Assert mockedPageContentSubmissionRepository.Verify(m => m.GetById(It.IsAny <Guid>()), Times.Once()); }
public void SubmitEdit(string content, string title) { Guard.WhenArgument(title, "title").IsNullOrEmpty().Throw(); var page = this.pageService.GetPageByTitle(title); if (page == null) { throw new NullReferenceException("Page not found!"); } var submission = new PageContentSubmission() { Content = content, PageEdit = page }; using (var unitOfWork = this.unitOfWorkFactory()) { this.pageContentSubmissionRepository.Add(submission); unitOfWork.Commit(); } }
public void CallDeleteMethodOfThePageContentSubmissionRepository() { //Arrange var mockedPageService = new Mock <IPageService>(); var mockedPageContentSubmissionRepository = new Mock <IContentSubmissionRepository>(); var mockedPageRepository = new Mock <IPageRepository>(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); Func <IUnitOfWork> mockedUnitOfWorkFactory = () => { return(mockedUnitOfWork.Object); }; var submissionServiceUnderTest = new ContentSubmissionService(mockedPageContentSubmissionRepository.Object, mockedPageRepository.Object, mockedUnitOfWorkFactory, mockedPageService.Object); var edit = new PageContentSubmission() { Content = "edit old content", PageHistory = null }; mockedPageContentSubmissionRepository.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(edit); //Act submissionServiceUnderTest.DismissEdit(Guid.NewGuid()); //Assert mockedPageContentSubmissionRepository.Verify(m => m.Delete(It.IsAny <PageContentSubmission>()), Times.Once()); }
public void SetViewModelHtmlCorrectly() { //Arrange var mockedView = new Mock <IPublishEditView>(); mockedView.Setup(v => v.Model).Returns(new PublishEditViewModel()); var mockedPageService = new Mock <IPageService>(); var mockedContentSubmissionService = new Mock <IContentSubmissionService>(); var defaultPresenterUnderTest = new PublishEditPresenter(mockedView.Object, mockedPageService.Object, mockedContentSubmissionService.Object); string expectedTitle = "page title"; string expectedContent = "edit content"; var contentSubmission = new PageContentSubmission() { Content = expectedContent }; mockedContentSubmissionService.Setup(x => x.GetPageContentSubmissionById(It.IsAny <Guid>())).Returns(contentSubmission); //Act mockedView.Raise(v => v.OnPageGetContent += null, new IdEventArgs(Guid.NewGuid(), expectedTitle)); //Assert Assert.AreEqual(expectedContent, mockedView.Object.Model.Content); }