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()));
 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();
 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());
Beispiel #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());
 }
 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());
 }
 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());
Beispiel #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());
Beispiel #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();
Beispiel #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());
 }
Beispiel #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());
        }
Beispiel #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();
        }