コード例 #1
0
        public void TestMethodShouldContainAssertion_NUnit_FluentAssertionsLegacy(string testFwkVersion, string fluentVersion) =>
        Verifier.VerifyCSharpAnalyzer(@"
using System;
using FluentAssertions;
using NUnit.Framework;

[TestFixture]
public class Foo
{
    [Test]
    public void Test1() // Noncompliant
    {
        var x = 42;
    }

    [Test]
    public void ShouldThrowTest()
    {
        Action act = () => { throw new Exception(); };
        act.ShouldThrow<Exception>();
    }

    [Test]
    public void ShouldNotThrowTest()
    {
        Action act = () => { throw new Exception(); };
        act.ShouldNotThrow<Exception>();
    }
}",
                                      new TestMethodShouldContainAssertion(),
                                      additionalReferences:
                                      NuGetMetadataReference.NUnit(testFwkVersion)
                                      .Concat(NuGetMetadataReference.FluentAssertions(fluentVersion))
                                      .Concat(MetadataReferenceFacade.GetSystemThreadingTasks()));
コード例 #2
0
 public static IEnumerable <MetadataReference> GetMsTestReferences(string msTestVersion) =>
 NuGetMetadataReference.MSTestTestFramework(msTestVersion)
 .Concat(NuGetMetadataReference.FluentAssertions(Constants.NuGetLatestVersion))
 .Concat(NuGetMetadataReference.NSubstitute(Constants.NuGetLatestVersion))
 .Concat(MetadataReferenceFacade.SystemXml)
 .Concat(MetadataReferenceFacade.SystemXmlLinq)
 .ToArray();
コード例 #3
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());
コード例 #4
0
 public void TestMethodShouldContainAssertion_Xunit_Legacy()
 {
     Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldContainAssertion.Xunit.Legacy.cs",
                             new TestMethodShouldContainAssertion(),
                             additionalReferences: NuGetMetadataReference.XunitFrameworkV1
                             .Concat(NuGetMetadataReference.FluentAssertions("1.6.0"))
                             .ToArray());
 }
コード例 #5
0
 public void TestMethodShouldContainAssertion_Xunit(string testFwkVersion, string fluentVersion)
 {
     Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldContainAssertion.Xunit.cs",
                             new TestMethodShouldContainAssertion(),
                             additionalReferences: NuGetMetadataReference.XunitFramework(testFwkVersion)
                             .Concat(NuGetMetadataReference.FluentAssertions(fluentVersion))
                             .ToArray());
 }
コード例 #6
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());
コード例 #7
0
 public void TestMethodShouldContainAssertion_MSTest(string testFwkVersion, string fluentVersion, string nSubstituteVersion) =>
 Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldContainAssertion.MsTest.cs",
                         new CS.TestMethodShouldContainAssertion(),
                         NuGetMetadataReference.MSTestTestFramework(testFwkVersion)
                         .Concat(NuGetMetadataReference.FluentAssertions(fluentVersion))
                         .Concat(NuGetMetadataReference.NSubstitute(nSubstituteVersion))
                         .Concat(MetadataReferenceFacade.SystemXml)
                         .Concat(MetadataReferenceFacade.SystemXmlLinq)
                         .ToArray());
コード例 #8
0
 public static IEnumerable <MetadataReference> AdditionalTestReferences(IEnumerable <MetadataReference> testFrameworkReference,
                                                                        string fluentVersion      = Constants.NuGetLatestVersion,
                                                                        string nSubstituteVersion = Constants.NuGetLatestVersion) =>
 testFrameworkReference
 .Concat(NuGetMetadataReference.FluentAssertions(fluentVersion))
 .Concat(NuGetMetadataReference.NSubstitute(nSubstituteVersion))
 .Concat(MetadataReferenceFacade.SystemXml)
 .Concat(MetadataReferenceFacade.SystemXmlLinq)
 .Concat(MetadataReferenceFacade.SystemThreadingTasks)
 .ToArray();
コード例 #9
0
 public void TestMethodShouldContainAssertion_NUnit(string testFwkVersion, string fluentVersion)
 {
     Verifier.VerifyAnalyzer(@"TestCases\TestMethodShouldContainAssertion.NUnit.cs",
                             new TestMethodShouldContainAssertion(),
                             additionalReferences: NuGetMetadataReference.NUnit(testFwkVersion)
                             .Concat(NuGetMetadataReference.FluentAssertions(fluentVersion))
                             .Concat(FrameworkMetadataReference.SystemReflection)
                             .Concat(FrameworkMetadataReference.SystemXmlXDocument)
                             .Concat(FrameworkMetadataReference.SystemXmlLinq)
                             .Concat(FrameworkMetadataReference.SystemThreadingTasks)
                             .ToArray());
 }
コード例 #10
0
        public void TestMethodShouldContainAssertion_NUnit_V2Specific(string testFwkVersion, string fluentVersion)
        {
            Verifier.VerifyCSharpAnalyzer(@"
using System;
using FluentAssertions;
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(NuGetMetadataReference.FluentAssertions(fluentVersion))
                                          .Concat(FrameworkMetadataReference.SystemReflection)
                                          .Concat(FrameworkMetadataReference.SystemXmlXDocument)
                                          .Concat(FrameworkMetadataReference.SystemXmlLinq)
                                          .Concat(FrameworkMetadataReference.SystemThreadingTasks)
                                          .ToArray());
        }
コード例 #11
0
        public void IsTest_ReturnsTrueForTestFrameworks()
        {
            IsTest(NuGetMetadataReference.JetBrainsDotMemoryUnit(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.MSTestTestFrameworkV1).Should().BeTrue();
            IsTest(NuGetMetadataReference.MSTestTestFramework(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.MicrosoftVisualStudioQualityToolsUnitTestFramework).Should().BeTrue();
            IsTest(NuGetMetadataReference.MachineSpecifications(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.NUnit(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.NUnitLite(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.SpecFlow(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.XunitFrameworkV1).Should().BeTrue();
            IsTest(NuGetMetadataReference.XunitFramework(Constants.NuGetLatestVersion)).Should().BeTrue();

            // Assertion
            IsTest(NuGetMetadataReference.FluentAssertions(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.Shouldly(Constants.NuGetLatestVersion)).Should().BeTrue();

            // Mock
            IsTest(NuGetMetadataReference.FakeItEasy(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.JustMock(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.Moq(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.NSubstitute(Constants.NuGetLatestVersion)).Should().BeTrue();
            IsTest(NuGetMetadataReference.RhinoMocks(Constants.NuGetLatestVersion)).Should().BeTrue();
        }