public void ParseUnknownTest()
        {
            string        text = "}";
            ITextProvider tp   = new StringTextProvider(text);
            {
                ParseItem pi = UnknownItem.ParseUnknown(
                    null, new ItemFactory(tp, null), tp,
                    Helpers.MakeTokenStream(tp),
                    ParseErrorType.OpenCurlyBraceMissingForRule);

                Assert.IsNotNull(pi);
                Assert.IsTrue(pi.HasParseErrors);
                Assert.AreEqual(ParseErrorType.OpenCurlyBraceMissingForRule, pi.ParseErrors[0].ErrorType);
                Assert.AreEqual(ParseErrorLocation.WholeItem, pi.ParseErrors[0].Location);
            }

            // Try a URL
            {
                text = "url('foo.jpg')";
                tp   = new StringTextProvider(text);

                UrlItem pi = UnknownItem.ParseUnknown(
                    null, new ItemFactory(tp, null), tp,
                    Helpers.MakeTokenStream(tp)) as UrlItem;

                Assert.IsNotNull(pi);
            }
        }
Esempio n. 2
0
        public void UnknownItem_Merge_OverridesSimilarAttributes()
        {
            var originalSetting = new UnknownItem("Unknown",
                                                  attributes: new Dictionary <string, string>()
            {
                { "old", "attr" }
            },
                                                  children: null);

            var newSetting = new UnknownItem("Unknown",
                                             attributes: new Dictionary <string, string>()
            {
                { "old", "newAttr" }
            },
                                             children: null);

            originalSetting.Merge(newSetting);

            var expectedSetting = new UnknownItem("Unknown",
                                                  attributes: new Dictionary <string, string>()
            {
                { "old", "newAttr" }
            },
                                                  children: null);

            SettingsTestUtils.DeepEquals(originalSetting, expectedSetting).Should().BeTrue();
        }
Esempio n. 3
0
        public void UnknownItem_Empty_ParsedCorrectly()
        {
            // Arrange
            var nugetConfigPath = "NuGet.Config";
            var config          = @"
<configuration>
    <Section>
        <Unknown />
    </Section>
</configuration>";

            var expectedSetting = new UnknownItem("Unknown", attributes: null, children: null);

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
                var settingsFile = new SettingsFile(mockBaseDirectory);

                // Act
                var section = settingsFile.GetSection("Section");
                section.Should().NotBeNull();

                var element = section.Items.FirstOrDefault();
                element.Should().NotBeNull();

                // Assert
                SettingsTestUtils.DeepEquals(element, expectedSetting).Should().BeTrue();
            }
        }
Esempio n. 4
0
        public void UnknownItem_Update_RemovesMissingAttributes()
        {
            // Arrange
            var nugetConfigPath = "NuGet.Config";
            var config          = @"
<configuration>
    <Section>
        <Unknown old=""attr"" />
    </Section>
</configuration>";

            var updateSetting = new UnknownItem("Unknown",
                                                attributes: new Dictionary <string, string>()
            {
            },
                                                children: null);

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
                var settingsFile = new SettingsFile(mockBaseDirectory);

                // Act
                var section = settingsFile.GetSection("Section");
                section.Should().NotBeNull();

                var element = section.Items.FirstOrDefault() as UnknownItem;
                element.Should().NotBeNull();

                element.Update(updateSetting);

                // Assert
                element.Attributes.TryGetValue("old", out var _).Should().BeFalse();
            }
        }
Esempio n. 5
0
        public void UnknownItem_Add_Item_WorksSuccessfully()
        {
            // Arrange
            var nugetConfigPath = "NuGet.Config";
            var config          = @"
<configuration>
    <Section>
        <Unknown />
    </Section>
</configuration>";

            var expectedSetting = new UnknownItem("Unknown", attributes: null,
                                                  children: new List <SettingBase>()
            {
                new AddItem("key", "val")
            });

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
                var settingsFile = new SettingsFile(mockBaseDirectory);

                // Act
                var section = settingsFile.GetSection("Section");
                section.Should().NotBeNull();

                var element = section.Items.FirstOrDefault() as UnknownItem;
                element.Should().NotBeNull();

                element.Add(new AddItem("key", "val")).Should().BeTrue();

                // Assert
                element.DeepEquals(expectedSetting).Should().BeTrue();
            }
        }
Esempio n. 6
0
        public void UnknownItem_Merge_UpdatesSimilarChildren()
        {
            var originalSetting = new UnknownItem("Unknown",
                                                  attributes: null,
                                                  children: new List <SettingBase>()
            {
                new AddItem("key", "val")
            });

            var newSetting = new UnknownItem("Unknown",
                                             attributes: null,
                                             children: new List <SettingBase>()
            {
                new AddItem("key", "val1")
            });

            originalSetting.Merge(newSetting);

            var expectedSetting = new UnknownItem("Unknown",
                                                  attributes: null,
                                                  children: new List <SettingBase>()
            {
                new AddItem("key", "val1")
            });

            SettingsTestUtils.DeepEquals(originalSetting, expectedSetting).Should().BeTrue();
        }
Esempio n. 7
0
        public void UnknownItem_Merge_AddsNewAttributes()
        {
            var originalSetting = new UnknownItem("Unknown",
                                                  attributes: new Dictionary <string, string>()
            {
                { "old", "attr" }
            },
                                                  children: null);

            var newSetting = new UnknownItem("Unknown",
                                             attributes: new Dictionary <string, string>()
            {
                { "new", "newAttr" }
            },
                                             children: null);

            originalSetting.Merge(newSetting);

            var expectedSetting = new UnknownItem("Unknown",
                                                  attributes: new Dictionary <string, string>()
            {
                { "old", "attr" }, { "new", "newAttr" }
            },
                                                  children: null);

            originalSetting.DeepEquals(expectedSetting).Should().BeTrue();
        }
Esempio n. 8
0
        public void UnknownItem_WithChildren_OnlyText_ParsedCorrectly()
        {
            // Arrange
            var nugetConfigPath = "NuGet.Config";
            var config          = @"
<configuration>
    <Section>
        <Unknown>Text for test</Unknown>
    </Section>
</configuration>";

            var expectedSetting = new UnknownItem("Unknown", attributes: null, children: new List <SettingBase>()
            {
                new SettingText("Text for test")
            });

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
                var settingsFile = new SettingsFile(mockBaseDirectory);

                // Act
                var section = settingsFile.GetSection("Section");
                section.Should().NotBeNull();

                var element = section.Items.FirstOrDefault();
                element.Should().NotBeNull();

                // Assert
                element.DeepEquals(expectedSetting).Should().BeTrue();
            }
        }
Esempio n. 9
0
        public void UnknownItem_Merge_AddshNewChildren()
        {
            var originalSetting = new UnknownItem("Unknown",
                                                  attributes: null,
                                                  children: new List <SettingBase>()
            {
                new AddItem("key", "val")
            });

            var newSetting = new UnknownItem("Unknown",
                                             attributes: null,
                                             children: new List <SettingBase>()
            {
                new SettingText("New test")
            });

            originalSetting.Merge(newSetting);

            var expectedSetting = new UnknownItem("Unknown",
                                                  attributes: null,
                                                  children: new List <SettingBase>()
            {
                new AddItem("key", "val"), new SettingText("New test")
            });

            originalSetting.DeepEquals(expectedSetting).Should().BeTrue();
        }
Esempio n. 10
0
        /// <inheritdoc />
        public Item Convert(ItemDTO value, object state)
        {
            var entity = new UnknownItem();

            this.Merge(entity, value, state);
            return(entity);
        }
