public void GivenTypeArray_WhenUpdateAvailablePageTypesCalled_SetsPageTypeAllowedPageTypes()
        {
            PageTypeDefinition definition = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();

            definition.Attribute.AvailablePageTypes = new[] { typeof(object) };
            IPageType                 existingPageType   = new NativePageType();
            MockRepository            mocks              = new MockRepository();
            List <PageTypeDefinition> definitions        = new List <PageTypeDefinition>();
            PageTypeDefinition        definitionToReturn = new PageTypeDefinition
            {
                Type      = typeof(object),
                Attribute = new PageTypeAttribute()
            };

            definitions.Add(definitionToReturn);
            var pageTypeDefinitionLocator = PageTypeDefinitionLocatorFactory.Mock();

            pageTypeDefinitionLocator.Setup(locator => locator.GetPageTypeDefinitions()).Returns(definitions);
            PageTypeUpdater pageTypeUpdater = mocks.PartialMock <PageTypeUpdater>(
                pageTypeDefinitionLocator.Object,
                new PageTypeFactory(),
                new PageTypeValueExtractor(),
                new PageTypeLocator(new PageTypeFactory()));
            IPageType allowedPageType = new NativePageType();

            allowedPageType.ID = 1;
            pageTypeUpdater.Stub(updater => updater.GetExistingPageType(definitionToReturn)).Return(allowedPageType);
            pageTypeUpdater.Replay();

            pageTypeUpdater.UpdateAvailablePageTypes(existingPageType, definition.Attribute.AvailablePageTypes);

            Assert.Equal <int[]>(new[] { 1 }, existingPageType.AllowedPageTypes);
        }
Exemplo n.º 2
0
        public void WhenUpdatePageTypeCalled_CallsPageTypeFactorySave()
        {
            PageTypeDefinition definition      = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            PageTypeUpdater    pageTypeUpdater = CreateFakePageTypeUpdaterWithUpdatePageTypeMethodHelperStubs();

            pageTypeUpdater.UpdatePageType(definition);

            pageTypeUpdater.PageTypeRepository.AssertWasCalled(factory => factory.Save(Arg <IPageType> .Is.NotNull));
        }
Exemplo n.º 3
0
        public void UpdatePageType_gets_existing_PageType()
        {
            PageTypeDefinition definition      = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            PageTypeUpdater    pageTypeUpdater = CreateFakePageTypeUpdaterWithUpdatePageTypeMethodHelperStubs();

            pageTypeUpdater.UpdatePageType(definition);

            pageTypeUpdater.AssertWasCalled(updater => updater.GetExistingPageType(definition));
        }
        public void WhenUpdatePageTypeCalled_CallsUpdateAvailablePageTypes()
        {
            PageTypeDefinition definition      = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            PageTypeUpdater    pageTypeUpdater = CreateFakePageTypeUpdaterWithUpdatePageTypeMethodHelperStubs();

            pageTypeUpdater.UpdatePageType(definition);

            pageTypeUpdater.AssertWasCalled(updater => updater.UpdateAvailablePageTypes(Arg <IPageType> .Is.Anything, Arg <Type[]> .Is.Anything));
        }
Exemplo n.º 5
0
        public void WhenUpdatePageTypeCalled_CallsUpdateFilename()
        {
            PageTypeDefinition definition      = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            IPageType          pageType        = new NativePageType();
            PageTypeUpdater    pageTypeUpdater = CreateFakePageTypeUpdaterWithUpdatePageTypeMethodHelperStubs();

            pageTypeUpdater.UpdatePageType(definition);

            pageTypeUpdater.AssertWasCalled(updater => updater.UpdateFilename(pageType, definition.Attribute));
        }
Exemplo n.º 6
0
        public void WhenUpdatePageTypeCalls_CallsUpdateDefaultVisibleInMenu()
        {
            PageTypeDefinition definition       = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            IPageType          existingPageType = new NativePageType();
            PageTypeUpdater    pageTypeUpdater  = CreateFakePageTypeUpdaterWithUpdatePageTypeMethodHelperStubs();

            pageTypeUpdater.UpdatePageType(definition);

            pageTypeUpdater.AssertWasCalled(updater => updater.UpdateDefaultVisibleInMenu(existingPageType, definition.Attribute));
        }
        public void GivenDefinitionWithNoSpecifiedName_CreateNewPageType_ReturnsNewPageTypeWithNameSetToTheNameOfTheTypeName()
        {
            PageTypeDefinition definition      = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            PageTypeUpdater    pageTypeUpdater = CreatePageTypeUpdater();

            SetupPageTypeUpdaterWithFakePageTypeFactory(pageTypeUpdater);

            IPageType returnedPageType = pageTypeUpdater.CreateNewPageType(definition);

            Assert.Equal(typeof(object).Name, returnedPageType.Name);
        }
        public void WhenCreateNewPageTypeCalled_CallsPageTypeFactorySave()
        {
            PageTypeDefinition definition      = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            PageTypeUpdater    pageTypeUpdater = CreatePageTypeUpdater();

            SetupPageTypeUpdaterWithFakePageTypeFactory(pageTypeUpdater);

            pageTypeUpdater.CreateNewPageType(definition);

            pageTypeUpdater.PageTypeFactory.AssertWasCalled(factory => factory.Save(Arg <IPageType> .Is.NotNull));
        }
