Skip to content

Commit

Permalink
tests for appending query string params
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Dec 23, 2016
1 parent 08aeafb commit 313309d
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UriTemplateStringArithmeticsFixture.cs" />
<Compile Include="UriTemplateStringOperatorsFixture.cs" />
<Compile Include="UriTemplateStringTests.cs" />
</ItemGroup>
Expand Down
154 changes: 154 additions & 0 deletions test/UriTemplateString.Tests/UriTemplateStringArithmeticsFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using FluentAssertions;
using Xunit;

namespace UriTemplateString.Tests
{
public class UriTemplateStringArithmeticsFixture
{
[Fact]
public void Can_append_exploded_query_param_to_literal_template()
{
// given
UriTemplateString template = "/some/path";

// when
var newTemplate = template.AppendQueryParam("query", true);

// then
newTemplate.ToString().Should().Be("/some/path{?query*}");
}

[Fact]
public void Can_append_regular_query_param_to_literal_template()
{
// given
UriTemplateString template = "/some/path";

// when
var newTemplate = template.AppendQueryParam("query");

// then
newTemplate.ToString().Should().Be("/some/path{?query}");
}

[Fact]
public void Can_append_exploded_query_param_to_existing_query()
{
// given
UriTemplateString template = "/some/path{?title}";

// when
var newTemplate = template.AppendQueryParam("query", true);

// then
newTemplate.ToString().Should().Be("/some/path{?title,query*}");
}

[Fact]
public void Can_append_regular_query_param_to_existing_query()
{
// given
UriTemplateString template = "/some/path{?title}";

// when
var newTemplate = template.AppendQueryParam("query");

// then
newTemplate.ToString().Should().Be("/some/path{?title,query}");
}

[Fact]
public void Can_append_exploded_query_param_to_template_with_mandatory_query_parameter()
{
// given
UriTemplateString template = "/static/path?required={required}";

// when
var newTemplate = template.AppendQueryParam("query", true);

// then
newTemplate.ToString().Should().Be("/static/path?required={required}{&query*}");
}

[Fact]
public void Can_append_query_param_to_template_with_mandatory_query_parameter()
{
// given
UriTemplateString template = "/static/path?required={required}";

// when
var newTemplate = template.AppendQueryParam("query");

// then
newTemplate.ToString().Should().Be("/static/path?required={required}{&query}");
}

[Fact]
public void Can_append_exploded_query_param_to_template_with_query_continuation()
{
// given
UriTemplateString template = "/static/path?required={required}{&opt}";

// when
var newTemplate = template.AppendQueryParam("query", true);

// then
newTemplate.ToString().Should().Be("/static/path?required={required}{&opt,query*}");
}

[Fact]
public void Can_append_query_param_to_template_with_query_continuation()
{
// given
UriTemplateString template = "/static/path?required={required}{&opt}";

// when
var newTemplate = template.AppendQueryParam("query");

// then
newTemplate.ToString().Should().Be("/static/path?required={required}{&opt,query}");
}

[Theory]
[InlineData("/static/path{/more,path}", "/static/path{/more,path}{?params*}")]
[InlineData("/static/path/{more,path}", "/static/path/{more,path}{?params*}")]
[InlineData("/static/path/{path,explode*}", "/static/path/{path,explode*}{?params*}")]
[InlineData("/static/path{/path,explode*}", "/static/path{/path,explode*}{?params*}")]
[InlineData("/static/path{/path}{;path_params}", "/static/path{/path}{;path_params}{?params*}")]
[InlineData("/static/path{/path}{;path_params*}", "/static/path{/path}{;path_params*}{?params*}")]
public void Can_append_exploded_query_param_to_template_ending_with_non_query_expression(
string templateBefore,
string templateAfter)
{
// given
UriTemplateString template = templateBefore;

// when
var newTemplate = template.AppendQueryParam("params", true);

// then
newTemplate.ToString().Should().Be(templateAfter);
}

[Theory]
[InlineData("/static/path{/more,path}", "/static/path{/more,path}{?params}")]
[InlineData("/static/path/{more,path}", "/static/path/{more,path}{?params}")]
[InlineData("/static/path/{path,explode*}", "/static/path/{path,explode*}{?params}")]
[InlineData("/static/path{/path,explode*}", "/static/path{/path,explode*}{?params}")]
[InlineData("/static/path{/path}{;path_params}", "/static/path{/path}{;path_params}{?params}")]
[InlineData("/static/path{/path}{;path_params*}", "/static/path{/path}{;path_params*}{?params}")]
public void Can_append_regular_query_param_to_template_ending_with_non_query_expression(
string templateBefore,
string templateAfter)
{
// given
UriTemplateString template = templateBefore;

// when
var newTemplate = template.AppendQueryParam("params");

// then
newTemplate.ToString().Should().Be(templateAfter);
}
}
}

0 comments on commit 313309d

Please sign in to comment.