Skip to content

Commit

Permalink
add some negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Dec 23, 2016
1 parent 313309d commit 64e2b57
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/UriTemplateString/Spec/Operator.cs
Expand Up @@ -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));
}
Expand Down
26 changes: 26 additions & 0 deletions 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<ArgumentException>(() => new UriTemplateString(string.Empty));
}

[Fact]
public void Should_throw_when_created_from_template_with_unclosed_expression()
{
Assert.Throws<ArgumentException>(() => new UriTemplateString("{/unclosed"));
}

[Fact]
public void Should_throw_when_created_from_template_with_unsupported_expression_operator()
{
Assert.Throws<ArgumentException>(() => new UriTemplateString("{'unclosed}"));
}
}
}
26 changes: 26 additions & 0 deletions 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<ArgumentOutOfRangeException>(() => Operator.FromString("_"));
}

[Theory]
[InlineData("=")]
[InlineData(",")]
[InlineData("!")]
[InlineData("@")]
[InlineData("|")]
public void Should_throw_when_constructed_with_operator_reserved_for_future_use(string op)
{
Assert.Throws<NotImplementedException>(() => Operator.FromString(op));
}
}
}
2 changes: 2 additions & 0 deletions test/UriTemplateString.Tests/UriTemplateString.Tests.csproj
Expand Up @@ -46,6 +46,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="InvalidUriTemplateFixture.cs" />
<Compile Include="OperatorFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UriTemplateStringArithmeticsFixture.cs" />
<Compile Include="UriTemplateStringOperatorsFixture.cs" />
Expand Down

0 comments on commit 64e2b57

Please sign in to comment.