Skip to content

Instantly share code, notes, and snippets.

@ThiagoBarradas
Last active January 25, 2021 16:07
Show Gist options
  • Save ThiagoBarradas/67dd229ad7aa7e0466493d7a606bf421 to your computer and use it in GitHub Desktop.
Save ThiagoBarradas/67dd229ad7aa7e0466493d7a606bf421 to your computer and use it in GitHub Desktop.
xUnit Theory ClassData Sample
// class with parameters
public class SendEmailParameters : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
// 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
}
};
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
// tests
[Theory]
[ClassData(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.True(expected.Result, emailSended.Result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment