コード例 #1
0
 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());
コード例 #2
0
 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());
コード例 #3
0
 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());
コード例 #4
0
 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());
コード例 #5
0
 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);
コード例 #6
0
 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());
コード例 #7
0
        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);
        }
コード例 #8
0
        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());
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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());
コード例 #12
0
        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);
        }
コード例 #13
0
 public void ReturnEmptyCollectionInsteadOfNull() =>
 Verifier.VerifyAnalyzer(@"TestCases\ReturnEmptyCollectionInsteadOfNull.cs",
                         new ReturnEmptyCollectionInsteadOfNull(),
                         additionalReferences: MetadataReferenceFacade.GetSystemXml());
コード例 #14
0
 public void TypesShouldNotExtendOutdatedBaseTypes() =>
 Verifier.VerifyAnalyzer(@"TestCases\TypesShouldNotExtendOutdatedBaseTypes.cs",
                         new TypesShouldNotExtendOutdatedBaseTypes(),
                         additionalReferences: MetadataReferenceFacade.GetSystemXml().Concat(MetadataReferenceFacade.GetSystemCollections()));