From ea928aa9ed6ff488e496ca18c2226f46a441ad13 Mon Sep 17 00:00:00 2001 From: sbansla Date: Thu, 7 Aug 2025 11:39:13 +0530 Subject: [PATCH 1/5] chore: added App IEndpoint type --- src/Twilio/Types/App.cs | 35 +++++++++++++++++++++++++++++++ test/Twilio.Test/Types/AppTest.cs | 21 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/Twilio/Types/App.cs create mode 100644 test/Twilio.Test/Types/AppTest.cs diff --git a/src/Twilio/Types/App.cs b/src/Twilio/Types/App.cs new file mode 100644 index 000000000..a5ce950ea --- /dev/null +++ b/src/Twilio/Types/App.cs @@ -0,0 +1,35 @@ +namespace Twilio.Types +{ + /// + /// App Endpoint + /// + public class App : IEndpoint + { + public const string PREFIX = "app:"; + + private readonly string _app; + + /// + /// Create new app + /// + /// App name + public App(string app) + { + if (!app.ToLower().StartsWith(PREFIX)) + { + app = PREFIX + app; + } + + _app = app; + } + + /// + /// Convert to string + /// + /// String representation + public override string ToString() + { + return _app; + } + } +} diff --git a/test/Twilio.Test/Types/AppTest.cs b/test/Twilio.Test/Types/AppTest.cs new file mode 100644 index 000000000..b8ac6ef45 --- /dev/null +++ b/test/Twilio.Test/Types/AppTest.cs @@ -0,0 +1,21 @@ +using System; +using NUnit.Framework; +using Twilio.Types; + +namespace Twilio.Tests.Types +{ + [TestFixture] + public class AppTest + { + [Test] + public void TestToString() + { + Assert.AreEqual("app:me", new App("me").ToString()); + Assert.AreEqual("app:YOU", new App("YOU").ToString()); + Assert.AreEqual("APP:HIM", new App("APP:HIM").ToString()); + Assert.AreEqual("aPp:her", new App("aPp:her").ToString()); + Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("app:AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString()); + Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString()); + } + } +} From db5ce65fdffe8869107a1b5cce354a79dd3bf313 Mon Sep 17 00:00:00 2001 From: sbansla Date: Thu, 25 Sep 2025 13:56:29 +0530 Subject: [PATCH 2/5] added null and empty check and added its test cases --- src/Twilio/Exceptions/InvalidInputException.cs | 12 ++++++++++++ src/Twilio/Types/App.cs | 8 +++++++- test/Twilio.Test/Types/AppTest.cs | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/Twilio/Exceptions/InvalidInputException.cs diff --git a/src/Twilio/Exceptions/InvalidInputException.cs b/src/Twilio/Exceptions/InvalidInputException.cs new file mode 100644 index 000000000..acde78f5a --- /dev/null +++ b/src/Twilio/Exceptions/InvalidInputException.cs @@ -0,0 +1,12 @@ +using System; + +namespace Twilio.Exceptions +{ + public class InvalidInputException : ArgumentException + { + public InvalidInputException(string paramName) + : base($"The parameter '{paramName}' cannot be null or empty.", paramName) + { + } + } +} \ No newline at end of file diff --git a/src/Twilio/Types/App.cs b/src/Twilio/Types/App.cs index a5ce950ea..54deadc98 100644 --- a/src/Twilio/Types/App.cs +++ b/src/Twilio/Types/App.cs @@ -1,4 +1,6 @@ -namespace Twilio.Types +using Twilio.Exceptions; + +namespace Twilio.Types { /// /// App Endpoint @@ -15,6 +17,10 @@ public class App : IEndpoint /// App name public App(string app) { + if (string.IsNullOrWhiteSpace(app)) + { + throw new InvalidInputException(nameof(app)); + } if (!app.ToLower().StartsWith(PREFIX)) { app = PREFIX + app; diff --git a/test/Twilio.Test/Types/AppTest.cs b/test/Twilio.Test/Types/AppTest.cs index b8ac6ef45..812f88b3a 100644 --- a/test/Twilio.Test/Types/AppTest.cs +++ b/test/Twilio.Test/Types/AppTest.cs @@ -1,5 +1,6 @@ using System; using NUnit.Framework; +using Twilio.Exceptions; using Twilio.Types; namespace Twilio.Tests.Types @@ -14,6 +15,7 @@ public void TestToString() Assert.AreEqual("app:YOU", new App("YOU").ToString()); Assert.AreEqual("APP:HIM", new App("APP:HIM").ToString()); Assert.AreEqual("aPp:her", new App("aPp:her").ToString()); + Assert.Throws(() => new App("").ToString()); Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("app:AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString()); Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString()); } From 8d79ca54e7d0f84bc147f07baa305c89d7408caf Mon Sep 17 00:00:00 2001 From: sbansla Date: Thu, 25 Sep 2025 14:07:31 +0530 Subject: [PATCH 3/5] fixed null check --- src/Twilio/Types/App.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Twilio/Types/App.cs b/src/Twilio/Types/App.cs index 54deadc98..15b4daa71 100644 --- a/src/Twilio/Types/App.cs +++ b/src/Twilio/Types/App.cs @@ -17,10 +17,11 @@ public class App : IEndpoint /// App name public App(string app) { - if (string.IsNullOrWhiteSpace(app)) + if (string.IsNullOrEmpty(app)) { throw new InvalidInputException(nameof(app)); } + if (!app.ToLower().StartsWith(PREFIX)) { app = PREFIX + app; From 21f291af5d3774daede97a793ab2b198fb3f6551 Mon Sep 17 00:00:00 2001 From: sbansla Date: Thu, 25 Sep 2025 14:12:12 +0530 Subject: [PATCH 4/5] using argument exception instead of custom exception, keeping exceptional handling uniform --- src/Twilio/Exceptions/InvalidInputException.cs | 12 ------------ src/Twilio/Types/App.cs | 4 ++-- test/Twilio.Test/Types/AppTest.cs | 2 +- 3 files changed, 3 insertions(+), 15 deletions(-) delete mode 100644 src/Twilio/Exceptions/InvalidInputException.cs diff --git a/src/Twilio/Exceptions/InvalidInputException.cs b/src/Twilio/Exceptions/InvalidInputException.cs deleted file mode 100644 index acde78f5a..000000000 --- a/src/Twilio/Exceptions/InvalidInputException.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Twilio.Exceptions -{ - public class InvalidInputException : ArgumentException - { - public InvalidInputException(string paramName) - : base($"The parameter '{paramName}' cannot be null or empty.", paramName) - { - } - } -} \ No newline at end of file diff --git a/src/Twilio/Types/App.cs b/src/Twilio/Types/App.cs index 15b4daa71..43ba6fa9e 100644 --- a/src/Twilio/Types/App.cs +++ b/src/Twilio/Types/App.cs @@ -1,4 +1,4 @@ -using Twilio.Exceptions; +using System; namespace Twilio.Types { @@ -19,7 +19,7 @@ public App(string app) { if (string.IsNullOrEmpty(app)) { - throw new InvalidInputException(nameof(app)); + throw new ArgumentException("Parameter 'app' cannot be null or empty.", nameof(app)); } if (!app.ToLower().StartsWith(PREFIX)) diff --git a/test/Twilio.Test/Types/AppTest.cs b/test/Twilio.Test/Types/AppTest.cs index 812f88b3a..b798cbc2d 100644 --- a/test/Twilio.Test/Types/AppTest.cs +++ b/test/Twilio.Test/Types/AppTest.cs @@ -15,7 +15,7 @@ public void TestToString() Assert.AreEqual("app:YOU", new App("YOU").ToString()); Assert.AreEqual("APP:HIM", new App("APP:HIM").ToString()); Assert.AreEqual("aPp:her", new App("aPp:her").ToString()); - Assert.Throws(() => new App("").ToString()); + Assert.Throws(() => new App("").ToString()); Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("app:AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString()); Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString()); } From 4f68e850a5b278e9737767d9bd42219aa9361ced Mon Sep 17 00:00:00 2001 From: sbansla Date: Mon, 29 Sep 2025 13:07:40 +0530 Subject: [PATCH 5/5] removed exception --- src/Twilio/Types/App.cs | 9 +-------- test/Twilio.Test/Types/AppTest.cs | 2 -- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Twilio/Types/App.cs b/src/Twilio/Types/App.cs index 43ba6fa9e..a5ce950ea 100644 --- a/src/Twilio/Types/App.cs +++ b/src/Twilio/Types/App.cs @@ -1,6 +1,4 @@ -using System; - -namespace Twilio.Types +namespace Twilio.Types { /// /// App Endpoint @@ -17,11 +15,6 @@ public class App : IEndpoint /// App name public App(string app) { - if (string.IsNullOrEmpty(app)) - { - throw new ArgumentException("Parameter 'app' cannot be null or empty.", nameof(app)); - } - if (!app.ToLower().StartsWith(PREFIX)) { app = PREFIX + app; diff --git a/test/Twilio.Test/Types/AppTest.cs b/test/Twilio.Test/Types/AppTest.cs index b798cbc2d..b8ac6ef45 100644 --- a/test/Twilio.Test/Types/AppTest.cs +++ b/test/Twilio.Test/Types/AppTest.cs @@ -1,6 +1,5 @@ using System; using NUnit.Framework; -using Twilio.Exceptions; using Twilio.Types; namespace Twilio.Tests.Types @@ -15,7 +14,6 @@ public void TestToString() Assert.AreEqual("app:YOU", new App("YOU").ToString()); Assert.AreEqual("APP:HIM", new App("APP:HIM").ToString()); Assert.AreEqual("aPp:her", new App("aPp:her").ToString()); - Assert.Throws(() => new App("").ToString()); Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("app:AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString()); Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString()); }