Ejemplo n.º 1
0
        public void DirtyProperty_WasDirty_UserProperty()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
            var prop    = content.Properties.First();

            content.ResetDirtyProperties(false);
            Assert.IsFalse(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            prop.SetValue("a");
            prop.SetValue("b");
            Assert.IsTrue(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            content.ResetDirtyProperties(false);
            Assert.IsFalse(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            prop.SetValue("a");
            prop.SetValue("b");
            content.ResetDirtyProperties(true); // what PersistUpdatedItem does
            Assert.IsFalse(content.IsDirty());
            //Assert.IsFalse(content.WasDirty()); // not impacted by user properties
            Assert.IsTrue(content.WasDirty()); // now it is!
            prop.SetValue("a");
            prop.SetValue("b");
            content.ResetDirtyProperties(); // what PersistUpdatedItem does
            Assert.IsFalse(content.IsDirty());
            //Assert.IsFalse(content.WasDirty()); // not impacted by user properties
            Assert.IsTrue(content.WasDirty()); // now it is!
        }
Ejemplo n.º 2
0
        public void Can_Serialize_Without_Error()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            contentType.Id = 99;
            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
            var i       = 200;

            foreach (var property in content.Properties)
            {
                property.Id = ++i;
            }
            content.Id         = 10;
            content.CreateDate = DateTime.Now;
            content.CreatorId  = 22;
            content.Key        = Guid.NewGuid();
            content.Level      = 3;
            content.Path       = "-1,4,10";
            content.ContentSchedule.Add(DateTime.Now, DateTime.Now.AddDays(1));
            //content.ChangePublishedState(PublishedState.Publishing);
            content.SortOrder  = 5;
            content.TemplateId = 88;
            content.Trashed    = false;
            content.UpdateDate = DateTime.Now;
            content.WriterId   = 23;

            var json = JsonConvert.SerializeObject(content);

            Debug.Print(json);
        }
Ejemplo n.º 3
0
        public void Can_Verify_Content_Is_Published()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            content.ResetDirtyProperties();
            content.PublishedState = PublishedState.Publishing;

            Assert.IsFalse(content.IsPropertyDirty("Published"));
            Assert.IsFalse(content.Published);
            Assert.IsFalse(content.IsPropertyDirty("Name"));
            Assert.AreEqual(PublishedState.Publishing, content.PublishedState);

            // the repo would do
            content.Published = true;

            // and then
            Assert.IsTrue(content.IsPropertyDirty("Published"));
            Assert.IsTrue(content.Published);
            Assert.IsFalse(content.IsPropertyDirty("Name"));
            Assert.AreEqual(PublishedState.Published, content.PublishedState);

            // and before returning,
            content.ResetDirtyProperties();

            // and then
            Assert.IsFalse(content.IsPropertyDirty("Published"));
            Assert.IsTrue(content.Published);
            Assert.IsFalse(content.IsPropertyDirty("Name"));
            Assert.AreEqual(PublishedState.Published, content.PublishedState);
        }
Ejemplo n.º 4
0
        public void After_Committing_Changes_Was_Dirty_Is_True_On_Changed_Property()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            contentType.ResetDirtyProperties(); //reset
            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "test", -1);

            content.ResetDirtyProperties();

            // Act
            content.SetValue("title", "new title");
            Assert.That(content.IsEntityDirty(), Is.False);
            Assert.That(content.IsDirty(), Is.True);
            Assert.That(content.IsPropertyDirty("title"), Is.True);
            Assert.That(content.IsAnyUserPropertyDirty(), Is.True);
            Assert.That(content.GetDirtyUserProperties().Count(), Is.EqualTo(1));
            Assert.That(content.Properties[0].IsDirty(), Is.True);
            Assert.That(content.Properties["title"].IsDirty(), Is.True);

            content.ResetDirtyProperties(); //this would be like committing the entity

            // Assert
            Assert.That(content.WasDirty(), Is.True);
            Assert.That(content.Properties[0].WasDirty(), Is.True);


            Assert.That(content.WasPropertyDirty("title"), Is.True);
            Assert.That(content.Properties["title"].IsDirty(), Is.False);
            Assert.That(content.Properties["title"].WasDirty(), Is.True);
        }