Esempio n. 11
0
        internal ParseItem AddUnknownAndAdvance(ItemFactory itemFactory, ITextProvider text, TokenStream tokens, ParseErrorType?errorType = null)
        {
            ParseItem item = UnknownItem.ParseUnknown(_parent, itemFactory, text, tokens, errorType);

            Debug.Assert(item != null);
            Add(item);

            return(item);
        }
        /// <summary>
        /// This only difference from a rule block is that unknown directive blocks allow child @directives.
        /// </summary>
        protected override ParseItem CreateDirective(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            ParseItem parseItem = AtDirective.ParseDirective(this, itemFactory, text, tokens);

            if (parseItem == null)
            {
                return(UnknownItem.ParseUnknown(this, itemFactory, text, tokens, ParseErrorType.UnexpectedParseError));
            }

            return(parseItem);
        }
Esempio n. 13
0
        protected virtual ParseItem CreateDefaultChild(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            ParseItem child = itemFactory.Create <KeyFramesRuleSet>(this);

            if (!child.Parse(itemFactory, text, tokens))
            {
                child = UnknownItem.ParseUnknown(this, itemFactory, text, tokens, ParseErrorType.UnexpectedParseError);
            }

            return(child);
        }
Esempio n. 14
0
        public void UnknownItem_EmptyConstructor()
        {
            var item = new UnknownItem();

            item.Quality.Should().Be(0);
            item.IsQuality.Should().BeFalse();
            item.TypeLine.Should().BeNull();
            item.DescriptiveName.Should().Be("[Unknown Item]");
            item.ItemSource.Should().BeNull();
            item.ErrorInformation.Should().BeNull();
        }
Esempio n. 15
0
        private void Unknown_PopulateInfo(ItemLocation src)
        {
            if ((src is UnknownItem) == false)
            {
                return;
            }
            UnknownItem topop = src as UnknownItem;

            isChanging = false;
            Unknown_InfoChanged();
            isChanging = true;
        }
Esempio n. 16
0
        protected override ParseItem CreateDirective(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            MarginDirective marginDirective = new MarginDirective();

            if (marginDirective.Parse(itemFactory, text, tokens))
            {
                return(marginDirective);
            }
            else
            {
                return(UnknownItem.ParseUnknown(this, itemFactory, text, tokens, ParseErrorType.UnexpectedParseError));
            }
        }
Esempio n. 17
0
        protected override void PostFillVanilla()
        {
            ExtendVanillaArrays(1);

            var ui = UnknownItem.Create();

            Load(new Dictionary <string, ItemDef>
            {
                { "_UnloadedItem", ui }
            });

            UnknownItemID = ui.Type;
        }
        protected override ParseItem CreateDefaultChild(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            // http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems?id=468547 - The contents of unknown directives could be rules or declarations.
            // Make a good guess for which one to create.

            int       startTokenPosition = tokens.Position;
            bool      childIsDeclaration = true;
            ParseItem newChild;

            for (bool done = false; !done && !tokens.CurrentToken.IsBlockTerminator();)
            {
                // If I see a curly brace before a semicolon, then this child is probably a RuleSet

                switch (tokens.CurrentToken.TokenType)
                {
                case CssTokenType.OpenCurlyBrace:
                    childIsDeclaration = false;
                    done = true;
                    break;

                case CssTokenType.Semicolon:
                    done = true;
                    break;

                default:
                    tokens.AdvanceToken();
                    break;
                }
            }

            tokens.Position = startTokenPosition;

            if (childIsDeclaration)
            {
                newChild = base.CreateDefaultChild(itemFactory, text, tokens);
            }
            else
            {
                newChild = itemFactory.Create <RuleSet>(this);

                if (!newChild.Parse(itemFactory, text, tokens))
                {
                    newChild = UnknownItem.ParseUnknown(this, itemFactory, text, tokens, ParseErrorType.UnexpectedToken);
                }
            }

            Debug.Assert(newChild != null);
            return(newChild);
        }
