-
Notifications
You must be signed in to change notification settings - Fork 317
chore: added App IEndpoint type #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+65
−0
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ea928aa
chore: added App IEndpoint type
sbansla 14d6ecb
Merge branch 'main' into add-app-endpoint-type
sbansla db5ce65
added null and empty check and added its test cases
sbansla 2f31467
Merge branch 'add-app-endpoint-type' of https://github.com/twilio/twi…
sbansla 8d79ca5
fixed null check
sbansla 21f291a
using argument exception instead of custom exception, keeping excepti…
sbansla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| using System; | ||
|
|
||
| namespace Twilio.Types | ||
| { | ||
| /// <summary> | ||
| /// App Endpoint | ||
| /// </summary> | ||
| public class App : IEndpoint | ||
| { | ||
| public const string PREFIX = "app:"; | ||
|
|
||
| private readonly string _app; | ||
|
|
||
| /// <summary> | ||
| /// Create new app | ||
| /// </summary> | ||
| /// <param name="app">App name</param> | ||
| 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; | ||
| } | ||
|
|
||
| _app = app; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Convert to string | ||
| /// </summary> | ||
| /// <returns>String representation</returns> | ||
| public override string ToString() | ||
| { | ||
| return _app; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using System; | ||
| using NUnit.Framework; | ||
| using Twilio.Exceptions; | ||
| 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.Throws<ArgumentException>(() => 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()); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prefix check uses
app.ToLower().StartsWith(PREFIX)but PREFIX is lowercase 'app:'. This means inputs like 'APP:test' or 'App:test' will incorrectly have the prefix added again, resulting in 'app:APP:test' or 'app:App:test'. Use case-insensitive comparison:!app.StartsWith(PREFIX, StringComparison.OrdinalIgnoreCase)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is working fine, check again.
app= "hello", outcome(_app) = "app:hello"
app= "app:hello", outcome(_app) = "app:hello"
app= "App:hello", outcome(_app) = "App:hello"