public void Should_Delete_Media_With_Access_Rules()
        {
            RunActionInTransaction(session =>
                {
                    var uow = new DefaultUnitOfWork(session);
                    var repository = new DefaultRepository(uow);

                    var file = TestDataProvider.CreateNewMediaFileWithAccessRules(3);
                    session.SaveOrUpdate(file);
                    session.Flush();
                    session.Clear();

                    var command = new DeleteMediaCommand();
                    command.Repository = repository;
                    command.UnitOfWork = uow;

                    var result = command.Execute(new DeleteMediaCommandRequest
                                        {
                                            Id = file.Id,
                                            Version = file.Version
                                        });

                    Assert.IsTrue(result);

                    session.Clear();

                    var deletedFile = session.Query<MediaFile>().FirstOrDefault(f => f.Id == file.Id && !f.IsDeleted);
                    Assert.IsNull(deletedFile);
                });
        }
        public void Should_Delete_HtmlContentWidget_Successfully()
        {
            var htmlContentWidget = TestDataProvider.CreateNewHtmlContentWidget();

            RunActionInTransaction(session =>
            {
                session.SaveOrUpdate(htmlContentWidget);
                session.Flush();
                session.Clear();

                var uow = new DefaultUnitOfWork(session);
                var repository = new DefaultRepository(uow);
                var optionService = new Mock<IOptionService>().Object;
                var contentService = new Mock<IContentService>().Object;
                var childContentService = new Mock<IChildContentService>().Object;
                var categoryService = new Mock<ICategoryService>();
                var widgetService = new DefaultWidgetService(repository, uow, optionService, contentService, childContentService, categoryService.Object);

                DeleteWidgetCommand command = new DeleteWidgetCommand(widgetService);

                bool success = command.Execute(new DeleteWidgetRequest
                                                    {
                                                        WidgetId = htmlContentWidget.Id,
                                                        Version = htmlContentWidget.Version
                                                    });
                Assert.IsTrue(success);
            });
        }
        public void Should_Delete_Page_Content()
        {
            RunActionInTransaction(session =>
            {
                // Create content
                var content = TestDataProvider.CreateNewHtmlContent();
                var pageContent = TestDataProvider.CreateNewPageContent(content);

                session.SaveOrUpdate(pageContent);
                session.Flush();
                session.Clear();

                // Delete page content
                var request = new DeletePageContentCommandRequest
                                  {
                                      PageContentId = pageContent.Id,
                                      PageContentVersion = pageContent.Version,
                                      ContentVersion = content.Version
                                  };
                var unitOfWork = new DefaultUnitOfWork(session);
                var repository = new DefaultRepository(unitOfWork);
                var contentService = Container.Resolve<IContentService>();
                var command = new DeletePageContentCommand(contentService);
                command.UnitOfWork = unitOfWork;
                command.Repository = repository;

                var result = command.Execute(request);
                Assert.IsTrue(result);
            });
        }
        public void Should_ThrowValidationException_AboutNonDeletableOption()
        {
            RunActionInTransaction(session =>
            {
                var unitOfWork = new DefaultUnitOfWork(session);
                var repository = new DefaultRepository(unitOfWork);

                var optionService = new DefaultOptionService(repository);

                // Create layout with options
                var layout = TestDataProvider.CreateNewLayout();
                layout.LayoutOptions = new List<LayoutOption>();

                var option1 = TestDataProvider.CreateNewLayoutOption(layout);
                option1.Type = OptionType.Text;
                option1.IsDeletable = false;
                layout.LayoutOptions.Add(option1);

                session.SaveOrUpdate(layout);
                session.Flush();
                session.Clear();

                optionService.SetOptions<LayoutOption, Layout>(layout, new List<IOption>());
                unitOfWork.Commit();
            });
        }
        public void Should_Sort_Page_Content_Successfully()
        {
            RunActionInTransaction(session =>
            {
                var layout = TestDataProvider.CreateNewLayout();
                var region = TestDataProvider.CreateNewRegion();

                layout.LayoutRegions = new List<LayoutRegion>
                    {
                        TestDataProvider.CreateNewLayoutRegion(layout, region),
                    };

                var page = TestDataProvider.CreateNewPageProperties(layout);
                page.PageContents = new[]
                    {
                        TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region),
                        TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region),
                        TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region)
                    };

                session.SaveOrUpdate(page);
                session.Flush();
                session.Clear();

                IUnitOfWork unitOfWork = new DefaultUnitOfWork(session);

                SortPageContentCommand command = new SortPageContentCommand();
                command.UnitOfWork = unitOfWork;
                command.Repository = new DefaultRepository(unitOfWork);

                var request = new PageContentSortViewModel
                    {
                        PageId = page.Id,
                        RegionId = region.Id,
                        PageContents =
                            new List<ContentViewModel>
                                {
                                    new ContentViewModel { Id = page.PageContents[2].Id, Version = page.PageContents[2].Version },
                                    new ContentViewModel { Id = page.PageContents[1].Id, Version = page.PageContents[1].Version },
                                    new ContentViewModel { Id = page.PageContents[0].Id, Version = page.PageContents[0].Version },
                                }
                    };
                var response = command.Execute(request);

                Assert.AreEqual(2, response.UpdatedPageContents.Count);

                session.Flush();
                session.Clear();

                var updatedPage = command.Repository.AsQueryable<PageContent>(f => f.Page.Id == page.Id).ToList();

                Assert.AreEqual(2, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[0].Id).Order);
                Assert.AreEqual(1, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[1].Id).Order);
                Assert.AreEqual(0, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[2].Id).Order);
            });
        }