Ejemplo n.º 5
0
        public void DirtyProperty_UpdateDate()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
            var prop    = content.Properties.First();

            content.ResetDirtyProperties(false);
            var d = content.UpdateDate;

            prop.SetValue("A");
            Assert.IsTrue(content.IsAnyUserPropertyDirty());
            Assert.IsFalse(content.IsEntityDirty());
            Assert.AreEqual(d, content.UpdateDate);

            content.UpdateDate = DateTime.Now;
            Assert.IsTrue(content.IsEntityDirty());
            Assert.AreNotEqual(d, content.UpdateDate);

            // so... changing UpdateDate would count as a content property being changed
            // however in ContentRepository.PersistUpdatedItem, we change UpdateDate AFTER
            // we've tested for RequiresSaving & RequiresNewVersion so it's OK
        }
Ejemplo n.º 6
0
        public void Can_Add_New_Property_To_New_PropertyType_In_New_PropertyGroup()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            // Act
            var propertyType = new PropertyType("test", ValueStorageType.Ntext, "subtitle")
            {
                Name        = "Subtitle",
                Description = "Optional subtitle",
                Mandatory   = false,
                SortOrder   = 3,
                DataTypeId  = -88
            };
            var propertyGroup = new PropertyGroup(true)
            {
                Name = "Test Group", SortOrder = 3
            };

            propertyGroup.PropertyTypes.Add(propertyType);
            contentType.PropertyGroups.Add(propertyGroup);
            var newProperty = new Property(propertyType);

            newProperty.SetValue("Subtitle Test");
            content.Properties.Add(newProperty);

            // Assert
            Assert.That(content.Properties.Count, Is.EqualTo(5));
            Assert.That(content.Properties["subtitle"].GetValue(), Is.EqualTo("Subtitle Test"));
            Assert.That(content.Properties["title"].GetValue(), Is.EqualTo("Textpage textpage"));
        }
        public void DirtyProperty_WasDirty_ContentProperty()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            content.ResetDirtyProperties(false);
            Assert.IsFalse(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            content.Published = false;
            content.Published = true;
            Assert.IsTrue(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            content.ResetDirtyProperties(false);
            Assert.IsFalse(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            content.Published = false;
            content.Published = true;
            content.ResetDirtyProperties(true); // what PersistUpdatedItem does
            Assert.IsFalse(content.IsDirty());
            Assert.IsTrue(content.WasDirty());
            content.Published = false;
            content.Published = true;
            content.ResetDirtyProperties(); // what PersistUpdatedItem does
            Assert.IsFalse(content.IsDirty());
            Assert.IsTrue(content.WasDirty());
        }
Ejemplo n.º 8
0
        public void DirtyProperty_OnlyIfActuallyChanged_User()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
            var prop    = content.Properties.First();

            // if you assign a user property with its value it is not dirty
            // if you assign it with another value then back, it is dirty

            prop.SetValue("A");
            content.ResetDirtyProperties(false);
            Assert.IsFalse(prop.IsDirty());
            prop.SetValue("B");
            Assert.IsTrue(prop.IsDirty());
            content.ResetDirtyProperties(false);
            Assert.IsFalse(prop.IsDirty());
            prop.SetValue("B");
            Assert.IsFalse(prop.IsDirty());
            prop.SetValue("A");
            prop.SetValue("B");
            Assert.IsTrue(prop.IsDirty());
        }
Ejemplo n.º 9
0
        public void Can_Verify_Content_Is_Published()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            content.ResetDirtyProperties();
            content.PublishedState = PublishedState.Publishing;

            Assert.IsFalse(content.IsPropertyDirty("Published"));
            Assert.IsFalse(content.Published);
            Assert.IsFalse(content.IsPropertyDirty("Name"));
            Assert.AreEqual(PublishedState.Publishing, content.PublishedState);

            // the repo would do
            content.Published = true;

            // and then
            Assert.IsTrue(content.IsPropertyDirty("Published"));
            Assert.IsTrue(content.Published);
            Assert.IsFalse(content.IsPropertyDirty("Name"));
            Assert.AreEqual(PublishedState.Published, content.PublishedState);

            // and before returning,
            content.ResetDirtyProperties();

            // and then
            Assert.IsFalse(content.IsPropertyDirty("Published"));
            Assert.IsTrue(content.Published);
            Assert.IsFalse(content.IsPropertyDirty("Name"));
            Assert.AreEqual(PublishedState.Published, content.PublishedState);
        }
Ejemplo n.º 10
0
        public void Can_Serialize_Without_Error()
        {
            var ss = new SerializationService(new JsonNetSerializer());

            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            contentType.Id = 99;
            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
            var i       = 200;

            foreach (var property in content.Properties)
            {
                property.Id = ++i;
            }
            content.Id         = 10;
            content.CreateDate = DateTime.Now;
            content.CreatorId  = 22;
            content.Key        = Guid.NewGuid();
            content.Level      = 3;
            content.Path       = "-1,4,10";
            content.ContentSchedule.Add(DateTime.Now, DateTime.Now.AddDays(1));
            //content.ChangePublishedState(PublishedState.Publishing);
            content.SortOrder  = 5;
            content.TemplateId = 88;
            content.Trashed    = false;
            content.UpdateDate = DateTime.Now;
            content.WriterId   = 23;

            var result = ss.ToStream(content);
            var json   = result.ResultStream.ToJsonString();

            Debug.Print(json);
        }
        public void CreateTestData()
        {
            //Create and Save ContentType "textpage" -> NodeDto.NodeIdSeed
            ContentType contentType = MockedContentTypes.CreateTextPageContentType();

            ServiceContext.ContentTypeService.Save(contentType);
        }
        public void DirtyProperty_WasDirty_UserProperty()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
            var prop        = content.Properties.First();

            content.ResetDirtyProperties(false);
            Assert.IsFalse(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            prop.SetValue("a");
            prop.SetValue("b");
            Assert.IsTrue(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            content.ResetDirtyProperties(false);
            Assert.IsFalse(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            prop.SetValue("a");
            prop.SetValue("b");
            content.ResetDirtyProperties(true); // what PersistUpdatedItem does
            Assert.IsFalse(content.IsDirty());
            //Assert.IsFalse(content.WasDirty()); // not impacted by user properties
            Assert.IsTrue(content.WasDirty()); // now it is!
            prop.SetValue("a");
            prop.SetValue("b");
            content.ResetDirtyProperties(); // what PersistUpdatedItem does
            Assert.IsFalse(content.IsDirty());
            //Assert.IsFalse(content.WasDirty()); // not impacted by user properties
            Assert.IsTrue(content.WasDirty()); // now it is!
        }
Ejemplo n.º 13
0
        public void Can_Update_PropertyType_Through_Content_Properties()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            // Act - note that the PropertyType's properties like SortOrder is not updated through the Content object
            var propertyType = new PropertyType("test", ValueStorageType.Ntext, "title")
            {
                Name        = "Title",
                Description = "Title description added",
                Mandatory   = false,
                SortOrder   = 10,
                DataTypeId  = -88
            };

            content.Properties.Add(new Property(propertyType));

            // Assert
            Assert.That(content.Properties.Count, Is.EqualTo(4));
            Assert.That(contentType.PropertyTypes.First(x => x.Alias == "title").SortOrder, Is.EqualTo(1));
            Assert.That(content.Properties["title"].GetValue(), Is.EqualTo("Textpage textpage"));
        }
Ejemplo n.º 14
0
        public void DirtyProperty_WasDirty_ContentSortOrder()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            content.ResetDirtyProperties(false);
            Assert.IsFalse(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            content.SortOrder = 0;
            content.SortOrder = 1;
            Assert.IsTrue(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            content.ResetDirtyProperties(false);
            Assert.IsFalse(content.IsDirty());
            Assert.IsFalse(content.WasDirty());
            content.SortOrder = 0;
            content.SortOrder = 1;
            content.ResetDirtyProperties(true); // what PersistUpdatedItem does
            Assert.IsFalse(content.IsDirty());
            Assert.IsTrue(content.WasDirty());
            content.SortOrder = 0;
            content.SortOrder = 1;
            content.ResetDirtyProperties(); // what PersistUpdatedItem does
            Assert.IsFalse(content.IsDirty());
            Assert.IsTrue(content.WasDirty());
        }
Ejemplo n.º 15
0
        public void UnpublishedNameChanges()
        {
            var urlSegmentProvider = new DefaultUrlSegmentProvider();

            var contentType = MockedContentTypes.CreateTextPageContentType();

            ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
            ServiceContext.ContentTypeService.Save(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "hello", Constants.System.Root);

            ServiceContext.ContentService.SaveAndPublish(content);
            var cachedContent = ServiceContext.ContentService.GetById(content.Id);
            var segment       = urlSegmentProvider.GetUrlSegment(cachedContent);

            // Does a new node work?

            Assert.AreEqual("hello", segment);

            content.Name  = "goodbye";
            cachedContent = ServiceContext.ContentService.GetById(content.Id);
            segment       = urlSegmentProvider.GetUrlSegment(cachedContent);

            // We didn't save anything, so all should still be the same

            Assert.AreEqual("hello", segment);

            ServiceContext.ContentService.Save(content);
            cachedContent = ServiceContext.ContentService.GetById(content.Id);
            segment       = urlSegmentProvider.GetUrlSegment(cachedContent);

            // At this point we have saved the new name, but not published. The url should still be the previous name

            Assert.AreEqual("hello", segment);

            PublishedSnapshotService.Rebuild();

            cachedContent = ServiceContext.ContentService.GetById(content.Id);
            segment       = urlSegmentProvider.GetUrlSegment(cachedContent);

            // After a rebuild, the unpublished name should still not be the url.
            // This was previously incorrect, per #11074

            Assert.AreEqual("hello", segment);

            ServiceContext.ContentService.SaveAndPublish(content);
            cachedContent = ServiceContext.ContentService.GetById(content.Id);
            segment       = urlSegmentProvider.GetUrlSegment(cachedContent);

            // The page has now been published, so we should see the new url segment
            Assert.AreEqual("goodbye", segment);

            PublishedSnapshotService.Rebuild();
            cachedContent = ServiceContext.ContentService.GetById(content.Id);
            segment       = urlSegmentProvider.GetUrlSegment(cachedContent);

            // Just double checking that things remain after a rebuild
            Assert.AreEqual("goodbye", segment);
        }
Ejemplo n.º 16
0
        public void PropertyGroups_Collection_FirstOrDefault_Returns_Null()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Assert.That(contentType.PropertyGroups, Is.Not.Null);
            Assert.That(contentType.PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals("Content")) == null, Is.False);
            Assert.That(contentType.PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals("Test")) == null, Is.True);
            Assert.That(contentType.PropertyGroups.Any(x => x.Name.InvariantEquals("Test")), Is.False);
        }
Ejemplo n.º 17
0
        public void Can_Deep_Clone_Content_Type_Perf_Test()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            contentType.Id = 99;

            var i = 200;

            foreach (var propertyType in contentType.PropertyTypes)
            {
                propertyType.Id = ++i;
            }
            foreach (var group in contentType.PropertyGroups)
            {
                group.Id = ++i;
            }
            contentType.AllowedTemplates = new[] { new Template((string)"Name", (string)"name")
                                                   {
                                                       Id = 200
                                                   }, new Template((string)"Name2", (string)"name2")
                                                   {
                                                       Id = 201
                                                   } };
            contentType.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => 888), 8, "sub"), new ContentTypeSort(new Lazy <int>(() => 889), 9, "sub2") };
            contentType.Id         = 10;
            contentType.CreateDate = DateTime.Now;
            contentType.CreatorId  = 22;
            contentType.SetDefaultTemplate(new Template((string)"Test Template", (string)"testTemplate")
            {
                Id = 88
            });
            contentType.Description = "test";
            contentType.Icon        = "icon";
            contentType.IsContainer = true;
            contentType.Thumbnail   = "thumb";
            contentType.Key         = Guid.NewGuid();
            contentType.Level       = 3;
            contentType.Path        = "-1,4,10";
            contentType.SortOrder   = 5;
            contentType.Trashed     = false;
            contentType.UpdateDate  = DateTime.Now;

            var proflog = GetTestProfilingLogger();

            using (proflog.DebugDuration <ContentTypeTests>("STARTING PERF TEST"))
            {
                for (var j = 0; j < 1000; j++)
                {
                    using (proflog.DebugDuration <ContentTypeTests>("Cloning content type"))
                    {
                        var clone = (ContentType)contentType.DeepClone();
                    }
                }
            }
        }
        public void DirtyProperty_Reset_Clears_SavedPublishedState()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            content.PublishedState = PublishedState.Publishing;
            Assert.IsFalse(content.Published);
            content.ResetDirtyProperties(false); // resets
            Assert.AreEqual(PublishedState.Unpublished, content.PublishedState);
            Assert.IsFalse(content.Published);
        }
Ejemplo n.º 19
0
        public void Can_Verify_Mocked_Content()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            // Act

            // Assert
            Assert.That(content, Is.Not.Null);
        }
        public void CreateTestData()
        {
            //Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed)
            ContentType simpleContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage");

            ServiceContext.ContentTypeService.Save(simpleContentType);

            //Create and Save ContentType "textPage" -> (NodeDto.NodeIdSeed + 1)
            ContentType textpageContentType = MockedContentTypes.CreateTextPageContentType();

            ServiceContext.ContentTypeService.Save(textpageContentType);
        }
