Skip to content

Instantly share code, notes, and snippets.

@ThiagoBarradas
Last active January 25, 2021 16:08
Show Gist options
  • Save ThiagoBarradas/eb74f9ad31efaa85ea80391363fde163 to your computer and use it in GitHub Desktop.
Save ThiagoBarradas/eb74f9ad31efaa85ea80391363fde163 to your computer and use it in GitHub Desktop.
xUnit Theory Hybrid (MemberData + ClassData) Sample
// test parameters
public class SendEmailParameters()
{
public static IEnumerable<object[]> Parameters()
{
// parameters to test send email success
yield return new object[]
{
new SendEmailModel
{
Content = "hello world",
Email = "[email protected]"
},
new SendEmailResult
{
Result = true
}
};
// parameters to test send email failed
yield return new object[]
{
new SendEmailModel
{
Content = "hello world",
Email = "wrong-email"
},
new SendEmailResult
{
Result = false
}
};
}
}
// tests
[Theory]
[MemberData(nameof(Parameters), MemberType= typeof(SendEmailParameters))]
public static void SendEmail_Should_Validate_Email(SendEmailModel model, SendEmailResult expected)
{
// arrange
var emailSender = new EmailSender();
// act
var emailSended = emailSender.SendEmail(model);
// assert
Assert.Equals(expected.Result, emailSended.Result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment