public override AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails) { if (!extraDetails.TryGet("framework", out ProjectFramework framework) || framework != ProjectFramework.Uwp) { return(AnalysisActions.None); } var result = AnalysisActions.EmptyList; foreach (var attribute in element.Attributes) { if (attribute.HasStringValue) { var attrValue = attribute.StringValue; if (attrValue.StartsWith("{Binding")) { result.RemoveAttribute(RapidXamlErrorType.Suggestion, "RXTPOC", $"Use 'x:Bind' rather than 'Binding' for '{attribute.Name}'.", "Change to 'x:Bind'", attribute) .AndAddAttribute(attribute.Name, attrValue.Replace("{Binding", "{x:Bind")); } } } return(result); }
public override AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails) { if (element.ContainsDescendant("TwoPaneView")) { var invalidDescendants = element.GetDescendants("TwoPaneView"); var result = AnalysisActions.EmptyList; foreach (var desc in invalidDescendants) { result.HighlightDescendantWithoutAction( RapidXamlErrorType.Error, code: "WinUI-2PV", description: "Do not put a TwoPaneView inside the pane of another TwoPaneview.", descendant: desc, moreInfoUrl: "https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/two-pane-view#dos-and-donts"); } return(result); } else { return(AnalysisActions.None); } }
public void GetDescendants_Many_ManyMatches_NestedChildrenAndAttributes() { var sut = RapidXamlElement.Build("Parent"); sut.AddChildAttribute( "Attr1", RapidXamlElement.Build("AttrChild") .AddChildAttribute("InnerAttrChild", RapidXamlElement.Build("Label"))); sut.AddChildAttribute( "Attr2", RapidXamlElement.Build("AttrChild") .AddChild(RapidXamlElement.Build("Label"))); sut.AddChild(RapidXamlElement.Build("MyChild") .AddChildAttribute( "MyChildAttr", RapidXamlElement.Build("MyChildInnerAttr") .AddChildAttribute( "Nested", RapidXamlElement.Build("Label")))) .AddChild( RapidXamlElement.Build("GrandChild") .AddChild( RapidXamlElement.Build("GreatGrandChild") .AddChild("Label"))); var actual = sut.GetDescendants("Label"); Assert.AreEqual(4, actual.Count()); }
public override AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails) { if (!extraDetails.TryGet("framework", out ProjectFramework framework) || (framework != ProjectFramework.Uwp && framework != ProjectFramework.Wpf)) { return(AnalysisActions.None); } var result = AnalysisActions.EmptyList; if (framework.Equals(ProjectFramework.Uwp)) { // TODO: Issue#163 - check for hard-coded string for Attributes.Content // Then remove CheckBoxProcessor, CheckBoxCheckedAndUncheckedEventsTag & MissingCheckBoxEvents } // If using one event, the recommendation is to use both var hasCheckedEvent = element.HasAttribute(Attributes.CheckedEvent); var hasuncheckedEvent = element.HasAttribute(Attributes.UncheckedEvent); if (hasCheckedEvent && !hasuncheckedEvent) { var existingCheckedName = element.Attributes.FirstOrDefault(a => a.Name == Attributes.CheckedEvent).StringValue; var newEventName = existingCheckedName.ToLowerInvariant().Contains("checked") ? existingCheckedName.Replace("Checked", "UnChecked").Replace("checked", "Unchecked") : "OnCheckBoxUnchecked"; result.AddAttribute( RapidXamlErrorType.Warning, "RXT401", StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsDescription, StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsToolTip, Attributes.UncheckedEvent, newEventName, StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsExtendedMessage, "https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/checkbox#handle-click-and-checked-events"); } if (!hasCheckedEvent && hasuncheckedEvent) { var existingUnheckedName = element.Attributes.FirstOrDefault(a => a.Name == Attributes.UncheckedEvent).StringValue; var newEventName = existingUnheckedName.ToLowerInvariant().Contains("unchecked") ? existingUnheckedName.Replace("UnChecked", "Checked").Replace("unchecked", "checked") : "OnCheckBoxChecked"; result.AddAttribute( RapidXamlErrorType.Warning, "RXT401", StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsDescription, StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsToolTip, Attributes.UncheckedEvent, newEventName, StringRes.UI_XamlAnalysisCheckBoxCheckedAndUncheckedEventsExtendedMessage, "https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/checkbox#handle-click-and-checked-events"); } return(result); }
public AnalysisActions Analyze(RapidXamlElement element) { // Don't do anything. // Knowing this is called is enough as this exists only to know // that the parsed file can be turned into a RapidXamlElement. return(AnalysisActions.None); }
public void ContainsAttribute_One_Found() { var sut = RapidXamlElement.Build("Grid"); sut.AddInlineAttribute("One", "ABC"); Assert.IsTrue(sut.ContainsAttribute("One")); }
public void ContainsDescendant_OneChild_Xmlns_Match() { var sut = RapidXamlElement.Build("Parent"); sut.AddChild("tst:Child"); Assert.IsTrue(sut.ContainsDescendant("Child")); }
public void ContainsDescendant_OneChild_NotMatch() { var sut = RapidXamlElement.Build("Parent"); sut.AddChild("Child"); Assert.IsFalse(sut.ContainsDescendant("one")); }
public void ContainsChild_One_WithoutXmlns_Found() { var sut = RapidXamlElement.Build("Grid"); sut.AddChild("test:One"); Assert.IsTrue(sut.ContainsChild("One")); }
public void ContainsChild_One_NotFound() { var sut = RapidXamlElement.Build("Grid"); sut.AddChild("One"); Assert.IsFalse(sut.ContainsChild("Any")); }
public void GetAttributes_Empty() { var sut = RapidXamlElement.Build("Grid"); var actual = sut.GetAttributes("Height"); Assert.AreEqual(0, actual.Count()); }
public void GetDescendants_None_NoMatches() { var sut = RapidXamlElement.Build("Parent"); var actual = sut.GetDescendants("Label"); Assert.AreEqual(0, actual.Count()); }
public void ContainsAttribute_One_Part2OfDotted_NotFound() { var sut = RapidXamlElement.Build("Grid"); sut.AddInlineAttribute("Grid.Row", "1"); Assert.IsFalse(sut.ContainsAttribute("Row")); }
public AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails) { var result = AutoFixAnalysisActions.RenameElement("newcontrols:WebView2"); result.AndAddXmlns("newcontrols", "https://somenewdomain/newcontrols"); return(result); }
public AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails) { var result = AutoFixAnalysisActions.RenameElement("WebView2"); result.AndAddAttribute("Source", "https://rapidxaml.dev/"); return(result); }
public void GetChildren_None_NoMatches() { var sut = RapidXamlElement.Build("Grid"); var actual = sut.GetChildren("Label"); Assert.AreEqual(0, actual.Count()); }
public void ContainsAttribute_One_Dotted_Found() { var sut = RapidXamlElement.Build("Grid"); sut.AddInlineAttribute("Grid.Row", "1"); Assert.IsTrue(sut.ContainsAttribute("Grid.Row")); }
public void ContainsAttribute_Two_Found_CaseInsensitive() { var sut = RapidXamlElement.Build("Grid"); sut.AddInlineAttribute("One", "ABC"); sut.AddInlineAttribute("Two", "DEF"); Assert.IsTrue(sut.ContainsAttribute("one")); }
public void ContainsAttribute_Two_NotFound() { var sut = RapidXamlElement.Build("Grid"); sut.AddInlineAttribute("One", "ABC"); sut.AddInlineAttribute("Two", "DEF"); Assert.IsFalse(sut.ContainsAttribute("Any")); }
public void ContainsChild_Two_WithXmlns_Found_CaseInsensitive() { var sut = RapidXamlElement.Build("Grid"); sut.AddChild("test:One"); sut.AddChild("test:Two"); Assert.IsTrue(sut.ContainsChild("one")); }
public void ContainsChild_Two_Found() { var sut = RapidXamlElement.Build("Grid"); sut.AddChild("One"); sut.AddChild("Two"); Assert.IsTrue(sut.ContainsChild("One")); }
public static RapidXamlElement AddChildAttribute(this RapidXamlElement element, string name, string value, int startPos = -1, int length = -1) { element.Attributes.Add(new RapidXamlAttribute() { Name = name, StringValue = value, IsInline = false, Location = new RapidXamlSpan(startPos, length) }); return(element); }
public static RapidXamlElement AddChild(this RapidXamlElement element, string name) { element.Children.Add(new RapidXamlElement() { Name = name }); return(element); }
public static RapidXamlElement AddChild(this RapidXamlElement element, RapidXamlElement child) { if (child != null) { element.Children.Add(child); } return(element); }
public AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails) { return(AnalysisActions.ReplaceElement( RapidXamlErrorType.Suggestion, "Test4", "Don't use `NewName` yet.", "Comment out NewName element", $"<!--{element.OriginalString}-->")); }
public static AnalysisActions RemoveChild(RapidXamlElement child) { return(RemoveChild( RapidXamlErrorType.Error, string.Empty, string.Empty, string.Empty, child)); }
public void GetAttributes_One_Match() { var sut = RapidXamlElement.Build("Grid"); sut.AddInlineAttribute("Width", "Auto"); var actual = sut.GetAttributes("Width"); Assert.AreEqual(1, actual.Count()); }
public void FooElement_WithXmlns() { var xaml = @"<demo:Foo />"; var expected = RapidXamlElement.Build("demo:Foo"); var actual = RapidXamlElementExtractor.GetElement(xaml); RapidXamlElementAssert.AreEqual(expected, actual); }
public AnalysisActions Analyze(RapidXamlElement element, ExtraAnalysisDetails extraDetails) { if (element.ContainsChild("TextBlock")) { return(AutoFixAnalysisActions.RemoveChild(element.Children.First(c => c.Name == "TextBlock"))); } else { return(AutoFixAnalysisActions.None); } }
public void ContainsDescendant_OneChild_OneGrandChild_NotMatch() { var sut = RapidXamlElement.Build("Parent"); var child = RapidXamlElement.Build("Child"); child.AddChild("Grandchild"); sut.AddChild(child); Assert.IsFalse(sut.ContainsDescendant("Uncle")); }