Exemplo n.º 9
0
        public void GivenNoAvailablePageTypes_WhenUpdateAvailablePageTypesCalled_SetsPageTypeAllowedPageTypesToEmptyArray()
        {
            PageTypeDefinition definition       = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            IPageType          existingPageType = new NativePageType();
            MockRepository     mocks            = new MockRepository();
            PageTypeUpdater    pageTypeUpdater  = CreatePageTypeUpdater();

            pageTypeUpdater.UpdateAvailablePageTypes(existingPageType, definition.Attribute.AvailablePageTypes);

            Assert.Equal <int[]>(new int[0], existingPageType.AllowedPageTypes);
        }
Exemplo n.º 10
0
        public void GivenNoNameSetInAttribute_WhenUpdatePageTypeCalled_UpdatesPageTypeNameWithName()
        {
            PageTypeDefinition definition      = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            IPageType          pageType        = new NativePageType();
            PageTypeUpdater    pageTypeUpdater = CreatePageTypeUpdater();
            string             name            = definition.Type.Name;

            pageTypeUpdater.UpdateName(pageType, definition);

            Assert.Equal <string>(name, pageType.Name);
        }
Exemplo n.º 11
0
        public void GivenValue_UpdateDefaultVisibleInMenu_UpdatesPageTypeDefaultVisibleInMenuWithValue(bool defaultVisibleInMenu)
        {
            PageTypeDefinition definition = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();

            definition.Attribute.DefaultVisibleInMenu = defaultVisibleInMenu;
            IPageType       pageType        = new NativePageType();
            PageTypeUpdater pageTypeUpdater = CreatePageTypeUpdater();

            pageTypeUpdater.UpdateDefaultVisibleInMenu(pageType, definition.Attribute);

            Assert.Equal <bool>(defaultVisibleInMenu, pageType.DefaultVisibleInMenu);
        }
        public void GivenDefinitionWithASpecifiedFilename_CreateNewPageType_ReturnsPageTypeWithThatFilename()
        {
            PageTypeDefinition definition = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();

            definition.Attribute.Filename = TestValueUtility.CreateRandomString();
            PageTypeUpdater pageTypeUpdater = CreatePageTypeUpdater();

            SetupPageTypeUpdaterWithFakePageTypeFactory(pageTypeUpdater);

            IPageType returnedPageType = pageTypeUpdater.CreateNewPageType(definition);

            Assert.Equal <string>(definition.Attribute.Filename, returnedPageType.FileName);
        }
        public void Given_definition_without_a_specified_filename_CreateNewPageType_returns_PageType_with_default_filename()
        {
            PageTypeDefinition definition      = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            PageTypeUpdater    pageTypeUpdater = CreatePageTypeUpdater();

            SetupPageTypeUpdaterWithFakePageTypeFactory(pageTypeUpdater);
            //Override the default filename to something without a slash in the beginning as
            //the PageType.Filename set method requires that EPiServer is started if
            //the filename begins with a slash
            pageTypeUpdater.DefaultFilename = TestValueUtility.CreateRandomString();

            IPageType returnedPageType = pageTypeUpdater.CreateNewPageType(definition);

            Assert.Equal <string>(pageTypeUpdater.DefaultFilename, returnedPageType.FileName);
        }
Exemplo n.º 14
0
        public void GivenPageTypeWithNoGuidOrSpecifiedName_GetExistingPageType_ReturnsPageTypeReturnedFromPageTypeFactoryLoad()
        {
            MockRepository     mockRepository         = new MockRepository();
            PageTypeDefinition pageTypeDefinition     = PageTypeUpdaterTestsUtility.CreateBasicPageTypeDefinition();
            PageTypeRepository fakePageTypeRepository = mockRepository.Stub <PageTypeRepository>();
            IPageType          pageTypeFromFactory    = new NativePageType();

            pageTypeFromFactory.ID = 1;
            fakePageTypeRepository.Expect(factory => factory.Load(pageTypeDefinition.Type.Name)).Return(pageTypeFromFactory);
            fakePageTypeRepository.Replay();
            PageTypeUpdater pageTypeUpdater = PageTypeUpdaterFactory.Create(
                PageTypeDefinitionLocatorFactory.Stub(), fakePageTypeRepository);

            IPageType returnedPageType = pageTypeUpdater.GetExistingPageType(pageTypeDefinition);

            fakePageTypeRepository.AssertWasCalled(factory => factory.Load(pageTypeDefinition.Type.Name));
            Assert.Equal <int>(pageTypeFromFactory.ID, returnedPageType.ID);
        }