Exemple #6
0
        public void Should_Clone_Page_With_Tags_Options_Contents_AccessRules()
        {
            RunActionInTransaction(session =>
                {
                    const string url = "/test-link";
                    var uow = new DefaultUnitOfWork(session);
                    var repository = new DefaultRepository(uow);

                    var pageToClone = TestDataProvider.CreateNewPageWithTagsContentsOptionsAndAccessRules(session, 2, 2, 2, 2);
                    
                    session.SaveOrUpdate(pageToClone);
                    session.Flush();
                    session.Clear();
                    
                    var pageService = new Mock<IPageService>();
                    pageService.Setup(f => f.ValidatePageUrl(It.IsAny<string>(), It.IsAny<Guid?>()));
                    pageService.Setup(f => f.CreatePagePermalink(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<Guid>())).Returns(url);

                    var urlService = new Mock<IUrlService>();
                    urlService.Setup(f => f.FixUrl(It.IsAny<string>())).Returns(url);

                    var rules = new List<IAccessRule>();
                    var rule1 = TestDataProvider.CreateNewAccessRule();
                    rules.Add(rule1);
                    var rule2 = TestDataProvider.CreateNewAccessRule();
                    rules.Add(rule2);

                    var pageCloningService = new DefaultPageCloneService(pageService.Object, urlService.Object, 
                        new Mock<ISecurityService>().Object, new Mock<IAccessControlService>().Object, repository, uow, 
                        Container.Resolve<ICmsConfiguration>());

                    var command = new ClonePageCommand(pageCloningService);
                    command.Repository = repository;
                    command.UnitOfWork = uow;

                    var result = command.Execute(new ClonePageViewModel
                                        {
                                            PageId = pageToClone.Id,
                                            PageTitle = "new cloned page",
                                            PageUrl = url,
                                            UserAccessList = pageToClone.AccessRules.Select(u => new UserAccessViewModel(u)).ToList()
                                        });

                    Assert.IsNotNull(result);
                    session.Clear();

                    var actual = repository.AsQueryable<PageProperties>().Where(f => f.Id == result.PageId).ToList().FirstOrDefault();
                    
                    Assert.IsNotNull(actual);
                    Assert.AreEqual(2, actual.AccessRules.Count(), "AccessRules");
                    Assert.AreEqual(2, actual.PageTags.Count(), "Tags");
                    Assert.AreEqual(2, actual.PageContents.Count(), "Contents");
                    Assert.AreEqual(2, actual.Options.Count(), "Options");
                });
        }
        public void Should_Return_Page_Content_Options_Successfully()
        {
            RunActionInTransaction(session =>
            {
                var content = TestDataProvider.CreateNewContent();
                var pageContent = TestDataProvider.CreateNewPageContent(content);

                FillContentWithOptions(content);
                FillPageContentWithOptions(content, pageContent);

                session.SaveOrUpdate(pageContent);
                session.Flush();
                session.Clear();

                // Create command
                var unitOfWork = new DefaultUnitOfWork(session);
                var command = new GetPageContentOptionsCommand();
                var repository = new DefaultRepository(unitOfWork);
                command.UnitOfWork = unitOfWork;
                command.Repository = repository;
                command.OptionService = new DefaultOptionService(repository);
                command.CmsConfiguration = Container.Resolve<ICmsConfiguration>();

                // Execute command
                var result = command.Execute(pageContent.Id);

                // Should return 4 options: 2 with assigned values, 1 without parent option and 1 unassigned
                Assert.IsNotNull(result);
                Assert.IsNotNull(result.OptionValues);
                Assert.AreEqual(result.OptionValues.Count, 5);
                Assert.IsNotNull(result.OptionValues.FirstOrDefault(o => o.OptionKey == content.ContentOptions[0].Key
                    && o.OptionValue == pageContent.Options[0].Value
                    && o.OptionDefaultValue == content.ContentOptions[0].DefaultValue
                    && !o.UseDefaultValue
                    && !o.CanEditOption));
                Assert.IsNotNull(result.OptionValues.FirstOrDefault(o => o.OptionKey == content.ContentOptions[1].Key
                    && o.OptionValue == pageContent.Options[1].Value
                    && o.OptionDefaultValue == content.ContentOptions[1].DefaultValue
                    && !o.UseDefaultValue
                    && !o.CanEditOption));
                Assert.IsNotNull(result.OptionValues.FirstOrDefault(o => o.OptionKey == content.ContentOptions[2].Key
                    && o.OptionValue == content.ContentOptions[2].DefaultValue
                    && o.OptionDefaultValue == content.ContentOptions[2].DefaultValue
                    && o.UseDefaultValue
                    && !o.CanEditOption));
                Assert.IsNotNull(result.OptionValues.FirstOrDefault(o => o.OptionKey == pageContent.Options[2].Key
                    && o.OptionValue == pageContent.Options[2].Value
                    && o.OptionDefaultValue == null
                    && o.CanEditOption));
                Assert.IsNotNull(result.OptionValues.FirstOrDefault(o => o.OptionKey == pageContent.Options[3].Key
                    && o.OptionValue == pageContent.Options[3].Value
                    && o.OptionDefaultValue == null
                    && o.CanEditOption));
            });
        }
        public void Sould_Delete_Page_Successfully()
        {
            RunActionInTransaction(session =>
                {
                    const string url = "/test-link/";
                    var uow = new DefaultUnitOfWork(session);
                    var repository = new DefaultRepository(uow);
                    
                    var page = TestDataProvider.CreateNewPageWithTagsContentsOptionsAndAccessRules(session);
                    
                    session.SaveOrUpdate(page);
                    session.Flush();
                    session.Clear();
                    
                    var pageService = new Mock<IPageService>();
                    pageService.Setup(f => f.ValidatePageUrl(It.IsAny<string>(), It.IsAny<Guid?>()));
                    pageService.Setup(f => f.CreatePagePermalink(It.IsAny<string>(), It.IsAny<string>())).Returns(url);

                    var sitemapService = new Mock<ISitemapService>();
                    sitemapService
                        .Setup(service => service.GetNodesByPage(It.IsAny<PageProperties>()))
                        .Returns(() => new List<SitemapNode>());

                    var urlService = new Mock<IUrlService>();
                    urlService.Setup(f => f.FixUrl(It.IsAny<string>())).Returns((string a) => a);

                    var securityService = new Mock<ICmsSecurityConfiguration>();
                    securityService.Setup(f => f.AccessControlEnabled).Returns(false);

                    var configurationService = new Mock<ICmsConfiguration>();
                    configurationService.Setup(f => f.Security).Returns(securityService.Object);

                    var command = new DeletePageCommand(null, sitemapService.Object, urlService.Object, configurationService.Object);
                    command.Repository = repository;
                    command.UnitOfWork = uow;

                    var result = command.Execute(new DeletePageViewModel
                                        {
                                            PageId = page.Id,
                                            UpdateSitemap = false,
                                            RedirectUrl = null,
                                            SecurityWord = "DELETE",
                                            Version = page.Version
                                        });

                    Assert.IsTrue(result);
                    session.Clear();

                    var actual = repository.AsQueryable<PageProperties>().FirstOrDefault(f => f.Id == page.Id && !f.IsDeleted);                    
                    Assert.IsNull(actual);   
                });
        }
        public void Should_Save_Options_Successfully()
        {
            RunActionInTransaction(session =>
            {
                var unitOfWork = new DefaultUnitOfWork(session);
                var repository = new DefaultRepository(unitOfWork);

                var optionService = new DefaultOptionService(repository);

                // Create layout with options
                var layout = TestDataProvider.CreateNewLayout();
                layout.LayoutOptions = new List<LayoutOption>();

                var option1 = TestDataProvider.CreateNewLayoutOption(layout);
                option1.Type = OptionType.Text;
                layout.LayoutOptions.Add(option1);

                var option2 = TestDataProvider.CreateNewLayoutOption(layout);
                option2.Type = OptionType.Text;
                layout.LayoutOptions.Add(option2);

                var option3 = TestDataProvider.CreateNewLayoutOption(layout);
                option3.Type = OptionType.Text;
                layout.LayoutOptions.Add(option3);

                session.SaveOrUpdate(layout);
                session.Flush();
                session.Clear();

                // Create fake options:
                // 1 should be kept
                // 2 should be updated
                // 3 should be inserted
                // option2 should be deleted
                var newOption1 = new LayoutOption { Key = option1.Key, Type = option1.Type, DefaultValue = option1.DefaultValue };
                var newOption2 = new LayoutOption { Key = option2.Key, Type = option2.Type, DefaultValue = TestDataProvider.ProvideRandomString(100) };
                var newOption3 = new LayoutOption { Key = TestDataProvider.ProvideRandomString(100), Type = OptionType.Text, DefaultValue = TestDataProvider.ProvideRandomString(100) };
                var newOptions = new List<IOption> { newOption1, newOption2, newOption3 };

                optionService.SetOptions<LayoutOption, Layout>(layout, newOptions);
                unitOfWork.Commit();

                // Load all options
                var options = repository.AsQueryable<LayoutOption>(lo => lo.Layout == layout).ToList();

                Assert.AreEqual(options.Count, 3);
                Assert.IsTrue(options.Any(o => o.Key == option1.Key && o.DefaultValue == option1.DefaultValue && o.Type == option1.Type));
                Assert.IsTrue(options.Any(o => o.Key == option2.Key && o.DefaultValue == newOption2.DefaultValue && o.Type == option2.Type));
                Assert.IsTrue(options.Any(o => o.Key == newOption3.Key && o.DefaultValue == newOption3.DefaultValue && o.Type == newOption3.Type));
            });
        }
        public void Should_Retrieve_Widgets_From_Database_Paged_And_Sorted_By_CategoryName()
        {
            RunActionInTransaction(session =>
                {
                    var widgets = new Widget[]
                                      {
                                         this.TestDataProvider.CreateNewServerControlWidget(),
                                         this.TestDataProvider.CreateNewServerControlWidget(),
                                         this.TestDataProvider.CreateNewHtmlContentWidget()
                                      };
                    int i = 0;
                    foreach (var widget in widgets)
                    {
                        widget.Name = "test name " + i++;
                        session.SaveOrUpdate(widget);
                    }
                    session.Flush();
                    session.Clear();

                    IUnitOfWork unitOfWork = new DefaultUnitOfWork(session);

                    GetSiteSettingsWidgetsCommand command = new GetSiteSettingsWidgetsCommand();
                    command.UnitOfWork = unitOfWork;
                    command.Repository = new DefaultRepository(unitOfWork);

                    var result = command.Execute(new SearchableGridOptions
                                                     {
                                                         PageSize = 20,
                                                         Column = "CategoryName",
                                                         Direction = SortDirection.Ascending,
                                                         PageNumber = 1,
                                                         SearchQuery = "test name 2"
                                                     });

                    Assert.IsNotNull(result);
                    Assert.AreEqual(1, result.Items.TotalItems);
                    Assert.AreEqual(widgets[2].Name, result.Items.First().WidgetName);
                });
        }
        public void Should_Create_New_Page_With_Access_Rules()
        {
            RunActionInTransaction(
                session =>
                    {
                        var tempLayout = TestDataProvider.CreateNewLayout();
                        session.SaveOrUpdate(tempLayout);
                        session.Flush();

                        var uow = new DefaultUnitOfWork(session);
                        var repository = new DefaultRepository(uow);
                        var configMock = new Mock<ICmsConfiguration>();
                        configMock.SetupAllProperties().Setup(f => f.Security.AccessControlEnabled).Returns(true);
                        configMock.Setup(f => f.Security.DefaultAccessRules).Returns(new AccessControlCollection
                                                                                         {
                                                                                             DefaultAccessLevel = "readwrite"
                                                                                         });
                        var config = configMock.Object;

                        var command = new CreatePageCommand(
                            new Mock<IPageService>().SetupAllProperties().Object,
                            new DefaultUrlService(uow, config),
                            config,
                            new DefaultAccessControlService(Container.Resolve<ISecurityService>(), new HttpRuntimeCacheService(), config),
                            new Mock<IOptionService>().SetupAllProperties().Object);

                        command.UnitOfWork = uow;
                        command.Repository = repository;

                        var request = new AddNewPageViewModel();
                        request.AccessControlEnabled = true;
                        request.PageTitle = "TestCreatePageCommand";
                        request.PageUrl = "/test-CreatePageCommand/";
                        request.TemplateId = tempLayout.Id;

                        request.UserAccessList = new List<UserAccessViewModel>(
                            new[]
                                {
                                    new UserAccessViewModel
                                        {
                                            Identity = "test 1",
                                            AccessLevel = AccessLevel.ReadWrite
                                        },

                                    new UserAccessViewModel
                                        {
                                            Identity = "test 2",
                                            AccessLevel = AccessLevel.Deny
                                        }
                                });

                        var response = command.Execute(request);
                        session.Clear();

                        Assert.IsNotNull(response);

                        var page = session.Query<Page>().FirstOrDefault(f => f.Id == response.PageId);
                        Assert.IsNotNull(page);
                        Assert.IsNotNull(page.AccessRules);
                        Assert.AreEqual(2, page.AccessRules.Count());

                    });
        }
        public void Should_Save_Page_Content_Options_Successfully()
        {
            RunActionInTransaction(session =>
            {
                // Create page content with options
                var content = TestDataProvider.CreateNewContent();
                var pageContent = TestDataProvider.CreateNewPageContent(content);
                FillContentWithOptions(content);
                FillPageContentWithOptions(content, pageContent);

                session.SaveOrUpdate(pageContent);
                session.Flush();
                session.Clear();

                // Random option value
                var randomOptionValue = TestDataProvider.CreateNewPageContentOption();

                // Create request
                var request = new ContentOptionValuesViewModel
                    {
                        OptionValues = new List<OptionValueEditViewModel>
                            {
                                  new OptionValueEditViewModel
                                      {
                                          // Must be updated
                                          OptionKey = pageContent.Options[0].Key,
                                          OptionValue = content.ContentOptions[0].DefaultValue,
                                          UseDefaultValue = false
                                      },
                                  new OptionValueEditViewModel
                                      {
                                          // Must be deleted
                                          OptionKey = pageContent.Options[1].Key,
                                          OptionValue = null,
                                          UseDefaultValue = true
                                      },
                                  new OptionValueEditViewModel
                                      {
                                          // Must be updated
                                          OptionKey = pageContent.Options[2].Key,
                                          OptionValue = null,
                                          UseDefaultValue = false
                                      },
                                  new OptionValueEditViewModel
                                      {
                                          // Must be created
                                          OptionValue = randomOptionValue.Value,
                                          OptionKey = randomOptionValue.Key,
                                          Type = OptionType.Text
                                      }

                            },
                        OptionValuesContainerId = pageContent.Id
                    };

                // Create command
                var unitOfWork = new DefaultUnitOfWork(session);
                var repository = new DefaultRepository(unitOfWork);
                var command = new SavePageContentOptionsCommand();
                command.UnitOfWork = unitOfWork;
                command.Repository = repository;
                command.OptionService = new DefaultOptionService(repository, new HttpRuntimeCacheService());
                var result = command.Execute(request);

                Assert.IsNotNull(result);
                Assert.Greater(result.PageContentVersion, pageContent.Version);

                // Check results: one of page content values must be deleted after save
                var results = repository
                    .AsQueryable<PageContentOption>(pco => pco.PageContent.Id == pageContent.Id
                        && !pco.IsDeleted
                        && !pco.PageContent.IsDeleted)
                    .ToList();
                Assert.AreEqual(results.Count, 3);
                Assert.IsNotNull(results.FirstOrDefault(pco => {
                    return pco.Key == pageContent.Options[0].Key && pco.Value == content.ContentOptions[0].DefaultValue;
                }));
                Assert.IsNotNull(results.FirstOrDefault(pco => {
                    return pco.Key == pageContent.Options[2].Key && pco.Value == null;
                }));
                Assert.IsNotNull(results.FirstOrDefault(pco => pco.Key == randomOptionValue.Key
                    && pco.Value == randomOptionValue.Value));
            });
        }
        public void Should_Save_Page_Content_Options_Successfully()
        {
            RunActionInTransaction(session =>
            {
                // Create page content with options
                var content = TestDataProvider.CreateNewContent();
                var pageContent = TestDataProvider.CreateNewPageContent(content);
                FillContentWithOptions(content);
                FillPageContentWithOptions(content, pageContent);

                session.SaveOrUpdate(pageContent);
                session.Flush();
                session.Clear();

                // Random option value
                var randomOptionValue = TestDataProvider.CreateNewPageContentOption();

                // Create request
                var request = new PageContentOptionsViewModel
                    {
                        WidgetOptions = new List<PageContentOptionViewModel>
                            {
                                  new PageContentOptionViewModel
                                      {
                                          // Will be deleted because of default value
                                          OptionValue = content.ContentOptions[0].DefaultValue,
                                          OptionKey = pageContent.Options[0].Key,
                                          OptionDefaultValue = content.ContentOptions[0].DefaultValue
                                      },
                                  new PageContentOptionViewModel
                                      {
                                          // Will be deleted because of null value
                                          OptionValue = null,
                                          OptionKey = pageContent.Options[1].Key
                                      },
                                  new PageContentOptionViewModel
                                      {
                                          OptionValue = pageContent.Options[2].Value,
                                          OptionKey = pageContent.Options[2].Key
                                      },
                                  new PageContentOptionViewModel
                                      {
                                          // Random value
                                          OptionValue = randomOptionValue.Value,
                                          OptionKey = randomOptionValue.Key
                                      }

                            },
                        PageContentId = pageContent.Id
                    };

                // Create command
                var unitOfWork = new DefaultUnitOfWork(session);
                var repository = new DefaultRepository(unitOfWork);
                var command = new SavePageContentOptionsCommand();
                command.UnitOfWork = unitOfWork;
                command.Repository = repository;
                var result = command.Execute(request);

                Assert.IsTrue(result);

                // Check results: one of page content values must be deleted after save
                var results = repository
                    .AsQueryable<PageContentOption>(pco => pco.PageContent.Id == pageContent.Id
                        && !pco.IsDeleted
                        && !pco.PageContent.IsDeleted)
                    .ToList();
                Assert.AreEqual(results.Count, 2);
                Assert.IsNotNull(results.FirstOrDefault(pco => pco.Key == pageContent.Options[2].Key
                    && pco.Value == pageContent.Options[2].Value));
                Assert.IsNotNull(results.FirstOrDefault(pco => pco.Key == randomOptionValue.Key
                    && pco.Value == randomOptionValue.Value));
            });
        }
        public void Should_Sort_Page_Content_Successfully()
        {
            RunActionInTransaction(session =>
            {
                var layout = TestDataProvider.CreateNewLayout();
                var region = TestDataProvider.CreateNewRegion();

                layout.LayoutRegions = new List<LayoutRegion>
                    {
                        TestDataProvider.CreateNewLayoutRegion(layout, region),
                    };

                var page = TestDataProvider.CreateNewPageProperties(layout);
                page.PageContents = new[]
                    {
                        TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region),
                        TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region),
                        TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region)
                    };

                session.SaveOrUpdate(page);
                session.Flush();
                session.Clear();

                IUnitOfWork unitOfWork = new DefaultUnitOfWork(session);

                var configuration = Container.Resolve<ICmsConfiguration>();
                SortPageContentCommand command = new SortPageContentCommand(configuration);
                command.UnitOfWork = unitOfWork;
                command.Repository = new DefaultRepository(unitOfWork);
                command.Context = new Mock<ICommandContext>().Object;

                var accessControlService = new Mock<IAccessControlService>();
                accessControlService.Setup(s => s.DemandAccess(It.IsAny<IPrincipal>(), It.IsAny<string>()));
                command.AccessControlService = accessControlService.Object;
                
                var request = new PageContentSortViewModel
                    {
                        PageId = page.Id,
                        PageContents =
                            new List<ContentSortViewModel>
                                {
                                    new ContentSortViewModel { RegionId = region.Id, PageContentId = page.PageContents[2].Id, Version = page.PageContents[2].Version },
                                    new ContentSortViewModel { RegionId = region.Id, PageContentId = page.PageContents[1].Id, Version = page.PageContents[1].Version },
                                    new ContentSortViewModel { RegionId = region.Id, PageContentId = page.PageContents[0].Id, Version = page.PageContents[0].Version },
                                }
                    };
                var response = command.Execute(request);

                Assert.IsNotNull(response);
                Assert.IsNotNull(response.PageContents);
                Assert.AreEqual(response.PageContents.Count, request.PageContents.Count);

                session.Flush();
                session.Clear();

                var updatedPage = command.Repository.AsQueryable<PageContent>(f => f.Page.Id == page.Id).ToList();

                Assert.AreEqual(2, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[0].Id).Order);
                Assert.AreEqual(1, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[1].Id).Order);
                Assert.AreEqual(0, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[2].Id).Order);
            });
        }
 private IRepository CreateRepository(ISession session)
 {
     var unitOfWork = new DefaultUnitOfWork(session);
     var repository = new DefaultRepository(unitOfWork);
     return repository;
 }
        public void ShouldRetrieveSecondChildPageOptionsSuccessfully()
        {
            RunActionInTransaction(session =>
            {
                var unitOfWork = new DefaultUnitOfWork(session);
                var repository = new DefaultRepository(unitOfWork);

                var pages = CreateNestedOptions(session, 3);

                var optionService = new DefaultOptionService(repository, new HttpRuntimeCacheService());
                var optionValues = optionService.GetMergedMasterPagesOptionValues(pages[2].Id, pages[2].MasterPage.Id, null);

                Assert.AreEqual(optionValues.Count, 5);
                Assert.IsTrue(optionValues.Any(o => o.OptionKey == "l1" && o.OptionValue == "l1"));
                Assert.IsTrue(optionValues.Any(o => o.OptionKey == "l2" && o.OptionValue == "l2p2"));
                Assert.IsTrue(optionValues.Any(o => o.OptionKey == "l3" && o.OptionValue == "l3p3"));
                Assert.IsTrue(optionValues.Any(o => o.OptionKey == "p1" && o.OptionValue == "p1"));
                Assert.IsTrue(optionValues.Any(o => o.OptionKey == "p2" && o.OptionValue == "p2"));
            });
        }