Esempio n. 19
0
        public void UnknownItem_IdentifiedItems_DescriptiveNameProducesCorrectDescription()
        {
            JSONProxy.Item normalProxyItem = Build.A.JsonProxyItem.WithFrameType((int)Rarity.Normal).WithItemLevel(10)
                                             .WithTypeLine("Tricorne").WithQuality(9);
            JSONProxy.Item magicProxyItem = Build.A.JsonProxyItem.WithFrameType((int)Rarity.Magic).WithItemLevel(15)
                                            .WithTypeLine("Noble Tricorne").ThatIsIdentified(false);
            JSONProxy.Item rareProxyItem = Build.A.JsonProxyItem.WithFrameType((int)Rarity.Rare).WithItemLevel(20)
                                           .WithTypeLine("Sinner Tricorne").WithQuality(0).ThatIsIdentified(false).WithName("Fantastic Voyage");
            JSONProxy.Item uniqueProxyItem = Build.A.JsonProxyItem.WithFrameType((int)Rarity.Unique).WithItemLevel(30)
                                             .WithTypeLine("Sinner Tricorne").WithQuality(20).ThatIsIdentified(false)
                                             .WithName("Kender's Confidence");

            var normalItem = new UnknownItem(normalProxyItem);

            normalItem.Quality.Should().Be(9);
            normalItem.IsQuality.Should().BeTrue();
            normalItem.TypeLine.Should().Be("Tricorne");
            normalItem.DescriptiveName.Should().Be("[Unknown Item] Tricorne, +9% Quality, i10");
            normalItem.ItemSource.Should().Be(normalProxyItem);
            normalItem.ErrorInformation.Should().BeNull();

            var magicItem = new UnknownItem(magicProxyItem);

            magicItem.Quality.Should().Be(0);
            magicItem.IsQuality.Should().BeFalse();
            magicItem.TypeLine.Should().Be("Noble Tricorne");
            magicItem.DescriptiveName.Should().Be("[Unknown Item] Noble Tricorne, i15");
            magicItem.ItemSource.Should().Be(magicProxyItem);
            magicItem.ErrorInformation.Should().BeNull();

            var rareItem = new UnknownItem(rareProxyItem);

            rareItem.Quality.Should().Be(0);
            rareItem.IsQuality.Should().BeTrue();
            rareItem.TypeLine.Should().Be("Sinner Tricorne");
            rareItem.DescriptiveName.Should().Be("[Unknown Item] Sinner Tricorne, +0% Quality, i20");
            rareItem.ItemSource.Should().Be(rareProxyItem);
            rareItem.ErrorInformation.Should().BeNull();

            var uniqueItem = new UnknownItem(uniqueProxyItem);

            uniqueItem.Quality.Should().Be(20);
            uniqueItem.IsQuality.Should().BeTrue();
            uniqueItem.TypeLine.Should().Be("Sinner Tricorne");
            uniqueItem.DescriptiveName.Should().Be("[Unknown Item] Sinner Tricorne, +20% Quality, i30");
            uniqueItem.ItemSource.Should().Be(uniqueProxyItem);
            uniqueItem.ErrorInformation.Should().BeNull();
        }
Esempio n. 20
0
        public void UnknownItem_Update_UpdatesExistingChildItems()
        {
            // Arrange
            var nugetConfigPath = "NuGet.Config";
            var config          = @"
<configuration>
    <Section>
        <Unknown old=""attr"">
            <add key=""key"" value=""val"" />
        </Unknown>
    </Section>
</configuration>";

            var updateSetting = new UnknownItem("Unknown",
                                                attributes: new Dictionary <string, string>()
            {
                { "old", "attr" }
            },
                                                children: new List <SettingBase>()
            {
                new AddItem("key", "val", new Dictionary <string, string>()
                {
                    { "meta", "data" }
                })
            });

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
                var settingsFile = new SettingsFile(mockBaseDirectory);

                // Act
                var section = settingsFile.GetSection("Section");
                section.Should().NotBeNull();

                var element = section.Items.FirstOrDefault() as UnknownItem;
                element.Should().NotBeNull();

                element.Update(updateSetting);

                // Assert
                element.Children.Count.Should().Be(1);
                element.Children.First().Should().BeOfType <AddItem>();
                (element.Children.First() as AddItem).AdditionalAttributes["meta"].Should().Be("data");
            }
        }
Esempio n. 21
0
        public void UnknownItem_Equals_WithSameElementName_ReturnsTrue()
        {
            var unkown1 = new UnknownItem("item1", attributes: new Dictionary <string, string>()
            {
                { "meta1", "data1" }
            }, children: new List <SettingBase>()
            {
                new AddItem("key", "val")
            });
            var unkown2 = new UnknownItem("item1", attributes: new Dictionary <string, string>()
            {
                { "meta2", "data2" }, { "meta3", "data4" }
            }, children: new List <SettingBase>()
            {
                new ClearItem()
            });

            unkown1.Equals(unkown2).Should().BeTrue();
        }
Esempio n. 22
0
        public void UnknownItem_Equals_WithDifferentElementName_ReturnsFalse()
        {
            var unkown1 = new UnknownItem("item1", attributes: new Dictionary <string, string>()
            {
                { "meta1", "data1" }
            }, children: new List <SettingBase>()
            {
                new AddItem("key", "val")
            });
            var unkown2 = new UnknownItem("item2", attributes: new Dictionary <string, string>()
            {
                { "meta1", "data1" }
            }, children: new List <SettingBase>()
            {
                new AddItem("key", "val")
            });

            unkown1.Equals(unkown2).Should().BeFalse();
        }
Esempio n. 23
0
        public void UnknownItem_Update_UpdatesExistingChildTexts()
        {
            // Arrange
            var nugetConfigPath = "NuGet.Config";
            var config          = @"
<configuration>
    <Section>
        <Unknown old=""attr"">
            test
        </Unknown>
    </Section>
</configuration>";

            var updateSetting = new UnknownItem("Unknown",
                                                attributes: new Dictionary <string, string>()
            {
                { "old", "attr" }
            },
                                                children: new List <SettingBase>()
            {
                new SettingText("New test")
            });

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
                var settingsFile = new SettingsFile(mockBaseDirectory);

                // Act
                var section = settingsFile.GetSection("Section");
                section.Should().NotBeNull();

                var element = section.Items.FirstOrDefault() as UnknownItem;
                element.Should().NotBeNull();

                element.Update(updateSetting);

                // Assert
                element.Children.Count.Should().Be(1);
                element.Children.First().Should().BeOfType <SettingText>();
                (element.Children.First() as SettingText).Value.Should().Be("New test");
            }
        }
Esempio n. 24
0
        public void UnknownItem_Remove_ExistingChild_Succeeds()
        {
            // Arrange
            var nugetConfigPath = "NuGet.Config";
            var config          = @"
<configuration>
    <Section>
        <Unknown meta=""data"">
            Text for test
            <add key=""key"" value=""val"" />
        </Unknown>
    </Section>
</configuration>";

            var expectedSetting = new UnknownItem("Unknown",
                                                  attributes: new Dictionary <string, string>()
            {
                { "meta", "data" }
            },
                                                  children: new List <SettingBase>()
            {
                new AddItem("key", "val")
            });

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
                var settingsFile = new SettingsFile(mockBaseDirectory);

                // Act
                var section = settingsFile.GetSection("Section");
                section.Should().NotBeNull();

                var element = section.Items.FirstOrDefault() as UnknownItem;
                element.Should().NotBeNull();

                element.Remove(element.Children.First());

                // Assert
                element.DeepEquals(expectedSetting).Should().BeTrue();
            }
        }
        internal virtual bool ParseInFunction(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            if (ItemName.IsAtItemName(tokens))
            {
                ItemName name = itemFactory.CreateSpecific <ItemName>(this);
                if (name.Parse(itemFactory, text, tokens))
                {
                    name.Context = CssClassifierContextCache.FromTypeEnum(CssClassifierContextType.ElementTagName);
                    Name         = name;
                    Children.Add(name);
                }
            }

            if (Name == null || Name.AfterEnd == tokens.CurrentToken.Start)
            {
                while (!IsAtSelectorTerminator(tokens) && tokens.CurrentToken.TokenType != CssTokenType.CloseFunctionBrace)
                {
                    ParseItem childItem = CreateNextAtomicPart(itemFactory, text, tokens);
                    if (childItem == null || !childItem.Parse(itemFactory, text, tokens))
                    {
                        childItem = UnknownItem.ParseUnknown(this, itemFactory, text, tokens, ParseErrorType.PseudoFunctionSelectorExpected);
                    }
                    else
                    {
                        SubSelectors.Add(childItem);
                    }

                    Children.Add(childItem);

                    if (tokens.IsWhiteSpaceBeforeCurrentToken())
                    {
                        break;
                    }
                }
            }

            return(Children.Count > 0);
        }
