513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
75 lines
3.1 KiB
C#
75 lines
3.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
|
|
{
|
|
/// <summary>Verifies that creating an email recipient sets the email address and leaves the phone number null.</summary>
|
|
[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);
|
|
}
|
|
|
|
/// <summary>Verifies that creating an SMS recipient sets the phone number and leaves the email address null.</summary>
|
|
[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);
|
|
}
|
|
|
|
/// <summary>Verifies that creating an email recipient with a blank name throws.</summary>
|
|
/// <param name="name">The blank recipient name.</param>
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
public void ForEmail_BlankName_Throws(string? name)
|
|
=> Assert.Throws<ArgumentException>(() => NotificationRecipient.ForEmail(name!, "jane@example.com"));
|
|
|
|
/// <summary>Verifies that creating an SMS recipient with a blank name throws.</summary>
|
|
/// <param name="name">The blank recipient name.</param>
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
public void ForSms_BlankName_Throws(string? name)
|
|
=> Assert.Throws<ArgumentException>(() => NotificationRecipient.ForSms(name!, "+15551234567"));
|
|
|
|
/// <summary>Verifies that creating an email recipient with a null email address throws.</summary>
|
|
[Fact]
|
|
public void ForEmail_NullEmail_Throws()
|
|
=> Assert.Throws<ArgumentNullException>(() => NotificationRecipient.ForEmail("Jane", null!));
|
|
|
|
/// <summary>Verifies that creating an SMS recipient with a null phone number throws.</summary>
|
|
[Fact]
|
|
public void ForSms_NullPhone_Throws()
|
|
=> Assert.Throws<ArgumentNullException>(() => NotificationRecipient.ForSms("Jane", null!));
|
|
|
|
/// <summary>Verifies that the public constructor throws for a blank name.</summary>
|
|
/// <param name="name">The blank recipient name.</param>
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
public void PublicCtor_BlankName_Throws(string? name)
|
|
=> Assert.Throws<ArgumentException>(() => new NotificationRecipient(name!, "jane@example.com"));
|
|
|
|
/// <summary>Verifies that the public constructor throws for a null email address.</summary>
|
|
[Fact]
|
|
public void PublicCtor_NullEmail_Throws()
|
|
=> Assert.Throws<ArgumentNullException>(() => new NotificationRecipient("Jane", null!));
|
|
}
|