Exemple #1
0
        public void GetDataPins_MultipleEntries_Ok()
        {
            QuotationsLayerFragment fr = GetFragment(2);

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

            Assert.Equal(8, pins.Count);

            // fr.author
            Assert.NotNull(pins.Find(
                               p => p.Name == "fr.author" && p.Value == "authora"));
            Assert.NotNull(pins.Find(
                               p => p.Name == "fr.author" && p.Value == "authorb"));

            // fr.work
            Assert.NotNull(pins.Find(
                               p => p.Name == "fr.work" && p.Value == "worka"));
            Assert.NotNull(pins.Find(
                               p => p.Name == "fr.work" && p.Value == "workb"));

            // fr.citation-uri
            Assert.NotNull(pins.Find(
                               p => p.Name == "fr.citation-uri" && p.Value == "urn:1"));
            Assert.NotNull(pins.Find(
                               p => p.Name == "fr.citation-uri" && p.Value == "urn:2"));

            // fr.tag
            Assert.NotNull(pins.Find(
                               p => p.Name == "fr.tag" && p.Value == "tag-a"));
            Assert.NotNull(pins.Find(
                               p => p.Name == "fr.tag" && p.Value == "tag-b"));
        }
Exemple #2
0
        public void GetDataPins_SingleEntry_Ok()
        {
            QuotationsLayerFragment fr = GetFragment(1);

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

            Assert.Equal(4, pins.Count);

            // fr.author
            DataPin pin = pins.Find(p => p.Name == "fr.author");

            Assert.NotNull(pin);
            Assert.Equal("authora", pin.Value);

            // fr.work
            pin = pins.Find(p => p.Name == "fr.work");
            Assert.NotNull(pin);
            Assert.Equal("worka", pin.Value);

            // fr.citation-uri
            pin = pins.Find(p => p.Name == "fr.citation-uri");
            Assert.NotNull(pin);
            Assert.Equal("urn:1", pin.Value);

            // fr.tag
            pin = pins.Find(p => p.Name == "fr.tag");
            Assert.NotNull(pin);
            Assert.Equal("tag-a", pin.Value);
        }
Exemple #3
0
        public void Seed_WithOptions_Ok()
        {
            QuotationsLayerFragmentSeeder seeder = new QuotationsLayerFragmentSeeder();

            seeder.SetSeedOptions(_seedOptions);
            seeder.Configure(new QuotationLayerFragmentSeederOptions
            {
                Authors = new[]
                {
                    "alpha",
                    "beta",
                    "gamma"
                }
            });

            ITextLayerFragment fragment = seeder.GetFragment(_item, "1.1", "alpha");

            Assert.NotNull(fragment);

            QuotationsLayerFragment fr = fragment as QuotationsLayerFragment;

            Assert.NotNull(fr);

            Assert.Equal("1.1", fr.Location);
            Assert.NotEmpty(fr.Entries);
        }
        /// <summary>
        /// Creates and seeds a new fragment.
        /// </summary>
        /// <param name="item">The item this part should belong to.</param>
        /// <param name="location">The location.</param>
        /// <param name="baseText">The base text.</param>
        /// <returns>A new fragment.</returns>
        /// <exception cref="ArgumentNullException">item or location or
        /// baseText</exception>
        public override ITextLayerFragment GetFragment(
            IItem item, string location, string baseText)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }
            if (baseText == null)
            {
                throw new ArgumentNullException(nameof(baseText));
            }

            Faker f = new Faker();
            QuotationsLayerFragment fr = new QuotationsLayerFragment
            {
                Location = location
            };
            int n = Randomizer.Seed.Next(1, 4);

            for (int i = 1; i <= n; i++)
            {
                string author = SeedHelper.RandomPickOneOf(_authors);
                string work   = f.Lorem.Word();

                fr.Entries.Add(new QuotationEntry
                {
                    Author      = author,
                    Work        = work,
                    Citation    = f.Random.Int(1, 100).ToString(CultureInfo.InvariantCulture),
                    CitationUri = $"urn:{author.ToLowerInvariant()}/{work.ToLowerInvariant()}",
                    Variant     = Randomizer.Seed.Next(1, 5) == 1 ?
                                  f.Lorem.Sentence() : null,
                    Tag = Randomizer.Seed.Next(1, 5) == 1 ?
                          f.Lorem.Word() : null,
                    Note = Randomizer.Seed.Next(1, 5) == 1 ?
                           f.Lorem.Sentence() : null
                });
            }

            return(fr);
        }
Exemple #5
0
        public void Fragment_Is_Serializable()
        {
            QuotationsLayerFragment fr = GetFragment(2);

            string json = TestHelper.SerializeFragment(fr);
            QuotationsLayerFragment fr2 =
                TestHelper.DeserializeFragment <QuotationsLayerFragment>(json);

            Assert.Equal(fr.Location, fr2.Location);
            Assert.Equal(fr.Entries.Count, fr2.Entries.Count);
            for (int i = 0; i < fr.Entries.Count; i++)
            {
                QuotationEntry expEntry = fr.Entries[i];
                QuotationEntry actEntry = fr2.Entries[i];
                Assert.Equal(expEntry.Author, actEntry.Author);
                Assert.Equal(expEntry.Work, actEntry.Work);
                Assert.Equal(expEntry.Citation, actEntry.Citation);
                Assert.Equal(expEntry.CitationUri, actEntry.CitationUri);
                Assert.Equal(expEntry.Variant, actEntry.Variant);
                Assert.Equal(expEntry.Tag, actEntry.Tag);
                Assert.Equal(expEntry.Note, actEntry.Note);
            }
        }
Exemple #6
0
        private static QuotationsLayerFragment GetFragment(int count)
        {
            QuotationsLayerFragment fr = new QuotationsLayerFragment
            {
                Location = "1.2"
            };

            for (int i = 0; i < count; i++)
            {
                char c = (char)('a' + i);
                fr.Entries.Add(new QuotationEntry
                {
                    Author      = $"author-{c}",
                    Work        = $"work-{c}",
                    Citation    = $"{i + 1}",
                    CitationUri = $"urn:{i + 1}",
                    Variant     = $"variant-{c}",
                    Tag         = $"tag-{c}",
                    Note        = $"note-{c}"
                });
            }

            return(fr);
        }
Exemple #7
0
        public void GetDataPins_Empty_0()
        {
            QuotationsLayerFragment fr = GetFragment(0);

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