using ZB.MOM.WW.ScadaBridge.Commons.Entities.Notifications; namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Entities; /// /// Commons-NNN: locks the construction invariants /// (exactly one contact field populated per channel; non-blank name on every path). /// public class NotificationRecipientTests { /// Verifies that creating an email recipient sets the email address and leaves the phone number null. [Fact] public void ForEmail_SetsEmail_LeavesPhoneNull() { var r = NotificationRecipient.ForEmail("Jane", "jane@example.com"); Assert.Equal("Jane", r.Name); Assert.Equal("jane@example.com", r.EmailAddress); Assert.Null(r.PhoneNumber); } /// Verifies that creating an SMS recipient sets the phone number and leaves the email address null. [Fact] public void ForSms_SetsPhone_LeavesEmailNull() { var r = NotificationRecipient.ForSms("Jane", "+15551234567"); Assert.Equal("Jane", r.Name); Assert.Equal("+15551234567", r.PhoneNumber); Assert.Null(r.EmailAddress); } /// Verifies that creating an email recipient with a blank name throws. /// The blank recipient name. [Theory] [InlineData(null)] [InlineData("")] [InlineData(" ")] public void ForEmail_BlankName_Throws(string? name) => Assert.Throws(() => NotificationRecipient.ForEmail(name!, "jane@example.com")); /// Verifies that creating an SMS recipient with a blank name throws. /// The blank recipient name. [Theory] [InlineData(null)] [InlineData("")] [InlineData(" ")] public void ForSms_BlankName_Throws(string? name) => Assert.Throws(() => NotificationRecipient.ForSms(name!, "+15551234567")); /// Verifies that creating an email recipient with a null email address throws. [Fact] public void ForEmail_NullEmail_Throws() => Assert.Throws(() => NotificationRecipient.ForEmail("Jane", null!)); /// Verifies that creating an SMS recipient with a null phone number throws. [Fact] public void ForSms_NullPhone_Throws() => Assert.Throws(() => NotificationRecipient.ForSms("Jane", null!)); /// Verifies that the public constructor throws for a blank name. /// The blank recipient name. [Theory] [InlineData(null)] [InlineData("")] [InlineData(" ")] public void PublicCtor_BlankName_Throws(string? name) => Assert.Throws(() => new NotificationRecipient(name!, "jane@example.com")); /// Verifies that the public constructor throws for a null email address. [Fact] public void PublicCtor_NullEmail_Throws() => Assert.Throws(() => new NotificationRecipient("Jane", null!)); }