示例#1
0
        public void Generate_Bulk_Import_Sql_Exceeding_Max_Params()
        {
            var servers = new List <ServerRegistrationDto>();

            for (int i = 0; i < 1500; i++)
            {
                servers.Add(new ServerRegistrationDto
                {
                    ServerAddress         = "address" + i,
                    ServerIdentity        = "computer" + i,
                    DateRegistered        = DateTime.Now,
                    IsActive              = true,
                    DateAccessed          = DateTime.Now,
                    IsSchedulingPublisher = true
                });
            }

            IDbCommand[] commands;
            using (IScope scope = ScopeProvider.CreateScope())
            {
                commands = ScopeAccessor.AmbientScope.Database.GenerateBulkInsertCommands(servers.ToArray());
                scope.Complete();
            }

            // Assert
            Assert.That(commands.Length, Is.EqualTo(5));
            foreach (string s in commands.Select(x => x.CommandText))
            {
                Assert.LessOrEqual(Regex.Matches(s, "@\\d+").Count, 2000);
            }
        }
示例#2
0
        public void Generate_Bulk_Import_Sql()
        {
            var servers = new List <ServerRegistrationDto>();

            for (int i = 0; i < 2; i++)
            {
                servers.Add(new ServerRegistrationDto
                {
                    ServerAddress  = "address" + i,
                    ServerIdentity = "computer" + i,
                    DateRegistered = DateTime.Now,
                    IsActive       = true,
                    DateAccessed   = DateTime.Now
                });
            }

            IDbCommand[] commands;
            using (IScope scope = ScopeProvider.CreateScope())
            {
                commands = ScopeAccessor.AmbientScope.Database.GenerateBulkInsertCommands(servers.ToArray());
                scope.Complete();
            }

            // Assert
            Assert.That(
                commands[0].CommandText,
                Is.EqualTo("INSERT INTO [umbracoServer] ([umbracoServer].[address], [umbracoServer].[computerName], [umbracoServer].[registeredDate], [umbracoServer].[lastNotifiedDate], [umbracoServer].[isActive], [umbracoServer].[isSchedulingPublisher]) VALUES (@0,@1,@2,@3,@4,@5), (@6,@7,@8,@9,@10,@11)"));
        }
示例#3
0
        public void DeleteKeysAndIndexesOfTDto()
        {
            IMigrationBuilder builder = Mock.Of <IMigrationBuilder>();

            Mock.Get(builder)
            .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>()))
            .Returns <Type, IMigrationContext>((t, c) =>
            {
                switch (t.Name)
                {
                case "CreateTableOfTDtoMigration":
                    return(new CreateTableOfTDtoMigration(c));

                case "DeleteKeysAndIndexesMigration":
                    return(new DeleteKeysAndIndexesMigration(c));

                default:
                    throw new NotSupportedException();
                }
            });

            using (IScope scope = ScopeProvider.CreateScope())
            {
                var upgrader = new Upgrader(
                    new MigrationPlan("test")
                    .From(string.Empty)
                    .To <CreateTableOfTDtoMigration>("a")
                    .To <DeleteKeysAndIndexesMigration>("done"));

                upgrader.Execute(MigrationPlanExecutor, ScopeProvider, Mock.Of <IKeyValueService>());
                scope.Complete();
            }
        }
示例#4
0
        public void Can_Bulk_Insert_Native_Sql_Bulk_Inserts()
        {
            var servers = new List <ServerRegistrationDto>();

            for (int i = 0; i < 1000; i++)
            {
                servers.Add(new ServerRegistrationDto
                {
                    ServerAddress  = "address" + i,
                    ServerIdentity = "computer" + i,
                    DateRegistered = DateTime.Now,
                    IsActive       = true,
                    DateAccessed   = DateTime.Now
                });
            }

            // Act
            using (ProfilingLogger.TraceDuration <NPocoBulkInsertTests>("starting insert", "finished insert"))
            {
                using (IScope scope = ScopeProvider.CreateScope())
                {
                    ScopeAccessor.AmbientScope.Database.BulkInsertRecords(servers);
                    scope.Complete();
                }
            }

            // Assert
            using (IScope scope = ScopeProvider.CreateScope())
            {
                Assert.That(ScopeAccessor.AmbientScope.Database.ExecuteScalar <int>("SELECT COUNT(*) FROM umbracoServer"), Is.EqualTo(1000));
            }
        }
        public void Can_Remove_Tag_Data_To_Published_Content()
        {
            Template template = TemplateBuilder.CreateTextPageTemplate();

            FileService.SaveTemplate(template);

            // Arrange
            ContentType contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", mandatoryProperties: true, defaultTemplateId: template.Id);

            CreateAndAddTagsPropertyType(contentType);
            ContentTypeService.Save(contentType);
            Content content = ContentBuilder.CreateSimpleContent(contentType, "Tagged content", -1);

            content.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello", "world", "some", "tags" });
            ContentService.SaveAndPublish(content);

            // Act
            content.RemoveTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "some", "world" });
            ContentService.SaveAndPublish(content);

            // Assert
            Assert.AreEqual(2, content.Properties["tags"].GetValue().ToString().Split(',').Distinct().Count());
            int propertyTypeId = contentType.PropertyTypes.Single(x => x.Alias == "tags").Id;

            using (IScope scope = ScopeProvider.CreateScope())
            {
                Assert.AreEqual(2, ScopeAccessor.AmbientScope.Database.ExecuteScalar <int>(
                                    "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId",
                                    new { nodeId = content.Id, propTypeId = propertyTypeId }));

                scope.Complete();
            }
        }
        public void Create_Tag_Data_Bulk_Publish_Operation()
        {
            // Arrange
            // set configuration
            IDataType dataType = DataTypeService.GetDataType(1041);

            dataType.Configuration = new TagConfiguration
            {
                Group       = "test",
                StorageType = TagsStorageType.Csv
            };

            Template template = TemplateBuilder.CreateTextPageTemplate();

            FileService.SaveTemplate(template);

            ContentType contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", mandatoryProperties: true, defaultTemplateId: template.Id);

            CreateAndAddTagsPropertyType(contentType);
            ContentTypeService.Save(contentType);
            contentType.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType.Id), 0, contentType.Alias) };

            Content content = ContentBuilder.CreateSimpleContent(contentType, "Tagged content", -1);

            content.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello", "world", "some", "tags" });
            ContentService.Save(content);

            Content child1 = ContentBuilder.CreateSimpleContent(contentType, "child 1 content", content.Id);

            child1.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello1", "world1", "some1" });
            ContentService.Save(child1);

            Content child2 = ContentBuilder.CreateSimpleContent(contentType, "child 2 content", content.Id);

            child2.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello2", "world2" });
            ContentService.Save(child2);

            // Act
            ContentService.SaveAndPublishBranch(content, true);

            // Assert
            int propertyTypeId = contentType.PropertyTypes.Single(x => x.Alias == "tags").Id;

            using (IScope scope = ScopeProvider.CreateScope())
            {
                Assert.AreEqual(4, ScopeAccessor.AmbientScope.Database.ExecuteScalar <int>(
                                    "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId",
                                    new { nodeId = content.Id, propTypeId = propertyTypeId }));

                Assert.AreEqual(3, ScopeAccessor.AmbientScope.Database.ExecuteScalar <int>(
                                    "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId",
                                    new { nodeId = child1.Id, propTypeId = propertyTypeId }));

                Assert.AreEqual(2, ScopeAccessor.AmbientScope.Database.ExecuteScalar <int>(
                                    "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId",
                                    new { nodeId = child2.Id, propTypeId = propertyTypeId }));

                scope.Complete();
            }
        }
示例#7
0
 protected void SeedDatabase()
 {
     using (IScope scope = ScopeProvider.CreateScope())
     {
         InsertData(ScopeAccessor.AmbientScope.Database);
         scope.Complete();
     }
 }
        public void WriteLockExisting()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                scope.EagerWriteLock(Constants.Locks.Servers);
                scope.Complete();
            }
        }
示例#9
0
        private void Save(MediaService service, IMedia media)
        {
            using (IScope scope = ScopeProvider.CreateScope())
            {
                if (ScopeAccessor.AmbientScope.Database.DatabaseType.IsSqlServer())
                {
                    ScopeAccessor.AmbientScope.Database.Execute("SET LOCK_TIMEOUT 60000");
                }

                service.Save(media);
                scope.Complete();
            }
        }
        public void WriteLockNonExisting()
        {
            IScopeProvider provider = ScopeProvider;

            Assert.Throws <ArgumentException>(() =>
            {
                using (IScope scope = provider.CreateScope())
                {
                    scope.EagerWriteLock(-666);
                    scope.Complete();
                }
            });
        }
    public void Handle(ContentMovedToRecycleBinNotification notification)
    {
        using (IScope scope = _scopeProvider.CreateScope())
        {
            const string  relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias;
            IRelationType?relationType      = _relationService.GetRelationTypeByAlias(relationTypeAlias);

            // check that the relation-type exists, if not, then recreate it
            if (relationType == null)
            {
                Guid         documentObjectType = Constants.ObjectTypes.Document;
                const string relationTypeName   = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteName;

                relationType = new RelationType(relationTypeName, relationTypeAlias, false, documentObjectType, documentObjectType, false);
                _relationService.Save(relationType);
            }

            foreach (MoveEventInfo <IContent> item in notification.MoveInfoCollection)
            {
                IList <string> originalPath     = item.OriginalPath.ToDelimitedList();
                var            originalParentId = originalPath.Count > 2
                    ? int.Parse(originalPath[originalPath.Count - 2], CultureInfo.InvariantCulture)
                    : Constants.System.Root;

                // before we can create this relation, we need to ensure that the original parent still exists which
                // may not be the case if the encompassing transaction also deleted it when this item was moved to the bin
                if (_entityService.Exists(originalParentId))
                {
                    // Add a relation for the item being deleted, so that we can know the original parent for if we need to restore later
                    IRelation relation =
                        _relationService.GetByParentAndChildId(originalParentId, item.Entity.Id, relationType) ??
                        new Relation(originalParentId, item.Entity.Id, relationType);
                    _relationService.Save(relation);

                    _auditService.Add(
                        AuditType.Delete,
                        item.Entity.WriterId,
                        item.Entity.Id,
                        UmbracoObjectTypes.Document.GetName(),
                        string.Format(_textService.Localize("recycleBin", "contentTrashed"), item.Entity.Id, originalParentId));
                }
            }

            scope.Complete();
        }
    }
示例#12
0
    /// <inheritdoc />
    public override IEnumerable <ValueSet> GetValueSets(params IContent[] content)
    {
        Dictionary <int, IProfile> creatorIds;
        Dictionary <int, IProfile> writerIds;

        // We can lookup all of the creator/writer names at once which can save some
        // processing below instead of one by one.
        using (IScope scope = _scopeProvider.CreateScope())
        {
            creatorIds = _userService.GetProfilesById(content.Select(x => x.CreatorId).ToArray())
                         .ToDictionary(x => x.Id, x => x);
            writerIds = _userService.GetProfilesById(content.Select(x => x.WriterId).ToArray())
                        .ToDictionary(x => x.Id, x => x);
            scope.Complete();
        }

        return(GetValueSetsEnumerable(content, creatorIds, writerIds));
    }
示例#13
0
        public void CreateKeysAndIndexes()
        {
            if (BaseTestDatabase.IsSqlite())
            {
                // TODO: Think about this for future migrations.
                Assert.Ignore("Can't add / drop keys in SQLite.");
                return;
            }

            IMigrationBuilder builder = Mock.Of <IMigrationBuilder>();

            Mock.Get(builder)
            .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>()))
            .Returns <Type, IMigrationContext>((t, c) =>
            {
                switch (t.Name)
                {
                case "CreateTableOfTDtoMigration":
                    return(new CreateTableOfTDtoMigration(c));

                case "DeleteKeysAndIndexesMigration":
                    return(new DeleteKeysAndIndexesMigration(c));

                case "CreateKeysAndIndexesMigration":
                    return(new CreateKeysAndIndexesMigration(c));

                default:
                    throw new NotSupportedException();
                }
            });

            using (IScope scope = ScopeProvider.CreateScope())
            {
                var upgrader = new Upgrader(
                    new MigrationPlan("test")
                    .From(string.Empty)
                    .To <CreateTableOfTDtoMigration>("a")
                    .To <DeleteKeysAndIndexesMigration>("b")
                    .To <CreateKeysAndIndexesMigration>("done"));

                upgrader.Execute(MigrationPlanExecutor, ScopeProvider, Mock.Of <IKeyValueService>());
                scope.Complete();
            }
        }
        public void ReadLockNonExisting()
        {
            var lockingMechanism = GetRequiredService <IDistributedLockingMechanismFactory>().DistributedLockingMechanism;

            if (lockingMechanism is SqliteDistributedLockingMechanism)
            {
                Assert.Ignore("SqliteDistributedLockingMechanism doesn't query the umbracoLock table for read locks.");
            }

            IScopeProvider provider = ScopeProvider;

            Assert.Throws <ArgumentException>(() =>
            {
                using (IScope scope = provider.CreateScope())
                {
                    scope.EagerReadLock(-666);
                    scope.Complete();
                }
            });
        }
        private void AssertDeliveredInstructions()
        {
            List <CacheInstructionDto> cacheInstructions;
            ISqlContext       sqlContext = GetRequiredService <ISqlContext>();
            Sql <ISqlContext> sql        = sqlContext.Sql()
                                           .Select <CacheInstructionDto>()
                                           .From <CacheInstructionDto>();

            using (IScope scope = ScopeProvider.CreateScope())
            {
                cacheInstructions = ScopeAccessor.AmbientScope.Database.Fetch <CacheInstructionDto>(sql);
                scope.Complete();
            }

            Assert.Multiple(() =>
            {
                Assert.AreEqual(1, cacheInstructions.Count);

                CacheInstructionDto firstInstruction = cacheInstructions.First();
                Assert.AreEqual(2, firstInstruction.InstructionCount);
                Assert.AreEqual(LocalIdentity, firstInstruction.OriginIdentity);
            });
        }
        public void Does_Not_Create_Tag_Data_For_Non_Published_Version()
        {
            Template template = TemplateBuilder.CreateTextPageTemplate();

            FileService.SaveTemplate(template);

            // create content type with a tag property
            ContentType contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", mandatoryProperties: true, defaultTemplateId: template.Id);

            CreateAndAddTagsPropertyType(contentType);
            ContentTypeService.Save(contentType);

            // create a content with tags and publish
            Content content = ContentBuilder.CreateSimpleContent(contentType, "Tagged content", -1);

            content.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello", "world", "some", "tags" });
            ContentService.SaveAndPublish(content);

            // edit tags and save
            content.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "another", "world" }, merge: true);
            ContentService.Save(content);

            // the (edit) property does contain all tags
            Assert.AreEqual(5, content.Properties["tags"].GetValue().ToString().Split(',').Distinct().Count());

            // but the database still contains the initial two tags
            int propertyTypeId = contentType.PropertyTypes.Single(x => x.Alias == "tags").Id;

            using (IScope scope = ScopeProvider.CreateScope())
            {
                Assert.AreEqual(4, ScopeAccessor.AmbientScope.Database.ExecuteScalar <int>(
                                    "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId",
                                    new { nodeId = content.Id, propTypeId = propertyTypeId }));
                scope.Complete();
            }
        }
示例#17
0
        public void TestMultipleOneToOne()
        {
            using (IScope scope = ScopeProvider.CreateScope())
            {
                var tA1A = new ThingA1Dto {
                    Id = 1, Name = "a1_a"
                };
                ScopeAccessor.AmbientScope.Database.Insert(tA1A);
                var tA1B = new ThingA1Dto {
                    Id = 2, Name = "a1_b"
                };
                ScopeAccessor.AmbientScope.Database.Insert(tA1B);
                var tA1C = new ThingA1Dto {
                    Id = 3, Name = "a1_c"
                };
                ScopeAccessor.AmbientScope.Database.Insert(tA1C);

                var tA2A = new ThingA2Dto {
                    Id = 1, Name = "a2_a"
                };
                ScopeAccessor.AmbientScope.Database.Insert(tA2A);
                var tA2B = new ThingA2Dto {
                    Id = 2, Name = "a2_b"
                };
                ScopeAccessor.AmbientScope.Database.Insert(tA2B);
                var tA2C = new ThingA2Dto {
                    Id = 3, Name = "a2_c"
                };
                ScopeAccessor.AmbientScope.Database.Insert(tA2C);

                var tA3A = new ThingA3Dto {
                    Id = 1, Name = "a3_a"
                };
                ScopeAccessor.AmbientScope.Database.Insert(tA3A);
                var tA3B = new ThingA3Dto {
                    Id = 2, Name = "a3_b"
                };
                ScopeAccessor.AmbientScope.Database.Insert(tA3B);

                var k1 = new ThingA12Dto {
                    Name = "a", Thing1Id = tA1A.Id, Thing2Id = tA2A.Id
                };
                ScopeAccessor.AmbientScope.Database.Insert(k1);
                var k2 = new ThingA12Dto {
                    Name = "b", Thing1Id = tA1A.Id, Thing2Id = tA2B.Id
                };
                ScopeAccessor.AmbientScope.Database.Insert(k2);

                string sql = @"SELECT a1.id, a1.name,
a2.id AS T2A__Id, a2.name AS T2A__Name, a3.id AS T2A__T3__Id, a3.name AS T2A__T3__Name,
a2x.id AS T2B__Id, a2x.name AS T2B__Name, a3x.id AS T2B__T3__Id, a3x.name AS T2B__T3__Name
FROM zbThingA1 a1
JOIN zbThingA12 a12 ON a1.id=a12.thing1id AND a12.name='a'
JOIN zbThingA2 a2 ON a12.thing2id=a2.id
JOIN zbThingA3 a3 ON a2.id=a3.id
JOIN zbThingA12 a12x ON a1.id=a12x.thing1id AND a12x.name='b'
JOIN zbThingA2 a2x ON a12x.thing2id=a2x.id
JOIN zbThingA3 a3x ON a2x.id=a3x.id
";

                List <ThingA1Dto> ts = ScopeAccessor.AmbientScope.Database.Fetch <ThingA1Dto>(sql);
                Assert.AreEqual(1, ts.Count);

                ThingA1Dto t = ts.First();
                Assert.AreEqual("a1_a", t.Name);
                Assert.AreEqual("a2_a", t.T2A.Name);
                Assert.AreEqual("a2_b", t.T2B.Name);

                Assert.AreEqual("a3_a", t.T2A.T3.Name);
                Assert.AreEqual("a3_b", t.T2B.T3.Name);

                scope.Complete();
            }
        }