Last active
October 18, 2023 20:06
-
-
Save JerryNixon/3df3944f856737b5cef831ab8b02641c to your computer and use it in GitHub Desktop.
Using complex data types as InlineData for Xunit tests.
This file contains hidden or 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.Collections.Generic; | |
using System.Linq; | |
using Xunit; | |
namespace PlaygroundXunit | |
{ | |
public class UnitTest1 | |
{ | |
[Theory] | |
[MemberData(nameof(Test1Data))] | |
public void Test1Test((string FirstName, string LastName) values) | |
{ | |
Assert.NotNull(values.FirstName); | |
Assert.NotNull(values.LastName); | |
} | |
public static IEnumerable<object[]> Test1Data | |
{ | |
get => new List<(string FirstName, string LastName)> | |
{ | |
("Jerry", "Nixon"), | |
("Rob", "Bagby") | |
}.Select(x => new[] { (object)x }); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is simpler with
TheoryData
: