Example #1
0
        public void GetDataPins_Entries_Ok()
        {
            MsHandsPart part = GetPart(3);

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

            Assert.Equal(10, 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);

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

                pin = pins.Find(p => p.Name == "person-id" && p.Value == $"person-{n}");
                Assert.NotNull(pin);
                TestHelper.AssertPinIds(part, pin);

                pin = pins.Find(p => p.Name == "type" && p.Value == $"type-{n}");
                Assert.NotNull(pin);
                TestHelper.AssertPinIds(part, pin);
            }
        }
Example #2
0
        public void GetDataPins_NoEntries_Ok()
        {
            MsHandsPart 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);
        }
Example #3
0
        public void Seed_Ok()
        {
            MsHandsPartSeeder seeder = new MsHandsPartSeeder();

            seeder.SetSeedOptions(_seedOptions);

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

            Assert.NotNull(part);

            MsHandsPart p = part as MsHandsPart;

            Assert.NotNull(p);

            TestHelper.AssertPartMetadata(p);

            Assert.NotEmpty(p.Hands);
        }
Example #4
0
        public void Part_Is_Serializable()
        {
            MsHandsPart part = GetPart(2);

            string      json  = TestHelper.SerializePart(part);
            MsHandsPart part2 =
                TestHelper.DeserializePart <MsHandsPart>(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.Hands.Count);
            // TODO: details
        }
Example #5
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));
            }

            MsHandsPart part = new MsHandsPart();

            SetPartMetadata(part, roleId, item);

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

            for (int n = 1; n <= count; n++)
            {
                MsHand hand = new Faker <MsHand>()
                              .RuleFor(h => h.Id, f => f.Person.FirstName)
                              .RuleFor(h => h.Types, f => new List <string>(
                                           new[] { f.PickRandom("got", "mea") }))
                              .RuleFor(h => h.PersonId, f => f.Name.FirstName().ToLowerInvariant())
                              .RuleFor(h => h.Description, f => f.Lorem.Sentence())
                              .RuleFor(h => h.Initials, f => f.Lorem.Sentence())
                              .RuleFor(h => h.Corrections, f => f.Lorem.Sentence())
                              .RuleFor(h => h.Punctuation, f => f.Lorem.Sentence())
                              .RuleFor(h => h.Abbreviations, f => f.Lorem.Sentence())
                              .RuleFor(h => h.IdReason, f => f.Lorem.Word())
                              .RuleFor(h => h.Ranges, f =>
                                       new List <MsLocationRange>(new[] {
                    new MsLocationRange
                    {
                        Start = new MsLocation
                        {
                            N = f.Random.Number(1, 30),
                            S = n % 2 == 0 ?
                                "v" : "r",
                            L = f.Random.Number(1, 20)
                        },
                        End = new MsLocation
                        {
                            N = f.Random.Number(31, 60),
                            S = n % 2 == 0 ?
                                "v" : "r",
                            L = f.Random.Number(1, 20)
                        }
                    }
                }))
                              .RuleFor(h => h.ExtentNote, f => f.Lorem.Sentence())
                              .RuleFor(h => h.Rubrications,
                                       f => GetRubrications(f.Random.Number(1, 2)))
                              .RuleFor(h => h.Subscriptions,
                                       f => GetSubscriptions(f.Random.Number(1, 2)))
                              .RuleFor(h => h.Signs, f => GetSigns(f.Random.Number(1, 2)))
                              .RuleFor(h => h.ImageIds,
                                       f => new List <string>(new[]
                                                              { "img" + f.Random.Number(1, 100) + "-" }))
                              .Generate();

                part.Hands.Add(hand);
            }

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

            for (int n = 1; n <= count; n++)
            {
                part.Hands.Add(new MsHand
                {
                    Id            = $"hand-{n}",
                    Types         = new List <string>(new[] { $"type-{n}" }),
                    PersonId      = $"person-{n}",
                    Description   = "Description",
                    Initials      = "Initials",
                    Corrections   = "Corrections",
                    Punctuation   = "Punctuation",
                    Abbreviations = "Abbreviations",
                    IdReason      = "Reason",
                    Ranges        = new List <MsLocationRange>(new[]
                    {
                        new MsLocationRange
                        {
                            Start = new MsLocation
                            {
                                N = 2,
                                S = n % 2 == 0
                                    ? "v"
                                    : "r",
                                L = 3
                            },
                            End = new MsLocation
                            {
                                N = 4,
                                S = n % 2 == 0
                                    ? "v"
                                    : "r",
                                L = 5
                            }
                        }
                    }),
                    ExtentNote   = "Extent",
                    Rubrications = new List <MsRubrication>(new[]
                    {
                        new MsRubrication
                        {
                            Type   = "type",
                            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
                                    }
                                }
                            }),
                            Description = "Description",
                            Issues      = "Issues"
                        }
                    }),
                    Subscriptions = new List <MsSubscription>(new[]
                    {
                        new MsSubscription
                        {
                            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
                                    }
                                }
                            }),
                            Language = "eng",
                            Text     = "Text"
                        }
                    }),
                    Signs    = GetSigns(1),
                    ImageIds = new List <string>(new string[] { "draco" })
                });
            }

            return(part);
        }