Last active
January 25, 2021 16:07
-
-
Save ThiagoBarradas/67dd229ad7aa7e0466493d7a606bf421 to your computer and use it in GitHub Desktop.
xUnit Theory ClassData Sample
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
// 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