Ejemplo n.º 1
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 Getting_100_Cached_Items()
        {
            // Arrange
            var contentType = ServiceContext.ContentTypeService.Get(NodeDto.NodeIdSeed);
            var pages       = MockedContent.CreateTextpageContent(contentType, -1, 100);

            ServiceContext.ContentService.Save(pages, 0);

            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var tRepository        = new TemplateRepository((IScopeAccessor)provider, AppCaches.Disabled, Logger, TestObjects.GetFileSystemsMock());
                var tagRepo            = new TagRepository((IScopeAccessor)provider, AppCaches.Disabled, Logger);
                var ctRepository       = new ContentTypeRepository((IScopeAccessor)provider, AppCaches.Disabled, Logger, tRepository);
                var languageRepository = new LanguageRepository((IScopeAccessor)provider, AppCaches.Disabled, Logger);
                var repository         = new DocumentRepository((IScopeAccessor)provider, AppCaches.Disabled, Logger, ctRepository, tRepository, tagRepo, languageRepository);

                // Act
                var contents = repository.GetMany();

                Stopwatch watch          = Stopwatch.StartNew();
                var       contentsCached = repository.GetMany();
                watch.Stop();
                var elapsed = watch.ElapsedMilliseconds;

                Debug.Print("100 content items retrieved in {0} ms with caching", elapsed);

                // Assert
                Assert.That(contentsCached.Any(x => x.HasIdentity == false), Is.False);
                Assert.That(contentsCached.Any(x => x == null), Is.False);
                Assert.That(contentsCached.Count(), Is.EqualTo(contents.Count()));
            }
        }
Ejemplo n.º 3
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.º 4
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.º 5
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.º 6
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
        }
        public void Getting_1000_Cached_Items()
        {
            // Arrange
            var contentType = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed);
            var pages       = MockedContent.CreateTextpageContent(contentType, -1, 1000);

            ServiceContext.ContentService.Save(pages, 0);

            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();

            using (var tRepository = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax, Mock.Of <IFileSystem>(), Mock.Of <IFileSystem>(), Mock.Of <ITemplatesSection>()))
                using (var tagRepo = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax))
                    using (var ctRepository = new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax, tRepository))
                        using (var repository = new ContentRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax, ctRepository, tRepository, tagRepo, Mock.Of <IContentSection>()))
                        {
                            // Act
                            var contents = repository.GetAll();

                            Stopwatch watch          = Stopwatch.StartNew();
                            var       contentsCached = repository.GetAll();
                            watch.Stop();
                            var elapsed = watch.ElapsedMilliseconds;

                            Debug.Print("1000 content items retrieved in {0} ms with caching", elapsed);

                            // Assert
                            //Assert.That(contentsCached.Any(x => x.HasIdentity == false), Is.False);
                            //Assert.That(contentsCached.Any(x => x == null), Is.False);
                            //Assert.That(contentsCached.Count(), Is.EqualTo(contents.Count()));
                        }
        }
        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.º 9
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.º 10
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.º 11
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.º 13
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());
        }
        public void Getting_1000_Uncached_Items()
        {
            // Arrange
            var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
            var pages       = MockedContent.CreateTextpageContent(contentType, -1, 1000);

            ServiceContext.ContentService.Save(pages, 0);

            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            var repository = RepositoryResolver.Current.ResolveByType <IContentRepository>(unitOfWork);

            // Act
            Stopwatch watch    = Stopwatch.StartNew();
            var       contents = repository.GetAll();

            watch.Stop();
            var elapsed = watch.ElapsedMilliseconds;

            Console.WriteLine("1000 content items retrieved in {0} ms without caching", elapsed);

            // Assert
            //Assert.That(contents.Any(x => x.HasIdentity == false), Is.False);
            //Assert.That(contents.Any(x => x == null), Is.False);
        }
        public void Can_Verify_Removal_Of_Used_PropertyType_From_ContentType()
        {
            // Arrange
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                ContentTypeRepository repository;
                var contentRepository = CreateRepository((IScopeAccessor)provider, out repository);
                var contentType       = repository.Get(NodeDto.NodeIdSeed + 1);

                var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
                contentRepository.Save(subpage);


                // Act
                contentType.RemovePropertyType("keywords");
                repository.Save(contentType);


                // Assert
                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(3));
                Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "keywords"), Is.False);
                Assert.That(subpage.Properties.First(x => x.Alias == "description").GetValue(), Is.EqualTo("This is the meta description for a textpage"));
            }
        }
        public void Can_Verify_Addition_Of_PropertyType_After_ContentType_Is_Used()
        {
            // Arrange
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                ContentTypeRepository repository;
                var contentRepository = CreateRepository((IScopeAccessor)provider, out repository);
                var contentType       = repository.Get(NodeDto.NodeIdSeed + 1);

                var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
                contentRepository.Save(subpage);


                // Act
                var propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta");
                propertyGroup.PropertyTypes.Add(new PropertyType("test", ValueStorageType.Ntext, "metaAuthor")
                {
                    Name = "Meta Author", Description = "", Mandatory = false, SortOrder = 1, DataTypeId = -88
                });
                repository.Save(contentType);


                // Assert
                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(5));
                Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "metaAuthor"), Is.True);
            }
        }
        public void Can_Verify_Addition_Of_PropertyType_After_ContentType_Is_Used()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();
            ContentTypeRepository repository;

            using (var contentRepository = CreateRepository(unitOfWork, out repository))
            {
                var contentType = repository.Get(NodeDto.NodeIdSeed + 1);

                var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
                contentRepository.AddOrUpdate(subpage);
                unitOfWork.Commit();

                // Act
                var propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta");
                propertyGroup.PropertyTypes.Add(new PropertyType("test", DataTypeDatabaseType.Ntext, "metaAuthor")
                {
                    Name = "Meta Author", Description = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88
                });
                repository.AddOrUpdate(contentType);
                unitOfWork.Commit();

                // Assert
                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(5));
                Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "metaAuthor"), Is.True);
            }
        }
        public void Can_Verify_Content_Type_Has_Content_Nodes()
        {
            // Arrange
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                ContentTypeRepository repository;
                var contentRepository = CreateRepository((IScopeAccessor)provider, out repository);
                var contentTypeId     = NodeDto.NodeIdSeed + 1;
                var contentType       = repository.Get(contentTypeId);

                // Act
                var result = repository.HasContentNodes(contentTypeId);

                var subpage = MockedContent.CreateTextpageContent(contentType, "Test Page 1", contentType.Id);
                contentRepository.Save(subpage);

                var result2 = repository.HasContentNodes(contentTypeId);

                // Assert
                Assert.That(result, Is.False);
                Assert.That(result2, Is.True);
            }
        }
Ejemplo n.º 19
0
        public void Rebuild_Content_Xml_On_Property_Removal()
        {
            var contentType1 = MockedContentTypes.CreateTextpageContentType("test1", "Test1");

            ServiceContext.ContentTypeService.Save(contentType1);
            var contentItems1 = MockedContent.CreateTextpageContent(contentType1, -1, 10).ToArray();

            contentItems1.ForEach(x => ServiceContext.ContentService.SaveAndPublish(x));
            var alias          = contentType1.PropertyTypes.First().Alias;
            var elementToMatch = "<" + alias + ">";

            foreach (var c in contentItems1)
            {
                var xml = DatabaseContext.Database.FirstOrDefault <ContentXmlDto>("WHERE nodeId = @Id", new { Id = c.Id });
                Assert.IsNotNull(xml);
                Assert.IsTrue(xml.Xml.Contains(elementToMatch)); //verify that it is there before we remove the property
            }

            //remove a property
            contentType1.RemovePropertyType(contentType1.PropertyTypes.First().Alias);
            ServiceContext.ContentTypeService.Save(contentType1);

            var reQueried = ServiceContext.ContentTypeService.GetContentType(contentType1.Id);
            var reContent = ServiceContext.ContentService.GetById(contentItems1.First().Id);

            foreach (var c in contentItems1)
            {
                var xml = DatabaseContext.Database.FirstOrDefault <ContentXmlDto>("WHERE nodeId = @Id", new { Id = c.Id });
                Assert.IsNotNull(xml);
                Assert.IsFalse(xml.Xml.Contains(elementToMatch)); //verify that it is no longer there
            }
        }
        public void Can_Verify_Removal_Of_Used_PropertyType_From_ContentType()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();
            ContentTypeRepository repository;

            using (var contentRepository = CreateRepository(unitOfWork, out repository))
            {
                var contentType = repository.Get(NodeDto.NodeIdSeed + 1);

                var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
                contentRepository.AddOrUpdate(subpage);
                unitOfWork.Commit();

                // Act
                contentType.RemovePropertyType("keywords");
                repository.AddOrUpdate(contentType);
                unitOfWork.Commit();

                // Assert
                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(3));
                Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "keywords"), Is.False);
                Assert.That(subpage.Properties.First(x => x.Alias == "description").Value, Is.EqualTo("This is the meta description for a textpage"));
            }
        }
        public void Getting_1000_Cached_Items()
        {
            // Arrange
            var contentType = ServiceContext.ContentTypeService.Get(NodeDto.NodeIdSeed);
            var pages       = MockedContent.CreateTextpageContent(contentType, -1, 1000);

            ServiceContext.ContentService.Save(pages, 0);

            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var repository = CreateDocumentRepository(provider);

                // Act
                var contents = repository.GetMany();

                Stopwatch watch          = Stopwatch.StartNew();
                var       contentsCached = repository.GetMany();
                watch.Stop();
                var elapsed = watch.ElapsedMilliseconds;

                Debug.Print("1000 content items retrieved in {0} ms with caching", elapsed);

                // Assert
                //Assert.That(contentsCached.Any(x => x.HasIdentity == false), Is.False);
                //Assert.That(contentsCached.Any(x => x == null), Is.False);
                //Assert.That(contentsCached.Count(), Is.EqualTo(contents.Count()));
            }
        }
Ejemplo n.º 22
0
        public void Rebuild_Content_Xml_On_Alias_Change()
        {
            var contentType1 = MockedContentTypes.CreateTextpageContentType("test1", "Test1");
            var contentType2 = MockedContentTypes.CreateTextpageContentType("test2", "Test2");

            ServiceContext.ContentTypeService.Save(contentType1);
            ServiceContext.ContentTypeService.Save(contentType2);
            var contentItems1 = MockedContent.CreateTextpageContent(contentType1, -1, 10).ToArray();

            contentItems1.ForEach(x => ServiceContext.ContentService.SaveAndPublish(x));
            var contentItems2 = MockedContent.CreateTextpageContent(contentType2, -1, 5).ToArray();

            contentItems2.ForEach(x => ServiceContext.ContentService.SaveAndPublish(x));
            //only update the contentType1 alias which will force an xml rebuild for all content of that type
            contentType1.Alias = "newAlias";
            ServiceContext.ContentTypeService.Save(contentType1);

            foreach (var c in contentItems1)
            {
                var xml = DatabaseContext.Database.FirstOrDefault <ContentXmlDto>("WHERE nodeId = @Id", new { Id = c.Id });
                Assert.IsNotNull(xml);
                Assert.IsTrue(xml.Xml.StartsWith("<newAlias"));
            }
            foreach (var c in contentItems2)
            {
                var xml = DatabaseContext.Database.FirstOrDefault <ContentXmlDto>("WHERE nodeId = @Id", new { Id = c.Id });
                Assert.IsNotNull(xml);
                Assert.IsTrue(xml.Xml.StartsWith("<test2")); //should remain the same
            }
        }
Ejemplo n.º 23
0
        public void Can_Add_New_Property_To_New_PropertyType_In_New_PropertyGroup()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateTextpageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

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

            propertyGroup.PropertyTypes.Add(propertyType);
            contentType.PropertyGroups.Add(propertyGroup);
            content.Properties.Add(new Property(propertyType)
            {
                Value = "Subtitle Test"
            });

            // Assert
            Assert.That(content.Properties.Count, Is.EqualTo(5));
            Assert.That(content.PropertyTypes.Count(), Is.EqualTo(5));
            Assert.That(content.PropertyGroups.Count(), Is.EqualTo(3));
            Assert.That(content.Properties["subtitle"].Value, Is.EqualTo("Subtitle Test"));
            Assert.That(content.Properties["title"].Value, Is.EqualTo("Textpage textpage"));
        }
Ejemplo n.º 24
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.º 25
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.º 26
0
        public void Can_Verify_Addition_Of_PropertyType_After_ContentType_Is_Used()
        {
            // Arrange
            var provider          = new PetaPocoUnitOfWorkProvider();
            var unitOfWork        = provider.GetUnitOfWork();
            var repository        = RepositoryResolver.Current.ResolveByType <IContentTypeRepository>(unitOfWork);
            var contentRepository = RepositoryResolver.Current.ResolveByType <IContentRepository>(unitOfWork);
            var contentType       = repository.Get(1046);

            var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);

            contentRepository.AddOrUpdate(subpage);
            unitOfWork.Commit();

            // Act
            var propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta");

            propertyGroup.PropertyTypes.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext)
            {
                Alias = "metaAuthor", Name = "Meta Author", Description = "", HelpText = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88
            });
            repository.AddOrUpdate(contentType);
            unitOfWork.Commit();

            // Assert
            Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(5));
            Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "metaAuthor"), Is.True);
        }
Ejemplo n.º 27
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.º 28
0
        public void Should_Not_Create_New_Version_When_Published_Status_Not_Changed()
        {
            var contentType = MockedContentTypes.CreateTextpageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            content.ResetDirtyProperties(false);

            Assert.IsFalse(content.ShouldCreateNewVersion(PublishedState.Unpublished));
        }
Ejemplo n.º 29
0
        public void Can_Deep_Clone_Perf_Test()
        {
            // 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.ExpireDate  = DateTime.Now;
            content.Key         = Guid.NewGuid();
            content.Language    = "en";
            content.Level       = 3;
            content.Path        = "-1,4,10";
            content.ReleaseDate = DateTime.Now;
            content.ChangePublishedState(PublishedState.Published);
            content.SortOrder = 5;
            content.Template  = new Template("-1,2,3,4", "Test Template", "testTemplate")
            {
                Id = 88
            };
            content.Trashed    = false;
            content.UpdateDate = DateTime.Now;
            content.Version    = Guid.NewGuid();
            content.WriterId   = 23;

            ((IUmbracoEntity)content).AdditionalData.Add("test1", 123);
            ((IUmbracoEntity)content).AdditionalData.Add("test2", "hello");

            var runtimeCache = new ObjectCacheRuntimeCacheProvider();

            runtimeCache.InsertCacheItem(content.Id.ToString(CultureInfo.InvariantCulture), () => content);

            using (DisposableTimer.DebugDuration <ContentTests>("STARTING PERF TEST WITH RUNTIME CACHE"))
            {
                for (int j = 0; j < 1000; j++)
                {
                    var clone = runtimeCache.GetCacheItem(content.Id.ToString(CultureInfo.InvariantCulture));
                }
            }

            using (DisposableTimer.DebugDuration <ContentTests>("STARTING PERF TEST WITHOUT RUNTIME CACHE"))
            {
                for (int j = 0; j < 1000; j++)
                {
                    var clone = (ContentType)contentType.DeepClone();
                }
            }
        }
Ejemplo n.º 30
0
        public void Should_Create_New_Version_When_Any_Property_Value_Changed_And_Its_Already_Published()
        {
            var contentType = MockedContentTypes.CreateTextpageContentType();
            var content     = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);

            content.ResetDirtyProperties(false);

            content.Properties.First().Value = "hello world";
            Assert.IsTrue(content.ShouldCreateNewVersion(PublishedState.Published));
        }