Created
October 28, 2019 18:06
-
-
Save johnmwright/bf374e3ac588fd9ceb8476148578772c to your computer and use it in GitHub Desktop.
Sample tests cases for https://github.com/nunit/nunit3-vs-adapter/issues/622
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using NUnit.Framework; | |
namespace NUnit_POC | |
{ | |
[TestFixture] | |
public class PassingTest | |
{ | |
[Test] | |
[TestCaseSource(nameof(TestCaseSourceMethod))] | |
public void DemoTest2(string param1) | |
{ | |
Assert.Pass("Just pass"); | |
} | |
private static IEnumerable<TestCaseData> TestCaseSourceMethod() | |
{ | |
yield return new TestCaseData("Name with mismatched parenthesis 'pp:-) :-)'").SetName("Name with mismatched parenthesis 'pp:-) :-)'"); | |
yield return new TestCaseData("Name with mismatched quote '\"c'").SetName("Name with mismatched quote '\"c'"); | |
} | |
} | |
[TestFixture] | |
public class TestNameRepro_jerryk414 | |
{ | |
#region TestCaseSource | |
protected static IEnumerable TestName_TestCases | |
{ | |
get | |
{ | |
// Adding a parenthesis to the end of this test name will stop the exception from throwing (e.g. $"TestName(...)") | |
yield return new TestCaseData(1).SetName($"TestName(..."); | |
// Cannot be duplicated without a second test included that ends with a ']' | |
yield return new TestCaseData(2).SetName($"TestName(...)]"); | |
} | |
} | |
#endregion | |
[Test, TestCaseSource(nameof(TestName_TestCases))] | |
public void TestName(int input) | |
{ | |
// Irrelevant | |
} | |
} | |
[TestFixture] | |
public class Repo_Dragonsangel | |
{ | |
[Test] | |
[TestCase(typeof(IEnumerable<(String oneValue, Int32 twoValue)>))] | |
public void UnitTest_TestCaseWithTuple_TestIsNotExecuted(Type targetType) | |
{ | |
Assert.That(targetType == typeof(IEnumerable<(String oneValue, Int32 twoValue)>), Is.True); | |
} | |
} | |
[TestFixture] | |
public class Repo_gavinschultz | |
{ | |
[Test, TestCaseSource(nameof(SourceA))] | |
public void TestA((int a, int b) x, int y) { } | |
public static IEnumerable SourceA => | |
new[] { new TestCaseData((a: 1, b: 2), 5) }; | |
[Test, TestCaseSource(nameof(SourceB))] | |
public void TestB(int y, (int a, int b) x) { } | |
public static IEnumerable SourceB => | |
new[] { new TestCaseData(5, (a: 1, b: 2)) }; | |
[Test, TestCaseSource(nameof(SourceC))] | |
public void TestC((int a, int b) x, int y) { } | |
public static IEnumerable SourceC => | |
new[] { new TestCaseData((a: 1, b: 2), 5).SetArgDisplayNames("a+b", "y") }; | |
} | |
[TestFixture] | |
public class Repo_johnjaylward | |
{ | |
[Test(), TestCaseSource(typeof(CaseTestData), nameof(CaseTestData.EqualsData))] | |
public void EqualsTest(Case case1, Case case2) | |
{ | |
Assert.AreEqual(case1, case2); | |
} | |
public class CaseTestData | |
{ | |
public IEnumerable EqualsData() | |
{ | |
yield return new object[] {new Case {Name = "case1"}, new Case {Name = "case2"}}; | |
} | |
} | |
public class Case | |
{ | |
public string Name; | |
} | |
} | |
//after | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment