how do you assert exception xunit code example
Example 1: xunit expect exception
[Fact]
public void ProfileRepository_GetSettingsForUserIDWithInvalidArguments_ThrowsArgumentException()
{
ProfileRepository profiles = new ProfileRepository();
Assert.Throws<ArgumentException>(() => profiles.GetSettingsForUserID(""));
}
Example 2: xunit test exception thrown
[Fact]
public void ProfileRepository_GetSettingsForUserIDWithInvalidArguments_ThrowsArgumentException()
{
ProfileRepository profiles = new ProfileRepository();
Action act = () => profiles.GetSettingsForUserID("");
ArgumentException exception = Assert.Throws<ArgumentException>(act);
Assert.Equal("expected error message here", exception.Message);
}