-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from aspriddell/query-collections
Implement collection support for forms and queries
- Loading branch information
Showing
8 changed files
with
206 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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,49 @@ | ||
// DragonFruit.Common Copyright 2020 DragonFruit Network | ||
// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details | ||
|
||
using System.Linq; | ||
using DragonFruit.Common.Data.Parameters; | ||
using NUnit.Framework; | ||
|
||
namespace DragonFruit.Common.Data.Tests | ||
{ | ||
[TestFixture] | ||
public class QueryCompilationTests | ||
{ | ||
[TestCase] | ||
public void TestQueries() | ||
{ | ||
var query = new TestRequest().FullUrl.Split('?').Last().Split('&'); | ||
|
||
for (int i = 0; i < TestRequest.TestDataset.Length; i++) | ||
{ | ||
var testString = TestRequest.TestDataset[i]; | ||
Assert.IsTrue(query.Contains($"{TestRequest.QueryName}={testString}")); | ||
Assert.IsTrue(query.Contains($"{TestRequest.QueryName}[]={testString}")); | ||
Assert.IsTrue(query.Contains($"{TestRequest.QueryName}[{i}]={testString}")); | ||
} | ||
|
||
Assert.IsTrue(query.Contains($"{TestRequest.QueryName}={string.Join(":", TestRequest.TestDataset)}")); | ||
} | ||
} | ||
|
||
internal class TestRequest : ApiRequest | ||
{ | ||
internal const string QueryName = "data"; | ||
internal static readonly string[] TestDataset = { "a", "b", "c" }; | ||
|
||
public override string Path => "http://example.com"; | ||
|
||
[QueryParameter(QueryName, CollectionConversionMode.Recursive)] | ||
public string[] RecursiveData { get; set; } = TestDataset; | ||
|
||
[QueryParameter(QueryName, CollectionConversionMode.Ordered)] | ||
public string[] OrderedData { get; set; } = TestDataset; | ||
|
||
[QueryParameter(QueryName, CollectionConversionMode.Unordered)] | ||
public string[] UnorderedData { get; set; } = TestDataset; | ||
|
||
[QueryParameter(QueryName, CollectionConversionMode.Concatenated, CollectionSeparator = ":")] | ||
public string[] ConcatenatedData { get; set; } = TestDataset; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,10 +1,16 @@ | ||
// DragonFruit.Common Copyright 2020 DragonFruit Network | ||
// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details | ||
|
||
#nullable enable | ||
|
||
namespace DragonFruit.Common.Data.Parameters | ||
{ | ||
public interface IProperty | ||
{ | ||
string Name { get; } | ||
string? Name { get; set; } | ||
|
||
CollectionConversionMode? CollectionHandling { get; set; } | ||
|
||
string? CollectionSeparator { get; set; } | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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