Skip to content

Commit

Permalink
fixed the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ugras-ergun-sonarsource committed Nov 3, 2023
1 parent 562e1e7 commit ca23d83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
22 changes: 7 additions & 15 deletions src/Education.UnitTests/XamlGenerator/RuleXamlBuilderSmokeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,44 +52,36 @@ public void Create_CheckAllEmbedded()
Console.WriteLine("Checking xaml creation. Count = " + resourceNames.Count());

string[] failures;
using(new AssertIgnoreScope()) // the product code can assert if it encounters an unrecognised tag
using (new AssertIgnoreScope()) // the product code can assert if it encounters an unrecognised tag
{
failures = resourceNames.Where(x => !ProcessResource(x))
.ToArray();
}

failures.Should().BeEquivalentTo(new[]
{
// introduced in sonar-cpp 6.48
"SonarLint.VisualStudio.Rules.Embedded.cpp.S1232.json",
// introduced in dotnet analyzer 9.5
"SonarLint.VisualStudio.Rules.Embedded.csharpsquid.S4433.json",
// possible issues with EnsureHtmlIsXml regexp in rich rule description, need to investigate (same issue for all 5332 rules)
"SonarLint.VisualStudio.Rules.Embedded.cpp.S5332.json",
"SonarLint.VisualStudio.Rules.Embedded.c.S5332.json",
"SonarLint.VisualStudio.Rules.Embedded.csharpsquid.S5332.json",
"SonarLint.VisualStudio.Rules.Embedded.javascript.S5332.json",
"SonarLint.VisualStudio.Rules.Embedded.typescript.S5332.json",
// some issue with diff highlighting
"SonarLint.VisualStudio.Rules.Embedded.csharpsquid.S6640.json",
});
}

private static bool ProcessResource(string fullResourceName)
{
var xamlWriterFactory = new XamlWriterFactory();
var ruleHelpXamlTranslatorFactory = new RuleHelpXamlTranslatorFactory(xamlWriterFactory, new DiffTranslator(xamlWriterFactory));
var xamlGeneratorHelperFactory = new XamlGeneratorHelperFactory(ruleHelpXamlTranslatorFactory);
var ruleInfoTranslator = new RuleInfoTranslator(ruleHelpXamlTranslatorFactory, new TestLogger());
var staticXamlStorage = new StaticXamlStorage(ruleHelpXamlTranslatorFactory);

var simpleXamlBuilder = new SimpleRuleHelpXamlBuilder(ruleHelpXamlTranslatorFactory, xamlGeneratorHelperFactory, xamlWriterFactory);
var richXamlBuilder = new RichRuleHelpXamlBuilder(ruleInfoTranslator, xamlGeneratorHelperFactory, staticXamlStorage, xamlWriterFactory);

try
{
bool res = false;

var data = ReadResource(fullResourceName);
var jsonRuleInfo = LocalRuleMetadataProvider.RuleInfoJsonDeserializer.Deserialize(data);

Expand All @@ -104,7 +96,7 @@ private static bool ProcessResource(string fullResourceName)
Res(richXamlBuilder.Create(jsonRuleInfo, null));
res = true;
}

return res; // simple || rich should be true
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions src/Rules.UnitTests/HtmlXmlCompatibilityHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class HtmlXmlCompatibilityHelperTests
[TestMethod]
public void EnsureHtmlIsXml_ClosesBr()
{
HtmlXmlCompatibilityHelper.EnsureHtmlIsXml("Lalala<br> < br >Hi <br>").Should().BeEquivalentTo("Lalala<br/> < br />Hi");
HtmlXmlCompatibilityHelper.EnsureHtmlIsXml("Lalala<br> < br >Hi").Should().BeEquivalentTo("Lalala<br/> < br />Hi");
}

[TestMethod]
Expand All @@ -45,7 +45,7 @@ public void EnsureHtmlIsXml_ClosesCol()
{
HtmlXmlCompatibilityHelper.EnsureHtmlIsXml("Lalala<col span=\"2\" style=\"background-color:red\">Hi < col > hello")
.Should()
.BeEquivalentTo("Lalala<col span=\"2\" style=\"background-color:red\"/>Hi < col /> hello <col/>");
.BeEquivalentTo("Lalala<col span=\"2\" style=\"background-color:red\"/>Hi < col /> hello");
}

[TestMethod]
Expand Down

0 comments on commit ca23d83

Please sign in to comment.