Last active
March 6, 2023 17:50
-
-
Save ThiagoBarradas/74e019c51e85a01cc92112d4299e3715 to your computer and use it in GitHub Desktop.
xUnit Theory MemberData Sample
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
// models for example | |
public class SendEmailModel | |
{ | |
public string Content { get; set; } | |
public string Email { get; set; } | |
} | |
public class SendEmailResult | |
{ | |
public bool Result { get; set; } | |
} | |
// test parameters | |
public static IEnumerable<object[]> SendEmailParameters() | |
{ | |
// parameters to test send email success | |
yield return new object[] | |
{ | |
new SendEmailModel | |
{ | |
Content = "hello world", | |
Email = "user@provider.com" | |
}, | |
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(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