Esempio n. 26
0
        private static bool UnkownItem_DeepEquals(UnknownItem item1, UnknownItem item2)
        {
            if (!ItemBase_DeepEquals(item1, item2))
            {
                return(false);
            }

            if (item1.Children.Count == item2.Children.Count)
            {
                var childEquals = true;

                var children1 = item1.Children.ToList();
                var children2 = item2.Children.ToList();

                for (var i = 0; i < children1.Count; i++)
                {
                    childEquals &= DeepEquals(children1[i], children2[i]);
                }

                return(childEquals);
            }

            return(false);
        }
Esempio n. 27
0
        /// <inheritdoc />
        public Item Convert(ItemDataContract value, object state)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value", "Precondition: value != null");
            }

            Item item;
            IConverter <ItemDataContract, Item> converter;

            if (this.typeConverters.TryGetValue(value.Type, out converter))
            {
                item = converter.Convert(value, state);
            }
            else
            {
                item = new UnknownItem();
            }

            int itemId;

            if (int.TryParse(value.ItemId, out itemId))
            {
                item.ItemId = itemId;
            }

            item.Name        = value.Name;
            item.Description = value.Description;

            int level;

            if (int.TryParse(value.Level, out level))
            {
                item.Level = level;
            }

            item.Rarity = this.converterForItemRarity.Convert(value.Rarity, state);

            int vendorValue;

            if (int.TryParse(value.VendorValue, out vendorValue))
            {
                item.VendorValue = vendorValue;
            }

            var gameTypes = value.GameTypes;

            if (gameTypes != null)
            {
                item.GameTypes = this.converterForGameTypes.Convert(gameTypes, state);
            }

            var flags = value.Flags;

            if (flags != null)
            {
                item.Flags = this.converterForItemFlags.Convert(flags, state);
            }

            var restrictions = value.Restrictions;

            if (restrictions != null)
            {
                item.Restrictions = this.converterForItemRestrictions.Convert(restrictions, state);
            }

            int iconFileId;

            if (int.TryParse(value.IconFileId, out iconFileId))
            {
                item.IconFileId = iconFileId;
            }

            // Set the icon file signature
            item.IconFileSignature = value.IconFileSignature;

            // Set the icon file URL
            const string IconUrlTemplate = @"https://render.guildwars2.com/file/{0}/{1}.{2}";
            var          iconUrl         = string.Format(IconUrlTemplate, value.IconFileSignature, value.IconFileId, "png");

            item.IconFileUrl = new Uri(iconUrl, UriKind.Absolute);

            return(item);
        }
Esempio n. 28
0
        public void UnknownItem_Remove_ExistingChild_PreservesComments()
        {
            // Arrange
            var nugetConfigPath = "NuGet.Config";
            var config          = @"
<configuration>
    <!-- This is a section -->
    <Section>
        <!-- Unknown Item -->
        <Unknown meta=""data"">
            <!-- Text child -->
            Text for test
            <!-- Item child -->
            <add key=""key"" value=""val"" />
        </Unknown>
    </Section>
</configuration>";

            var expectedSetting = new UnknownItem("Unknown",
                                                  attributes: new Dictionary <string, string>()
            {
                { "meta", "data" }
            },
                                                  children: new List <SettingBase>()
            {
                new AddItem("key", "val")
            });

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
                var settingsFile = new SettingsFile(mockBaseDirectory);

                // Act
                var section = settingsFile.GetSection("Section");
                section.Should().NotBeNull();

                var element = section.Items.FirstOrDefault() as UnknownItem;
                element.Should().NotBeNull();
                element.Remove(element.Children.First());

                settingsFile.AddOrUpdate("Section", element);
                settingsFile.SaveToDisk();

                var expectedConfig = ConfigurationFileTestUtility.RemoveWhitespace(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <!-- This is a section -->
    <Section>
        <!-- Unknown Item -->
        <Unknown meta=""data"">
            <!-- Text child -->
            <!-- Item child -->
            <add key=""key"" value=""val"" />
        </Unknown>
    </Section>
</configuration>");

                ConfigurationFileTestUtility.RemoveWhitespace(File.ReadAllText(Path.Combine(mockBaseDirectory, nugetConfigPath))).Should().Be(expectedConfig);

                // Assert
                element.DeepEquals(expectedSetting).Should().BeTrue();
            }
        }
Esempio n. 29
0
        public void UnknownItem_ElementName_IsCorrect()
        {
            var unkownItem = new UnknownItem("item", attributes: null, children: null);

            unkownItem.ElementName.Should().Be("item");
        }
        public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            bool hasSubject = false;

            // Allow a bang before the tag name.
            while (tokens.CurrentToken.TokenType == CssTokenType.Bang)
            {
                ParseItem item = itemFactory.Create <SubjectSelector>(this);
                if (item.Parse(itemFactory, text, tokens))
                {
                    Children.Add(item);

                    if (hasSubject)
                    {
                        item.AddParseError(ParseErrorType.UnexpectedBangInSelector, ParseErrorLocation.WholeItem);
                    }

                    hasSubject = true;
                }

                if (tokens.IsWhiteSpaceBeforeCurrentToken())
                {
                    break;
                }
            }

            if (ItemName.IsAtItemName(tokens))
            {
                ItemName name = itemFactory.CreateSpecific <ItemName>(this);
                if (name.Parse(itemFactory, text, tokens))
                {
                    name.Context = CssClassifierContextCache.FromTypeEnum(CssClassifierContextType.ElementTagName);
                    Name         = name;
                    Children.Add(name);
                }
            }

            ParseItem lastItem = (Children.Count > 0) ? Children[Children.Count - 1] : null;

            // Only continue parsing the simple selector if the name touches the next token.
            if (lastItem == null || lastItem.AfterEnd == tokens.CurrentToken.Start)
            {
                bool addedErrorItem = false;

                while (!IsAtSelectorTerminator(tokens))
                {
                    ParseItem pi = CreateNextAtomicPart(itemFactory, text, tokens);
                    if (pi == null)
                    {
                        // Only treat the first bad token as an error (don't need more than one in a row)

                        if (addedErrorItem)
                        {
                            pi = UnknownItem.ParseUnknown(this, itemFactory, text, tokens);
                        }
                        else
                        {
                            pi             = UnknownItem.ParseUnknown(this, itemFactory, text, tokens, ParseErrorType.SimpleSelectorExpected);
                            addedErrorItem = true;
                        }
                    }
                    else if (!pi.Parse(itemFactory, text, tokens))
                    {
                        break;
                    }

                    if (pi is SubjectSelector)
                    {
                        if (hasSubject)
                        {
                            pi.AddParseError(ParseErrorType.UnexpectedBangInSelector, ParseErrorLocation.WholeItem);
                        }
                        hasSubject = true;
                    }

                    SubSelectors.Add(pi);
                    Children.Add(pi);

                    if (tokens.IsWhiteSpaceBeforeCurrentToken())
                    {
                        break;
                    }
                }
            }

            if (IsAtSelectorCombineOperator(text, tokens))
            {
                ParseSelectorCombineOperator(itemFactory, text, tokens);

                if (Name == null &&
                    SelectorCombineOperator != null &
                    SubSelectors.Count == 0 &&
                    !CanStartWithCombineOperator(SelectorCombineOperator))
                {
                    SelectorCombineOperator.AddParseError(ParseErrorType.SelectorBeforeCombineOperatorMissing, ParseErrorLocation.BeforeItem);
                }
            }

            return(Children.Count > 0);
        }