diff --git a/src/UriTemplateString/Spec/Operator.cs b/src/UriTemplateString/Spec/Operator.cs index 4f17636..a67bd30 100644 --- a/src/UriTemplateString/Spec/Operator.cs +++ b/src/UriTemplateString/Spec/Operator.cs @@ -79,6 +79,12 @@ public static Operator FromString(string operatorCharacter) return Operator.PathParameter; case "&": return Operator.QueryContinuation; + case "!": + case "=": + case ",": + case "@": + case "|": + throw new NotImplementedException($"The operator character {operatorCharacter} is reserved for future extensions and not currently supported"); default: throw new ArgumentOutOfRangeException(nameof(operatorCharacter)); } diff --git a/test/UriTemplateString.Tests/InvalidUriTemplateFixture.cs b/test/UriTemplateString.Tests/InvalidUriTemplateFixture.cs new file mode 100644 index 0000000..c0f17d1 --- /dev/null +++ b/test/UriTemplateString.Tests/InvalidUriTemplateFixture.cs @@ -0,0 +1,26 @@ +using System; +using Xunit; + +namespace UriTemplateString.Tests +{ + public class InvalidUriTemplateFixture + { + [Fact] + public void Should_throw_when_created_from_empty_string() + { + Assert.Throws(() => new UriTemplateString(string.Empty)); + } + + [Fact] + public void Should_throw_when_created_from_template_with_unclosed_expression() + { + Assert.Throws(() => new UriTemplateString("{/unclosed")); + } + + [Fact] + public void Should_throw_when_created_from_template_with_unsupported_expression_operator() + { + Assert.Throws(() => new UriTemplateString("{'unclosed}")); + } + } +} \ No newline at end of file diff --git a/test/UriTemplateString.Tests/OperatorFixture.cs b/test/UriTemplateString.Tests/OperatorFixture.cs new file mode 100644 index 0000000..5182cfe --- /dev/null +++ b/test/UriTemplateString.Tests/OperatorFixture.cs @@ -0,0 +1,26 @@ +using System; +using UriTemplateString.Spec; +using Xunit; + +namespace UriTemplateString.Tests +{ + public class OperatorFixture + { + [Fact] + public void Should_throw_when_constructed_with_unsupported_operator_character() + { + Assert.Throws(() => Operator.FromString("_")); + } + + [Theory] + [InlineData("=")] + [InlineData(",")] + [InlineData("!")] + [InlineData("@")] + [InlineData("|")] + public void Should_throw_when_constructed_with_operator_reserved_for_future_use(string op) + { + Assert.Throws(() => Operator.FromString(op)); + } + } +} \ No newline at end of file diff --git a/test/UriTemplateString.Tests/UriTemplateString.Tests.csproj b/test/UriTemplateString.Tests/UriTemplateString.Tests.csproj index 09ccc55..21b8cae 100644 --- a/test/UriTemplateString.Tests/UriTemplateString.Tests.csproj +++ b/test/UriTemplateString.Tests/UriTemplateString.Tests.csproj @@ -46,6 +46,8 @@ + +