示例#1
0
        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);
        }
示例#2
0
        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());
        }
示例#3
0
        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());
        }
示例#5
0
        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();
            }
        }
示例#6
0
        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());
        }
示例#7
0
        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);
        }