Ejemplo n.º 21
0
        public void If_Not_Committed_Was_Dirty_Is_False()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            // Act
            contentType.Alias = "newAlias";

            // Assert
            Assert.That(contentType.IsDirty(), Is.True);
            Assert.That(contentType.WasDirty(), Is.False);
        }
Ejemplo n.º 22
0
        public void Detect_That_A_Property_Is_Removed()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Assert.That(contentType.WasPropertyDirty("HasPropertyTypeBeenRemoved"), Is.False);

            // Act
            contentType.RemovePropertyType("title");

            // Assert
            Assert.That(contentType.IsPropertyDirty("HasPropertyTypeBeenRemoved"), Is.True);
        }
Ejemplo n.º 23
0
        public void All_Dirty_Properties_Get_Reset()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            content.ResetDirtyProperties(false);

            Assert.IsFalse(content.IsDirty());
            foreach (var prop in content.Properties)
            {
                Assert.IsFalse(prop.IsDirty());
            }
        }
Ejemplo n.º 24
0
        public void Publishing_Set_Value()
        {
            var contentTypeService = ServiceContext.ContentTypeService;

            var contentType = MockedContentTypes.CreateTextPageContentType();

            ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
            contentTypeService.Save(contentType);

            var contentService = ServiceContext.ContentService;

            IContent document = new Content("content", -1, contentType);

            void OnSaving(IContentService sender, ContentSavingEventArgs e)
            {
                var saved = e.SavedEntities.First();

                Assert.IsTrue(document.GetValue <string>("title").IsNullOrWhiteSpace());

                saved.SetValue("title", "title");
            }

            void OnSaved(IContentService sender, ContentSavedEventArgs e)
            {
                var saved = e.SavedEntities.First();

                Assert.AreSame("title", document.GetValue <string>("title"));

                //we're only dealing with invariant here
                var propValue = saved.Properties["title"].Values.First(x => x.Culture == null && x.Segment == null);

                Assert.AreEqual("title", propValue.EditedValue);
                Assert.AreEqual("title", propValue.PublishedValue);
            }

            //We are binding to Saving (not Publishing), because the Publishing event is really just used for cancelling, it should not be
            //used for setting values and it won't actually work! This is because the Publishing event is raised AFTER the values on the model
            //are published, but Saving is raised BEFORE.
            ContentService.Saving += OnSaving;
            ContentService.Saved  += OnSaved;
            try
            {
                contentService.SaveAndPublish(document);
            }
            finally
            {
                ContentService.Saving -= OnSaving;
                ContentService.Saved  -= OnSaved;
            }
        }
Ejemplo n.º 25
0
        public void Can_Set_Property_Value_As_String()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            // Act
            content.SetValue("title", "This is the new title");

            // Assert
            Assert.That(content.Properties.Any(), Is.True);
            Assert.That(content.Properties["title"], Is.Not.Null);
            Assert.That(content.Properties["title"].GetValue(), Is.EqualTo("This is the new title"));
        }
Ejemplo n.º 26
0
        public void Can_Verify_Dirty_Property_On_Content()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            // Act
            content.ResetDirtyProperties();
            content.Name = "New Home";

            // Assert
            Assert.That(content.Name, Is.EqualTo("New Home"));
            Assert.That(content.IsPropertyDirty("Name"), Is.True);
        }
Ejemplo n.º 27
0
        public void DirtyProperty_Reset_Clears_SavedPublishedState()
        {
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            content.PublishedState = PublishedState.Publishing;
            Assert.IsFalse(content.Published);
            content.ResetDirtyProperties(false); // resets
            Assert.AreEqual(PublishedState.Unpublished, content.PublishedState);
            Assert.IsFalse(content.Published);
        }
Ejemplo n.º 28
0
        public void Can_Verify_Mocked_Content()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            // Act

            // Assert
            Assert.That(content, Is.Not.Null);
        }
Ejemplo n.º 29
0
        public void Can_Add_PropertyGroup_On_ContentType()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            // Act
            contentType.PropertyGroups.Add(new PropertyGroup(true)
            {
                Name = "Test Group", SortOrder = 3
            });

            // Assert
            Assert.That(contentType.PropertyGroups.Count, Is.EqualTo(3));
        }
Ejemplo n.º 30
0
        public void Can_Remove_PropertyGroup_From_ContentType()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextPageContentType();

            contentType.ResetDirtyProperties();

            // Act
            contentType.PropertyGroups.Remove("Content");

            // Assert
            Assert.That(contentType.PropertyGroups.Count, Is.EqualTo(1));
            //Assert.That(contentType.IsPropertyDirty("PropertyGroups"), Is.True);
        }