Skip to content
Merged
2 changes: 1 addition & 1 deletion src/Core/Services/RestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ RequestValidator requestValidator
DatabaseObject dbObject = sqlMetadataProvider.EntityToDatabaseObject[entityName];

QueryString? query = GetHttpContext().Request.QueryString;
string queryString = query is null ? string.Empty : GetHttpContext().Request.QueryString.ToString();
string queryString = query is null ? string.Empty : GetHttpContext().Request.QueryString.ToString().Replace("%24", "$"); //Add replacement in order to ensure '$' sign is present as expected
Comment thread
RubenCerna2079 marked this conversation as resolved.
Outdated

// Read the request body early so it can be used for downstream processing.
string requestBody = string.Empty;
Expand Down
36 changes: 36 additions & 0 deletions src/Service.Tests/Configuration/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4224,6 +4224,42 @@ public async Task OpenApi_InteractiveSwaggerUI(
}
}

/// <summary>
/// End to end test that validates that REST requests with OData query
/// options $filter and $orderby succeed to ensure no regression can occur.
/// </summary>
[TestMethod]
[TestCategory(TestCategory.MSSQL)]
public async Task TestForRestRequestsWithFilterAndOrderbyParameters()
{
// The configuration file is constructed by merging hard-coded JSON strings to simulate the scenario where users manually edit the
// configuration file (instead of using CLI).
string configJson = TestHelper.AddPropertiesToJson(TestHelper.BASE_CONFIG, BOOK_ENTITY_JSON);
Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(
configJson,
out RuntimeConfig deserializedConfig,
replacementSettings: new(),
connectionString: GetConnectionStringFromEnvironmentConfig(environment: TestCategory.MSSQL)));
string configFileName = "custom-config.json";
File.WriteAllText(configFileName, deserializedConfig.ToJson());
string[] args = new[]
{
$"--ConfigFileName={configFileName}"
};

using (TestServer server = new(Program.CreateWebHostBuilder(args)))
using (HttpClient client = server.CreateClient())
{
// Act
RuntimeConfigProvider configProvider = server.Services.GetService<RuntimeConfigProvider>();
Comment thread
RubenCerna2079 marked this conversation as resolved.
Outdated
using HttpRequestMessage restRequest = new(HttpMethod.Get, "/api/Book?$orderby=id desc&$filter=publisher_id eq 1234");
Comment thread
RubenCerna2079 marked this conversation as resolved.
Outdated
Comment thread
RubenCerna2079 marked this conversation as resolved.
Outdated
using HttpResponseMessage restResponse = await client.SendAsync(restRequest);

// Assert - Verify REST response
Assert.AreEqual(HttpStatusCode.OK, restResponse.StatusCode, "REST request to auto-generated entity should succeed");
Comment thread
RubenCerna2079 marked this conversation as resolved.
}
}

/// <summary>
/// Test different loglevel values that are avaliable by deserializing RuntimeConfig with specified LogLevel
/// and checks if value exists properly inside the deserialized RuntimeConfig.
Expand Down
Loading