Skip to content

Instantly share code, notes, and snippets.

@MatthewDavidCampbell
Last active August 8, 2022 13:54
Show Gist options
  • Save MatthewDavidCampbell/5f392ea1266fe0f55798816758114a63 to your computer and use it in GitHub Desktop.
Save MatthewDavidCampbell/5f392ea1266fe0f55798816758114a63 to your computer and use it in GitHub Desktop.
How a query is executed and headers + request uri are adjusted
using Microsoft.OData.Client;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
namespace Biometria.Discovery.OData.Test
{
public static class Extensions
{
private const int DeltaMilliseconds = 100;
public static void EnqueueTestComplete(this AzureSearchContextTests test)
{
test.IsCompleted = true;
}
public static void WaitForTestToComplete(this AzureSearchContextTests test)
{
while (!test.IsCompleted)
{
Sleep(DeltaMilliseconds);
}
}
private static void Sleep(int milliseconds)
{
Task.Delay(milliseconds).Wait();
}
}
public class AzureSearchContextTests
{
public bool IsCompleted = false;
[Fact]
public void When_FindActors_ItShould_ReturnSingle()
{
// Arrange
AzureSearchContext searchable = new AzureSearchContext("https://(service address)/indexes");
// Act + Assert
var query = searchable
.Actors
// Use!!!! AddQueryOption("api-version", "2021-04-30-Preview")
.Where(entity => entity.Identitet == "00043-00000") as DataServiceQuery<Actor>;
query.BeginExecute(
(callback) =>
{
var howMany = query.EndExecute(callback).Count();
Assert.Equal(1, howMany);
this.EnqueueTestComplete();
},
default!
);
this.WaitForTestToComplete();
}
}
}
@MatthewDavidCampbell
Copy link
Author

MatthewDavidCampbell commented Aug 8, 2022

Microsoft.OData.Client.DataServiceQueryException : An error occurred while processing this request.
---- Microsoft.OData.Client.DataServiceClientException : {"error":{"code":"","message":"Invalid or missing api-version query string parameter."}}
-------- Microsoft.OData.ODataErrorException : An error was read from the payload. See the 'Error' property for more details.

@MatthewDavidCampbell
Copy link
Author

var query = searchable .Actors .AddQueryOption("api-version", "2021-04-30-Preview") .Where(entity => entity.Identitet == "00043-00000") as DataServiceQuery<Actor>;

Using AddQueryOption passes along the api-version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment