示例#1
0
        public void GetDataPins_Entries_Ok()
        {
            MsContentsPart part = GetPart(3);

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

            Assert.Equal(7, pins.Count);

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

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

            for (int n = 1; n <= 3; n++)
            {
                // work
                pin = pins.Find(p => p.Name == "work" && p.Value == $"work.{n}");
                Assert.NotNull(pin);
                TestHelper.AssertPinIds(part, pin);

                // title
                pin = pins.Find(p => p.Name == "title" && p.Value == $"title {n}");
                Assert.NotNull(pin);
                TestHelper.AssertPinIds(part, pin);
            }
        }
示例#2
0
        private static MsContentsPart GetPart(int count)
        {
            MsContentsPart part = new MsContentsPart
            {
                ItemId    = Guid.NewGuid().ToString(),
                RoleId    = "some-role",
                CreatorId = "zeus",
                UserId    = "another",
            };

            for (int n = 1; n <= count; n++)
            {
                part.Contents.Add(new MsContent
                {
                    Start = new MsLocation
                    {
                        N = n, S = n % 2 == 0 ? "v" : "r", L = n + 10
                    },
                    End = new MsLocation
                    {
                        N = n + 3, S = n % 2 == 0 ? "v" : "r", L = n + 5
                    },
                    Work     = $"work.{n}",
                    Location = "12.34",
                    Title    = $"Title {n}",
                    Incipit  = "incipit",
                    Explicit = "explicit",
                    Note     = "note",
                    Editions = TestHelper.GetDocReferences(2)
                });
            }

            return(part);
        }
示例#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));
            }

            MsContentsPart part = new MsContentsPart();

            SetPartMetadata(part, roleId, item);

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

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

                part.Contents.Add(new Faker <MsContent>()
                                  .RuleFor(c => c.Author, f => f.Lorem.Word())
                                  .RuleFor(c => c.ClaimedAuthor,
                                           f => f.PickRandom(null, f.Lorem.Word()))
                                  .RuleFor(c => c.Work, f => f.Lorem.Word())
                                  .RuleFor(c => c.Title, f => f.Lorem.Sentence())
                                  .RuleFor(c => c.Incipit, f => f.Lorem.Sentence())
                                  .RuleFor(c => c.Explicit, f => f.Lorem.Sentence())
                                  .RuleFor(c => c.Ranges, new List <MsLocationRange>(new[]
                {
                    new MsLocationRange
                    {
                        Start = new MsLocation
                        {
                            N = n,
                            S = n % 2 == 0 ? "v" : "r",
                            L = n * 5
                        },
                        End = new MsLocation
                        {
                            N = n + 1,
                            S = n % 2 == 0 ? "r" : "v",
                            L = n * 5
                        }
                    }
                }))
                                  .RuleFor(c => c.State, f => f.PickRandom("partial", "integral"))
                                  .RuleFor(c => c.Note, f => f.Lorem.Sentence())
                                  .RuleFor(c => c.Units, GetUnits(Randomizer.Seed.Next(1, 3 + 1)))
                                  .Generate());
            }

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

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

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

            Assert.Equal("tot-count", pin.Name);
            TestHelper.AssertPinIds(part, pin);
            Assert.Equal("0", pin.Value);
        }
示例#5
0
        public void Part_Is_Serializable()
        {
            MsContentsPart part = GetPart(3);

            string         json  = TestHelper.SerializePart(part);
            MsContentsPart part2 = TestHelper.DeserializePart <MsContentsPart>(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.NotEmpty(part.Contents);
            // TODO: details
        }
        public void Seed_Ok()
        {
            MsContentsPartSeeder seeder = new MsContentsPartSeeder();

            seeder.SetSeedOptions(_seedOptions);

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

            Assert.NotNull(part);

            MsContentsPart p = part as MsContentsPart;

            Assert.NotNull(p);

            TestHelper.AssertPartMetadata(p);
            Assert.NotEmpty(p.Contents);
        }
示例#7
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</exception>
        public override IPart GetPart(IItem item, string roleId,
                                      PartSeederFactory factory)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            MsContentsPart part = new MsContentsPart();

            SetPartMetadata(part, roleId, item);

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

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

                part.Contents.Add(new Faker <MsContent>()
                                  .RuleFor(c => c.Start, f => new MsLocation
                {
                    N = sn,
                    S = sn % 2 == 0? "v" : "r",
                    L = f.Random.Number(1, 20)
                })
                                  .RuleFor(c => c.End, f => new MsLocation
                {
                    N = (sn + 1),
                    S = (sn + 1) % 2 == 0 ? "v" : "r",
                    L = f.Random.Number(1, 20)
                })
                                  .RuleFor(c => c.Work, f => $"{f.Lorem.Word()}.{f.Lorem.Word()}")
                                  .RuleFor(c => c.Location,
                                           f => f.Lorem.Random.Number(1, 24) + "." +
                                           f.Lorem.Random.Number(1, 100))
                                  .RuleFor(c => c.Title, f => f.Lorem.Sentence(3))
                                  .RuleFor(c => c.Incipit, f => f.Lorem.Sentence(5, 3))
                                  .RuleFor(c => c.Explicit, f => f.Lorem.Sentence(5, 3))
                                  .RuleFor(c => c.Note,
                                           f => f.Random.Bool(0.2f)? f.Lorem.Sentence() : null)
                                  .RuleFor(c => c.Editions, SeedHelper.GetDocReferences(1, 3))
                                  .Generate());
            }

            return(part);
        }
示例#8
0
        public void GetDataPins_Contents_Ok()
        {
            MsContentsPart part = GetPart(3);

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

            Assert.Equal(7, 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 == "author" && p.Value == "authorodd");
            Assert.NotNull(pin);
            TestHelper.AssertPinIds(part, pin);

            pin = pins.Find(p => p.Name == "author" && p.Value == "authoreven");
            Assert.NotNull(pin);
            TestHelper.AssertPinIds(part, pin);

            pin = pins.Find(p => p.Name == "claimed-author" &&
                            p.Value == "claimedodd");
            Assert.NotNull(pin);
            TestHelper.AssertPinIds(part, pin);

            pin = pins.Find(p => p.Name == "claimed-author" &&
                            p.Value == "claimedeven");
            Assert.NotNull(pin);
            TestHelper.AssertPinIds(part, pin);

            pin = pins.Find(p => p.Name == "work" && p.Value == "workodd");
            Assert.NotNull(pin);
            TestHelper.AssertPinIds(part, pin);

            pin = pins.Find(p => p.Name == "work" && p.Value == "workeven");
            Assert.NotNull(pin);
            TestHelper.AssertPinIds(part, pin);
        }