public static void ValidateNotSupplied(string s, ClientExDetail detail) { if (!string.IsNullOrWhiteSpace(s)) { throw detail.Instance(); } }
public void TestValidateMustMatchIfBothSupplied() { ClientExDetail detail = new ClientExDetail("TEST", 999999, "desc"); Assert.Null(Validator.ValidateMustMatchIfBothSupplied(null, null, detail)); Assert.Equal("y", Validator.ValidateMustMatchIfBothSupplied(null, "y", detail)); Assert.Equal("y", Validator.ValidateMustMatchIfBothSupplied("", "y", detail)); Assert.Equal("x", Validator.ValidateMustMatchIfBothSupplied("x", null, detail)); Assert.Equal("x", Validator.ValidateMustMatchIfBothSupplied("x", " ", detail)); Assert.Equal("x", Validator.ValidateMustMatchIfBothSupplied("x", "x", detail)); Assert.Throws <NATSJetStreamClientException>(() => Validator.ValidateMustMatchIfBothSupplied("x", "y", detail)); }
internal static string ValidateMustMatchIfBothSupplied(string s1, string s2, ClientExDetail detail) { // s1 | s2 || result // ---- | ---- || -------------- // null | null || valid, null s2 // null | y || valid, y s2 // x | null || valid, x s1 // x | x || valid, x s1 // x | y || invalid s1 = EmptyAsNull(s1); s2 = EmptyAsNull(s2); if (s1 == null) { return(s2); // s2 can be either null or y } // x / null or x / x if (s2 == null || s1.Equals(s2)) { return(s1); } throw detail.Instance(); }
public void TestNatsJetStreamClientError() { ClientExDetail err = new ClientExDetail("TEST", 999999, "desc"); Assert.Equal("[TEST-999999] desc", err.Message); }