Beispiel #1
0
        public void Seed_WithTags_Ok()
        {
            OrthographyLayerFragmentSeeder seeder = new OrthographyLayerFragmentSeeder();

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

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

            Assert.NotNull(fragment);

            OrthographyLayerFragment fr = fragment as OrthographyLayerFragment;

            Assert.NotNull(fr);

            Assert.Equal("1.1", fr.Location);
            Assert.NotNull(fr.Standard);
            Assert.Single(fr.Operations);
            MspOperation op = MspOperation.Parse(fr.Operations[0]);

            Assert.NotNull(op.Tag);
        }
        /// <summary>
        /// Creates and seeds a new part.
        /// </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));
            }

            // find 1st letter
            int i = 0;

            while (i < baseText.Length)
            {
                if (char.IsLetter(baseText[i]))
                {
                    break;
                }
                i++;
            }
            if (i == baseText.Length)
            {
                return(null);
            }

            // change it
            string standard = ChangeLetterAt(baseText, i);

            // create operation
            MspOperation op = new MspOperation
            {
                Operator = MspOperator.Replace,
                RangeA   = new TextRange(i, 1),
                ValueA   = new string(baseText[i], 1),
                ValueB   = new string(standard[i], 1),
                Tag      = _options?.Tags?.Length > 0
                    ? SeedHelper.RandomPickOneOf(_options.Tags) : null
            };

            OrthographyLayerFragment fragment = new OrthographyLayerFragment
            {
                Location = location,
                Standard = standard
            };

            fragment.Operations.Add(op.ToString());

            return(fragment);
        }
        public void Fragment_Is_Serializable()
        {
            OrthographyLayerFragment fr = GetFragment("\"b\"@1x1=\"v\"");

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

            Assert.Equal(fr.Location, fr2.Location);
            Assert.Equal(fr.Standard, fr2.Standard);
            Assert.Equal(fr.Operations.Count, fr2.Operations.Count);
            Assert.Equal(fr.Operations[0], fr2.Operations[0]);
        }
        public void GetDataPins_WithItem_2()
        {
            Item item = new Item
            {
                CreatorId   = "zeus",
                UserId      = "zeus",
                Title       = "Mock",
                Description = "A mock item",
                FacetId     = "default",
                SortKey     = "mock"
            };
            TokenTextPart textPart = new TokenTextPart
            {
                ItemId    = item.Id,
                CreatorId = item.CreatorId,
                UserId    = item.UserId,
            };

            textPart.Lines.Add(new TextLine
            {
                Text = "quae bixit annis X",
                Y    = 1
            });
            item.Parts.Add(textPart);

            TokenTextLayerPart <OrthographyLayerFragment> layerPart =
                new TokenTextLayerPart <OrthographyLayerFragment>();
            OrthographyLayerFragment fr;

            layerPart.AddFragment(fr = new OrthographyLayerFragment
            {
                Location = "1.2",
                Standard = "vixit",
            });
            item.Parts.Add(layerPart);

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

            Assert.Equal(2, pins.Count);

            DataPin pin = pins.Find(p => p.Name == "fr.orthography-txt");

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

            pin = pins.Find(p => p.Name == "fr.orthography-std");
            Assert.NotNull(pin);
            Assert.Equal("vixit", pin.Value);
        }
        private static OrthographyLayerFragment GetFragment(
            params string[] operations)
        {
            OrthographyLayerFragment fr = new OrthographyLayerFragment
            {
                Location = "1.23",
                Standard = "vixit",
            };

            foreach (string operation in operations)
            {
                fr.Operations.Add(operation);
            }
            return(fr);
        }
        public void GetDataPins_TaggedOperations_2()
        {
            OrthographyLayerFragment fr = GetFragment(
                "\"b\"@1x1=\"v\" [c]",
                "\"e\"@1x1=\"ae\" [v]",
                "\"b\"@1x1=\"p\" [c]");

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

            Assert.Equal(2, pins.Count);
            DataPin pin = pins[0];

            Assert.Equal("fr.msp.c", pin.Name);
            Assert.Equal("2", pin.Value);

            pin = pins[1];
            Assert.Equal("fr.msp.v", pin.Name);
            Assert.Equal("1", pin.Value);
        }
Beispiel #7
0
        public void Seed_WithoutTags_Ok()
        {
            OrthographyLayerFragmentSeeder seeder = new OrthographyLayerFragmentSeeder();

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

            Assert.NotNull(fragment);

            OrthographyLayerFragment fr = fragment as OrthographyLayerFragment;

            Assert.NotNull(fr);

            Assert.Equal("1.1", fr.Location);
            Assert.NotNull(fr.Standard);
            Assert.Single(fr.Operations);
            MspOperation op = MspOperation.Parse(fr.Operations[0]);

            Assert.Null(op.Tag);
        }
        public void GetDataPins_NoOperations_0()
        {
            OrthographyLayerFragment fr = GetFragment();

            Assert.Empty(fr.GetDataPins());
        }
        public void GetDataPins_NoTaggedOperations_0()
        {
            OrthographyLayerFragment fr = GetFragment("\"b\"@1x1=\"v\"");

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