using Ardalis.GuardClauses; using System; using Xunit; namespace UnitTests.GuardClauses { public class InvalidEmailGuard { [Fact] public void ThrowsArgumentNullExceptionIfNullOrEmptyEmail() { string? email = null; Assert.Throws<ArgumentNullException>(() => Guard.Against.InvalidEmail(email, nameof(email))); } [Fact] public void ThrowsArgumentExceptionIfEmailDoesNotEndInCorrectSuffix() { var email = "eric@fleming.invalidsuffix"; Assert.Throws<ArgumentException>(() => Guard.Against.InvalidEmail(email, nameof(email))); } [Fact] public void ReturnsEmailAddressGivenValidEmail() { var validEmailAddress = "eric@fleming.com"; var result = Guard.Against.InvalidEmail(validEmailAddress, nameof(validEmailAddress)); Assert.Equal(validEmailAddress, result); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter