Example #1
0
        public void Should_Insert_HtmlWidget_To_Page_Successfully()
        {
            // Create html content
            var widget = TestDataProvider.CreateNewHtmlContentWidget();

            widget.Status = ContentStatus.Published;

            var page        = TestDataProvider.CreateNewPage();
            var region      = TestDataProvider.CreateNewRegion();
            var pageContent = TestDataProvider.CreateNewPageContent(widget, page, region);

            pageContent.Order = TestDataProvider.ProvideRandomNumber(1, 99999);

            // Mock
            var repository = new Mock <IRepository>();

            repository
            .Setup(r => r.AsProxy <Page>(It.IsAny <Guid>()))
            .Returns(TestDataProvider.CreateNewPage());
            repository
            .Setup(r => r.AsProxy <Region>(It.IsAny <Guid>()))
            .Returns(TestDataProvider.CreateNewRegion());
            repository
            .Setup(r => r.AsQueryable <PageContent>())
            .Returns(new List <PageContent> {
                pageContent
            }.AsQueryable());
            repository
            .Setup(r => r.Save(It.IsAny <PageContent>()))
            .Callback <PageContent>(pc =>
            {
                Assert.AreEqual(pc.Order, pageContent.Order + 1);
            });

            // Create command
            var command = new InsertContentToPageCommand();

            command.UnitOfWork = new Mock <IUnitOfWork>().Object;
            command.Repository = repository.Object;

            // Execute
            var request = new InsertContentToPageRequest {
                ContentId = widget.Id, PageId = page.Id, RegionId = region.Id
            };
            var result = command.Execute(request);

            Assert.IsNotNull(result);
            Assert.IsTrue(result);
        }
Example #2
0
        public ActionResult InsertContentToPage(string pageId, string contentId, string regionId)
        {
            var request = new InsertContentToPageRequest
            {
                ContentId = contentId.ToGuidOrDefault(),
                PageId = pageId.ToGuidOrDefault(),
                RegionId = regionId.ToGuidOrDefault()
            };

            if (GetCommand<InsertContentToPageCommand>().ExecuteCommand(request))
            {
                return Json(new WireJson { Success = true });
            }

            return Json(new WireJson { Success = false });
        }
        public ActionResult InsertContentToPage(string pageId, string contentId, string regionId, string parentPageContentId, string includeChildRegions)
        {
            var request = new InsertContentToPageRequest
            {
                ContentId           = contentId.ToGuidOrDefault(),
                PageId              = pageId.ToGuidOrDefault(),
                RegionId            = regionId.ToGuidOrDefault(),
                ParentPageContentId = (!string.IsNullOrWhiteSpace(parentPageContentId))
                        ? parentPageContentId.ToGuidOrDefault()
                        : (System.Guid?)null,
                IncludeChildRegions = includeChildRegions.ToBoolOrDefault()
            };

            var result = GetCommand <InsertContentToPageCommand>().ExecuteCommand(request);

            return(WireJson(result != null, result));
        }
Example #4
0
        public void Should_Insert_HtmlWidget_To_Page_Successfully()
        {
            // Create html content
            var widget = TestDataProvider.CreateNewHtmlContentWidget();

            widget.Status = ContentStatus.Published;

            var page        = TestDataProvider.CreateNewPage();
            var region      = TestDataProvider.CreateNewRegion();
            var pageContent = TestDataProvider.CreateNewPageContent(widget, page, region);

            pageContent.Order   = TestDataProvider.ProvideRandomNumber(1, 99999);
            pageContent.Id      = Guid.NewGuid();
            pageContent.Version = 10;
            widget.Version      = 20;

            // Mock content Service
            var contentService = new Mock <IContentService>();

            contentService
            .Setup(r => r.GetPageContentNextOrderNumber(It.IsAny <Guid>(), It.IsAny <Guid?>()))
            .Returns(pageContent.Order + 1);

            // Mock
            var repository = new Mock <IRepository>();

            repository
            .Setup(r => r.AsProxy <Page>(It.IsAny <Guid>()))
            .Returns(TestDataProvider.CreateNewPage());
            repository
            .Setup(r => r.AsProxy <Region>(It.IsAny <Guid>()))
            .Returns(TestDataProvider.CreateNewRegion());
            repository
            .Setup(r => r.AsQueryable <PageContent>())
            .Returns(new List <PageContent> {
                pageContent
            }.AsQueryable());
            repository
            .Setup(r => r.AsQueryable <Content>())
            .Returns(new List <Content> {
                widget
            }.AsQueryable());
            repository
            .Setup(r => r.Save(It.IsAny <PageContent>()))
            .Callback <PageContent>(pc =>
            {
                Assert.AreEqual(pc.Order, pageContent.Order + 1);
                pc.Id      = pageContent.Id;
                pc.Version = pageContent.Version;
            });

            // Create command
            var command = new InsertContentToPageCommand(contentService.Object,
                                                         new FakePageContentProjectionFactory(null, null),
                                                         new Mock <IWidgetService>().Object);

            command.UnitOfWork = new Mock <IUnitOfWork>().Object;
            command.Repository = repository.Object;

            // Execute
            var request = new InsertContentToPageRequest {
                ContentId = widget.Id, PageId = page.Id, RegionId = region.Id
            };
            var result = command.Execute(request);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.PageContentId, pageContent.Id);
            Assert.AreEqual(result.PageId, page.Id);
            Assert.AreEqual(result.ContentId, widget.Id);
            Assert.AreEqual(result.ContentType, "html-widget");
            Assert.AreEqual(result.ContentVersion, widget.Version);
            Assert.AreEqual(result.PageContentVersion, pageContent.Version);
            Assert.AreEqual(result.Title, widget.Name);
            Assert.AreEqual(result.RegionId, region.Id);
            Assert.AreEqual(result.DesirableStatus, widget.Status);
        }