public void GetDataPins_NoEntries_Ok()
        {
            MsDecorationsPart part = GetPart(0);

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

            TestHelper.AssertValidDataPinNames(pins);

            Assert.Single(pins);
            DataPin pin = pins[0];

            Assert.Equal("tot-count", pin.Name);
            TestHelper.AssertPinIds(part, pin);
            Assert.Equal("0", pin.Value);
        }
        public void GetDataPins_Entries_Ok()
        {
            MsDecorationsPart part = GetPart(3);

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

            Assert.Equal(13, pins.Count);
            TestHelper.AssertValidDataPinNames(pins);

            DataPin pin = pins.Find(p => p.Name == "tot-count");

            Assert.NotNull(pin);
            TestHelper.AssertPinIds(part, pin);
            Assert.Equal("3", pin.Value);

            pin = pins.Find(p => p.Name == "type-odd-count");
            Assert.NotNull(pin);
            TestHelper.AssertPinIds(part, pin);
            Assert.Equal("2", pin.Value);

            pin = pins.Find(p => p.Name == "type-even-count");
            Assert.NotNull(pin);
            TestHelper.AssertPinIds(part, pin);
            Assert.Equal("1", pin.Value);

            pin = pins.Find(p => p.Name == "artist-id");
            Assert.NotNull(pin);
            TestHelper.AssertPinIds(part, pin);
            Assert.Equal("artist", pin.Value);

            for (int n = 1; n <= 3; n++)
            {
                pin = pins.Find(p => p.Name == $"subject-s{n}-count");
                Assert.NotNull(pin);
                TestHelper.AssertPinIds(part, pin);
                Assert.Equal("3", pin.Value);

                pin = pins.Find(p => p.Name == $"color-c{n}-count");
                Assert.NotNull(pin);
                TestHelper.AssertPinIds(part, pin);
                Assert.Equal("3", pin.Value);

                pin = pins.Find(p => p.Name == "date-value" &&
                                p.Value == $"{1300 + n}");
                Assert.NotNull(pin);
                TestHelper.AssertPinIds(part, pin);
            }
        }
Beispiel #3
0
        public void Seed_Ok()
        {
            MsDecorationsPartSeeder seeder = new MsDecorationsPartSeeder();

            seeder.SetSeedOptions(_seedOptions);

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

            Assert.NotNull(part);

            MsDecorationsPart dp = part as MsDecorationsPart;

            Assert.NotNull(dp);

            TestHelper.AssertPartMetadata(dp);
            Assert.NotEmpty(dp.Decorations);
        }
        public void Part_Is_Serializable()
        {
            MsDecorationsPart part = GetPart(2);

            string            json  = TestHelper.SerializePart(part);
            MsDecorationsPart part2 =
                TestHelper.DeserializePart <MsDecorationsPart>(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(2, part.Decorations.Count);
            // TODO: details
        }
        /// <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));
            }

            MsDecorationsPart part = new MsDecorationsPart();

            SetPartMetadata(part, roleId, item);

            int count = Randomizer.Seed.Next(1, 3);

            for (int n = 1; n <= count; n++)
            {
                int sn = (n - 1) * 2;

                part.Decorations.Add(new Faker <MsDecoration>()
                                     .RuleFor(d => d.Id, f => "d" + f.UniqueIndex)
                                     .RuleFor(d => d.Name, f => f.Lorem.Word())
                                     .RuleFor(d => d.Type, f => f.PickRandom(_types))
                                     .RuleFor(d => d.Date, HistoricalDate.Parse($"{1300 + n} AD"))
                                     .RuleFor(d => d.Flags,
                                              f => new List <string>(new[] { f.PickRandom(_flags) }))
                                     .RuleFor(d => d.Place, f => f.Address.Country())
                                     .RuleFor(d => d.Artist, GetArtist())
                                     .RuleFor(d => d.Note, f => f.Random.Bool(0.25f)
                        ? f.Lorem.Sentence() : null)
                                     .RuleFor(d => d.References, SeederHelper.GetDocReferences(1, 3))
                                     .RuleFor(d => d.Elements, f => GetElements(f.Random.Number(1, 3), f))
                                     .Generate());
            }

            return(part);
        }
        private static MsDecorationsPart GetPart(int count)
        {
            MsDecorationsPart part = new MsDecorationsPart
            {
                ItemId    = Guid.NewGuid().ToString(),
                RoleId    = "some-role",
                CreatorId = "zeus",
                UserId    = "another",
            };

            for (int n = 1; n <= count; n++)
            {
                string alt = n % 2 == 0 ? "even" : "odd";
                part.Decorations.Add(new MsDecoration
                {
                    Id     = $"d{n}",
                    Name   = "Decoration " + n,
                    Type   = n % 2 == 0? "even" : "odd",
                    Date   = HistoricalDate.Parse($"{1300 + n}"),
                    Flags  = new List <string>(new[] { "f-" + alt }),
                    Place  = "Paris",
                    Note   = "Note",
                    Artist = new MsDecorationArtist
                    {
                        Id      = "artist",
                        Name    = "name",
                        Note    = "note",
                        Type    = "type",
                        Sources = TestHelper.GetDocReferences(2)
                    },
                    References = TestHelper.GetDocReferences(1),
                    Elements   = GetElements(3)
                });
            }

            return(part);
        }