I have been looking a ways to build a query in .NET Core Web API and I have discovered the Querybuilder in Microsoft.AspNetCore.Http.Extensions
Its not clear to me how to use it.
[Fact]
public void ThisTestFailsWithQueryBuilder()
{
string baseUri = "http://localhost:13493/api/employees";
string expected = "http://localhost:13493/api/employees/1?Role=Salesman";
var kvps = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("id", "1"),
new KeyValuePair<string, string>("role", "Salesman"),
};
var query = new QueryBuilder(kvps).ToQueryString();
var finalQuery = baseUri + query;
Assert.Equal(expected,finalQuery);
}
[Fact]
public void ThisIsSUCCESSNotUsingQueryBuilder()
{
string baseUri = "http://localhost:13493/api/employees";
string expected = "http://localhost:13493/api/employees/1?Role=Salesman";
string id = "1";
string role = "Salesman";
string partialQueryString = $"/{id}?Role={role}";
string query = baseUri + partialQueryString;
Assert.Equal(expected,query);
}
How can I modify my failing test so that the one using QueryBuilder works?