public void XmlExternalEntityShouldNotBeParsed_XPathDocument_CSharp9() => Verifier.VerifyAnalyzerFromCSharp9Console(@"TestCases\XmlExternalEntityShouldNotBeParsed_XPathDocument_CSharp9.cs", new XmlExternalEntityShouldNotBeParsed(GetVersionProviderMock(NetFrameworkVersion.After452)), MetadataReferenceFacade.GetSystemXml() .Concat(MetadataReferenceFacade.GetSystemData()) .Concat(MetadataReferenceFacade.GetSystemXmlLinq()) .ToArray());
public void TestMethodShouldContainAssertion_Xunit_Legacy() => Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldContainAssertion.Xunit.Legacy.cs", new TestMethodShouldContainAssertion(), additionalReferences: NuGetMetadataReference.XunitFrameworkV1 .Concat(NuGetMetadataReference.FluentAssertions(Constants.NuGetLatestVersion)) .Concat(MetadataReferenceFacade.GetSystemXml()) .Concat(MetadataReferenceFacade.GetSystemXmlLinq()) .ToArray());
public void XmlExternalEntityShouldNotBeParsed_XmlDocument(NetFrameworkVersion version, string testFilePath) => Verifier.VerifyAnalyzer(testFilePath, new XmlExternalEntityShouldNotBeParsed(GetVersionProviderMock(version)), additionalReferences: MetadataReferenceFacade.GetSystemXml() .Concat(MetadataReferenceFacade.GetSystemData()) .Concat(MetadataReferenceFacade.GetSystemXmlLinq()) .Concat(NuGetMetadataReference.MicrosoftWebXdt()) .ToArray());
public void TestMethodShouldContainAssertion_NUnit(string testFwkVersion, string fluentVersion, string nSubstituteVersion) => Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldContainAssertion.NUnit.cs", new TestMethodShouldContainAssertion(), additionalReferences: NuGetMetadataReference.NUnit(testFwkVersion) .Concat(NuGetMetadataReference.FluentAssertions(fluentVersion)) .Concat(NuGetMetadataReference.NSubstitute(nSubstituteVersion)) .Concat(MetadataReferenceFacade.GetSystemXml()) .Concat(MetadataReferenceFacade.GetSystemXmlLinq()) .ToArray());
private static void VerifyRule(NetFrameworkVersion version, string testFilePath, OutputKind outputKind = OutputKind.DynamicallyLinkedLibrary, IEnumerable <ParseOptions> options = null) => Verifier.VerifyAnalyzer(testFilePath, new XmlExternalEntityShouldNotBeParsed(GetVersionProviderMock(version)), additionalReferences: MetadataReferenceFacade.GetSystemXml() .Concat(MetadataReferenceFacade.GetSystemData()) .Concat(MetadataReferenceFacade.GetSystemXmlLinq()) .ToArray(), outputKind: outputKind, options: options);
public void XmlExternalEntityShouldNotBeParsed_NoCrashOnExternalParameterUse() => Verifier.VerifyAnalyzer( new[] { @"TestCases\XmlExternalEntityShouldNotBeParsed_XmlReader_ExternalParameter.cs", @"TestCases\XmlExternalEntityShouldNotBeParsed_XmlReader_ParameterProvider.cs" }, new XmlExternalEntityShouldNotBeParsed(GetVersionProviderMock(NetFrameworkVersion.After452)), additionalReferences: MetadataReferenceFacade.GetSystemXml());
public void XmlExternalEntityShouldNotBeParsed_XmlTextReader(NetFrameworkVersion version, string testFilePath) { // setup var rule = new XmlExternalEntityShouldNotBeParsed(GetVersionProviderMock(version)); // act & verify Verifier.VerifyAnalyzer(testFilePath, rule, additionalReferences: MetadataReferenceFacade.GetSystemXml().ToArray(), options: ParseOptionsHelper.FromCSharp8); }
private static void VerifyRule(NetFrameworkVersion version, string testFilePath) { var rule = new XmlExternalEntityShouldNotBeParsed(GetVersionProviderMock(version)); Verifier.VerifyAnalyzer(testFilePath, rule, additionalReferences: MetadataReferenceFacade.GetSystemXml() .Concat(MetadataReferenceFacade.GetSystemData()) .Concat(MetadataReferenceFacade.GetSystemXmlLinq()) .ToArray()); }
public void XmlExternalEntityShouldNotBeParsed_XmlDocument(NetFrameworkVersion version, string testFilePath) { // setup var rule = new XmlExternalEntityShouldNotBeParsed(GetVersionProviderMock(version)); // act & verify Verifier.VerifyAnalyzer(testFilePath, rule, additionalReferences: MetadataReferenceFacade.GetSystemXml() .Concat(MetadataReferenceFacade.GetSystemData()) .Concat(MetadataReferenceFacade.GetSystemXmlLinq()) .Concat(NuGetMetadataReference.MicrosoftWebXdt()) .ToArray(), options: ParseOptionsHelper.FromCSharp8); }
public void ExactMatch_DoesNotMatchOverrides_VB() { var code = @" Imports System.Xml Namespace Test Class Class1 Public Sub DoStuff(node As XmlNode, doc As XmlDocument) node.WriteTo(Nothing) doc.WriteTo(Nothing) End Sub End Class End Namespace "; var snippet = new SnippetCompiler(code, false, AnalyzerLanguage.VisualBasic, MetadataReferenceFacade.GetSystemXml()); CheckExactMatch_DoesNotMatchOverrides(snippet); }
public void TestMethodShouldContainAssertion_NUnit_V2Specific(string testFwkVersion) => Verifier.VerifyCSharpAnalyzer(@" using System; using NUnit.Framework; [TestFixture] public class Foo { [TestCase] [ExpectedException(typeof(Exception))] public void TestCase4() { var x = System.IO.File.Open("""", System.IO.FileMode.Open); } [Theory] [ExpectedException(typeof(Exception))] public void Theory4() { var x = System.IO.File.Open("""", System.IO.FileMode.Open); } [TestCaseSource(""Foo"")] [ExpectedException(typeof(Exception))] public void TestCaseSource4() { var x = System.IO.File.Open("""", System.IO.FileMode.Open); } [Test] [ExpectedException(typeof(Exception))] public void Test4() { var x = System.IO.File.Open("""", System.IO.FileMode.Open); } }", new TestMethodShouldContainAssertion(), additionalReferences: NuGetMetadataReference.NUnit(testFwkVersion) .Concat(MetadataReferenceFacade.GetSystemXml()) .Concat(MetadataReferenceFacade.GetSystemXmlLinq()) .ToArray());
public void IsMatch_AndCheckingOverrides_DoesMatchOverrides_CS() { var code = @" namespace Test { using System.Xml; class Class1 { public void DoStuff(XmlNode node, XmlDocument doc) { node.WriteTo(null); doc.WriteTo(null); } } } "; var snippet = new SnippetCompiler(code, MetadataReferenceFacade.GetSystemXml()); CheckIsMatch_AndCheckingOverrides_DoesMatchOverrides(snippet); }
public void ReturnEmptyCollectionInsteadOfNull() => Verifier.VerifyAnalyzer(@"TestCases\ReturnEmptyCollectionInsteadOfNull.cs", new ReturnEmptyCollectionInsteadOfNull(), additionalReferences: MetadataReferenceFacade.GetSystemXml());
public void TypesShouldNotExtendOutdatedBaseTypes() => Verifier.VerifyAnalyzer(@"TestCases\TypesShouldNotExtendOutdatedBaseTypes.cs", new TypesShouldNotExtendOutdatedBaseTypes(), additionalReferences: MetadataReferenceFacade.GetSystemXml().Concat(MetadataReferenceFacade.GetSystemCollections()));