Last active
August 8, 2022 13:54
-
-
Save MatthewDavidCampbell/5f392ea1266fe0f55798816758114a63 to your computer and use it in GitHub Desktop.
How a query is executed and headers + request uri are adjusted
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
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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