Last active
April 11, 2020 22:18
-
-
Save ankitvijay/5fb9f0b07bb359abe36c9edb535e407d to your computer and use it in GitHub Desktop.
xUnitMemberDataExample_Version2_2
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
public class AnimalRepositoryTestSource : TestSource | |
{ | |
public AnimalRepositoryTestSource(SearchCriteria searchCriteria, string expectedResult, [CallerMemberName]string testName = null) | |
: base(testName) | |
{ | |
SearchCriteria = searchCriteria; | |
ExpectedResult = expectedResult; | |
} | |
public SearchCriteria SearchCriteria { get; } | |
public string ExpectedResult { get; } | |
} |
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
public class AnimalRepositoryTests | |
{ | |
[Theory] | |
[MemberData(nameof(GetFindAnimalData))] | |
public void FindReturnsCorrectResult(AnimalRepositoryTestSource testData) | |
{ | |
var repository = new AnimalRepository(); | |
// Act | |
var result = repository.Find(testData.SearchCriteria); | |
// Assert | |
Assert.Equal(testData.ExpectedResult, result); | |
} | |
public static IEnumerable<object[]> GetFindAnimalData() | |
{ | |
yield return WhenSearchTermDoesNotExist(); | |
yield return WhenIgnoreCaseIsSetToTrue(); | |
yield return WhenSearchTermIsPartialMatch(); | |
} | |
private static object[] WhenSearchTermDoesNotExist() | |
{ | |
return new object[] | |
{ | |
new AnimalRepositoryTestSource(new SearchCriteria("FOX"), null) | |
}; | |
} | |
private static object[] WhenIgnoreCaseIsSetToTrue() | |
{ | |
return new object[] | |
{ | |
new AnimalRepositoryTestSource(new SearchCriteria("dog", true), "DOG") | |
}; | |
} | |
private static object[] WhenSearchTermIsPartialMatch() | |
{ | |
return new object[] | |
{ | |
new AnimalRepositoryTestSource(new SearchCriteria("IG", true), "TIGER") | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment