Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.Commons.Tests/Entities/NotificationRecipientTests.cs
T
Joseph Doherty a9393c8913 test(sms): regression tests for code-review fixes
Lock the behaviors changed by the review-fix commit + the security invariants:

- ManagementActorTests: UpdateSms/SmtpConfig now require Administrator (updated the
  existing success cases from Designer); + UpdateSmsConfig_WithDesignerRole_Returns
  Unauthorized and _WithEmptyAuthToken_PreservesExistingToken regression tests.
- SecretEncryptionTests: SmsConfiguration.AuthToken stored-encrypted round-trip +
  null round-trip (AccountSid stays plaintext) — guards ApplySecretColumnEncryption.
- ArtifactDiffTests: CompareSmsConfiguration New/Identical/Modified + the secret
  presence-only invariant (value never echoed, presence-flip shows <present> only).
- UpdateCommandContractTests: notification sms update core fields Required, --auth-token optional.
- NotificationListsPageTests: SMS recipient badge shows phone, not "Name <>".
- NotificationOutboxActorDispatchTests: SMS-typed notification routes to the SMS
  adapter (StubAdapter.Type made configurable), not the Email adapter.
- NotificationRecipientTests (new): ForEmail/ForSms + public-ctor invariants.
2026-06-19 15:09:47 -04:00

64 lines
2.1 KiB
C#

using ZB.MOM.WW.ScadaBridge.Commons.Entities.Notifications;
namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Entities;
/// <summary>
/// Commons-NNN: locks the <see cref="NotificationRecipient"/> construction invariants
/// (exactly one contact field populated per channel; non-blank name on every path).
/// </summary>
public class NotificationRecipientTests
{
[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);
}
[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);
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void ForEmail_BlankName_Throws(string? name)
=> Assert.Throws<ArgumentException>(() => NotificationRecipient.ForEmail(name!, "jane@example.com"));
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void ForSms_BlankName_Throws(string? name)
=> Assert.Throws<ArgumentException>(() => NotificationRecipient.ForSms(name!, "+15551234567"));
[Fact]
public void ForEmail_NullEmail_Throws()
=> Assert.Throws<ArgumentNullException>(() => NotificationRecipient.ForEmail("Jane", null!));
[Fact]
public void ForSms_NullPhone_Throws()
=> Assert.Throws<ArgumentNullException>(() => NotificationRecipient.ForSms("Jane", null!));
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void PublicCtor_BlankName_Throws(string? name)
=> Assert.Throws<ArgumentException>(() => new NotificationRecipient(name!, "jane@example.com"));
[Fact]
public void PublicCtor_NullEmail_Throws()
=> Assert.Throws<ArgumentNullException>(() => new NotificationRecipient("Jane", null!));
}