示例#1
0
        public void GetDataPins_Tag_3()
        {
            IndexKeywordsPart part = GetPart();

            List <DataPin> pins = part.GetDataPins().ToList();

            Assert.Equal(3, pins.Count);

            // xkeyword..eng = Greek
            DataPin pin = pins[0];

            Assert.Equal(part.ItemId, pin.ItemId);
            Assert.Equal(part.Id, pin.PartId);
            Assert.Equal(part.RoleId, pin.RoleId);
            Assert.Equal("xkeyword..eng", pin.Name);
            Assert.Equal("Greek", pin.Value);

            // xkeyword.colors.eng = green
            pin = pins[1];
            Assert.Equal(part.ItemId, pin.ItemId);
            Assert.Equal(part.Id, pin.PartId);
            Assert.Equal(part.RoleId, pin.RoleId);
            Assert.Equal("xkeyword.colors.eng", pin.Name);
            Assert.Equal("green", pin.Value);

            // xkeyword.colors.eng = red
            pin = pins[2];
            Assert.Equal(part.ItemId, pin.ItemId);
            Assert.Equal(part.Id, pin.PartId);
            Assert.Equal(part.RoleId, pin.RoleId);
            Assert.Equal("xkeyword.colors.eng", pin.Name);
            Assert.Equal("red", pin.Value);
        }
示例#2
0
        public void Seed_ValidOptions_Ok()
        {
            IndexKeywordsPartSeeder seeder = new IndexKeywordsPartSeeder();

            seeder.SetSeedOptions(_seedOptions);
            seeder.Configure(new IndexKeywordsPartSeederOptions
            {
                IndexIds = new[]
                {
                    "",
                    "person-names"
                },
                Languages = new[]
                {
                    "eng",
                    "ita",
                    "deu"
                }
            });

            IPart part = seeder.GetPart(_item, null, _factory);

            Assert.NotNull(part);

            IndexKeywordsPart cp = part as IndexKeywordsPart;

            Assert.NotNull(cp);

            TestHelper.AssertPartMetadata(cp);
            Assert.NotEmpty(cp.Keywords);
        }
示例#3
0
        /// <summary>
        /// Creates and seeds a new part.
        /// </summary>
        /// <param name="item">The item this part should belong to.</param>
        /// <param name="roleId">The optional part role ID.</param>
        /// <param name="factory">The part seeder factory. This is used
        /// for layer parts, which need to seed a set of fragments.</param>
        /// <returns>A new part.</returns>
        /// <exception cref="ArgumentNullException">item or factory</exception>
        public override IPart GetPart(IItem item, string roleId,
                                      PartSeederFactory factory)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            if (_options?.Languages == null || _options.Languages.Length == 0)
            {
                return(null);
            }

            IndexKeywordsPart part = new IndexKeywordsPart();

            SetPartMetadata(part, roleId, item);

            int  count       = Randomizer.Seed.Next(1, 4);
            bool hasIndexIds = _options.IndexIds?.Length > 0;

            while (count > 0)
            {
                IndexKeyword keyword = new Faker <IndexKeyword>()
                                       .RuleFor(k => k.IndexId, f => hasIndexIds?
                                                f.PickRandom(_options.IndexIds) : null)
                                       .RuleFor(k => k.Language, f => f.PickRandom(_options.Languages))
                                       .RuleFor(k => k.Value, f => f.Lorem.Word())
                                       .Generate();

                part.AddKeyword(keyword);
                count--;
            }

            return(part);
        }
示例#4
0
        public void Part_Is_Serializable()
        {
            IndexKeywordsPart part = GetPart();

            string            json  = TestHelper.SerializePart(part);
            IndexKeywordsPart part2 =
                TestHelper.DeserializePart <IndexKeywordsPart>(json);

            Assert.Equal(part.Id, part2.Id);
            Assert.Equal(part.TypeId, part2.TypeId);
            Assert.Equal(part.ItemId, part2.ItemId);
            Assert.Equal(part.RoleId, part2.RoleId);
            Assert.Equal(part.CreatorId, part2.CreatorId);
            Assert.Equal(part.UserId, part2.UserId);
            Assert.Equal(part.Keywords.Count, part2.Keywords.Count);

            foreach (IndexKeyword expected in part.Keywords)
            {
                Assert.Contains(part2.Keywords,
                                k => k.IndexId == expected.IndexId &&
                                k.Language == expected.Language &&
                                k.Value == expected.Value);
            }
        }
示例#5
0
        private static IndexKeywordsPart GetPart(bool keywords = true)
        {
            IndexKeywordsPart part = new IndexKeywordsPart
            {
                ItemId    = Guid.NewGuid().ToString(),
                RoleId    = "some-role",
                CreatorId = "zeus",
                UserId    = "another"
            };

            if (keywords)
            {
                part.AddKeyword(new IndexKeyword
                {
                    IndexId  = "colors",
                    Language = "eng",
                    Value    = "red",
                    Note     = "red note",
                    Tag      = "tag"
                });
                part.AddKeyword(new IndexKeyword
                {
                    IndexId  = "colors",
                    Language = "eng",
                    Value    = "green",
                    Note     = "green note",
                    Tag      = "tag"
                });
                part.AddKeyword(new IndexKeyword
                {
                    Language = "eng",
                    Value    = "Greek"
                });
            }
            return(part);
        }
示例#6
0
        public void GetDataPins_NoKeywords_Empty()
        {
            IndexKeywordsPart part = GetPart(false);

            Assert.Empty(part.GetDataPins());
        }