Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public async Task GetTokenAsync_CallsOnFirstRun()
{
int count = 0;
GenericAuthenticationProvider sut = new(_ => { count++; return Task.FromResult(ValidAuthenticationToken); });
string actual = await sut.GetTokenAsync();
string actual = await sut.GetTokenAsync(cancellationToken: TestContext.Current.CancellationToken);
actual.Should().Be(ValidAuthenticationToken.Token);
count.Should().Be(1);
}
Expand All @@ -216,8 +216,8 @@ public async Task GetTokenAsync_CachesResult()
{
int count = 0;
GenericAuthenticationProvider sut = new(_ => { count++; return Task.FromResult(ValidAuthenticationToken); });
string firstCall = await sut.GetTokenAsync();
string secondCall = await sut.GetTokenAsync();
string firstCall = await sut.GetTokenAsync(cancellationToken: TestContext.Current.CancellationToken);
string secondCall = await sut.GetTokenAsync(cancellationToken: TestContext.Current.CancellationToken);
firstCall.Should().Be(ValidAuthenticationToken.Token);
secondCall.Should().Be(ValidAuthenticationToken.Token);
count.Should().Be(1);
Expand All @@ -228,9 +228,9 @@ public async Task GetTokenAsync_CallsOnForce()
{
int count = 0;
GenericAuthenticationProvider sut = new(_ => { count++; return Task.FromResult(ValidAuthenticationToken); });
string firstCall = await sut.GetTokenAsync();
string firstCall = await sut.GetTokenAsync(cancellationToken: TestContext.Current.CancellationToken);
firstCall.Should().Be(ValidAuthenticationToken.Token);
string secondCall = await sut.GetTokenAsync(true);
string secondCall = await sut.GetTokenAsync(true, TestContext.Current.CancellationToken);
secondCall.Should().Be(ValidAuthenticationToken.Token);
count.Should().Be(2);
}
Expand All @@ -239,14 +239,14 @@ public async Task GetTokenAsync_CallsOnForce()
public async Task GetTokenAsync_LogsOutWhenExpired()
{
GenericAuthenticationProvider sut = new(_ => Task.FromResult(ValidAuthenticationToken));
string firstCall = await sut.GetTokenAsync();
string firstCall = await sut.GetTokenAsync(cancellationToken: TestContext.Current.CancellationToken);
firstCall.Should().Be(ValidAuthenticationToken.Token);
sut.DisplayName.Should().Be(ValidAuthenticationToken.DisplayName);
sut.UserId.Should().Be(ValidAuthenticationToken.UserId);
sut.IsLoggedIn.Should().BeTrue();

sut.TokenRequestorAsync = _ => Task.FromResult(ExpiredAuthenticationToken);
string secondCall = await sut.GetTokenAsync(true);
string secondCall = await sut.GetTokenAsync(true, TestContext.Current.CancellationToken);
secondCall.Should().BeNull();
sut.DisplayName.Should().BeNull();
sut.UserId.Should().BeNull();
Expand All @@ -258,7 +258,7 @@ public async Task LoginAsync_CallsTokenRequestor()
{
int count = 0;
GenericAuthenticationProvider sut = new(_ => { count++; return Task.FromResult(ValidAuthenticationToken); });
await sut.LoginAsync();
await sut.LoginAsync(TestContext.Current.CancellationToken);
count.Should().Be(1);
}

Expand All @@ -267,9 +267,9 @@ public async Task LoginAsync_ForcesTokenRequestor()
{
int count = 0;
GenericAuthenticationProvider sut = new(_ => { count++; return Task.FromResult(ValidAuthenticationToken); });
string firstCall = await sut.GetTokenAsync();
string firstCall = await sut.GetTokenAsync(cancellationToken: TestContext.Current.CancellationToken);
firstCall.Should().Be(ValidAuthenticationToken.Token);
await sut.LoginAsync();
await sut.LoginAsync(TestContext.Current.CancellationToken);
count.Should().Be(2);
}

Expand All @@ -284,7 +284,7 @@ public async Task SendAsync_AddsHeader_BearerAuth()
InnerHandler = handler
};

HttpResponseMessage response = await sut.WrappedSendAsync(request);
HttpResponseMessage response = await sut.WrappedSendAsync(request, TestContext.Current.CancellationToken);

response.Should().NotBeNull();

Expand All @@ -303,7 +303,7 @@ public async Task SendAsync_NoHeader_WhenExpired()
InnerHandler = handler
};

HttpResponseMessage response = await sut.WrappedSendAsync(request);
HttpResponseMessage response = await sut.WrappedSendAsync(request, TestContext.Current.CancellationToken);

response.Should().NotBeNull();

Expand All @@ -323,7 +323,7 @@ public async Task SendAsync_RemoveHeader_WhenExpired()
InnerHandler = handler
};

HttpResponseMessage response = await sut.WrappedSendAsync(request);
HttpResponseMessage response = await sut.WrappedSendAsync(request, TestContext.Current.CancellationToken);

response.Should().NotBeNull();

Expand All @@ -343,7 +343,7 @@ public async Task SendAsync_OverwritesHeader_WhenNotExpired()
InnerHandler = handler
};

HttpResponseMessage response = await sut.WrappedSendAsync(request);
HttpResponseMessage response = await sut.WrappedSendAsync(request, TestContext.Current.CancellationToken);

response.Should().NotBeNull();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task ClientWinsConflictResolver_ShouldReturnClientObject()
};

// Act
var resolution = await clientResolver.ResolveConflictAsync(clientObject, serverObject);
var resolution = await clientResolver.ResolveConflictAsync(clientObject, serverObject, TestContext.Current.CancellationToken);

// Assert
resolution.Result.Should().Be(ConflictResolutionResult.Client);
Expand All @@ -53,7 +53,7 @@ public async Task ServerWinsConflictResolver_ShouldReturnServerObject()
};

// Act
var resolution = await serverResolver.ResolveConflictAsync(clientObject, serverObject);
var resolution = await serverResolver.ResolveConflictAsync(clientObject, serverObject, TestContext.Current.CancellationToken);

// Assert
resolution.Result.Should().Be(ConflictResolutionResult.Server);
Expand All @@ -68,7 +68,7 @@ public async Task ClientWinsConflictResolver_ShouldReturnClientObject_WithNullSe
var clientObject = new ClientMovie(TestData.Movies.BlackPanther) { Id = "test-id" };

// Act
var resolution = await clientResolver.ResolveConflictAsync(clientObject, null);
var resolution = await clientResolver.ResolveConflictAsync(clientObject, null, TestContext.Current.CancellationToken);

// Assert
resolution.Result.Should().Be(ConflictResolutionResult.Client);
Expand All @@ -87,7 +87,7 @@ public async Task ServerWinsConflictResolver_ShouldReturnServerObject_WithNullCl
};

// Act
var resolution = await serverResolver.ResolveConflictAsync(null, serverObject);
var resolution = await serverResolver.ResolveConflictAsync(null, serverObject, TestContext.Current.CancellationToken);

// Assert
resolution.Result.Should().Be(ConflictResolutionResult.Server);
Expand All @@ -112,7 +112,7 @@ public async Task GenericConflictResolver_ShouldResolveTypedConflict()
};

// Act
var resolution = await resolver.ResolveConflictAsync(clientObject, serverObject);
var resolution = await resolver.ResolveConflictAsync(clientObject, serverObject, TestContext.Current.CancellationToken);

// Assert
resolution.Result.Should().Be(ConflictResolutionResult.Client);
Expand All @@ -136,7 +136,7 @@ public async Task GenericConflictResolver_ObjectMethod_ShouldCallTypedMethod()
};

// Act
var resolution = await resolver.ResolveConflictAsync((object)clientObject, (object)serverObject);
var resolution = await resolver.ResolveConflictAsync((object)clientObject, (object)serverObject, TestContext.Current.CancellationToken);

// Assert
resolution.Result.Should().Be(ConflictResolutionResult.Client);
Expand All @@ -154,7 +154,7 @@ public async Task GenericConflictResolver_BothNull_ShouldReturnDefault()
var resolver = new TestGenericConflictResolver();

// Act
var resolution = await resolver.ResolveConflictAsync(null, null);
var resolution = await resolver.ResolveConflictAsync(null, null, TestContext.Current.CancellationToken);

// Assert
resolution.Result.Should().Be(ConflictResolutionResult.Default);
Expand Down Expand Up @@ -216,7 +216,7 @@ public async Task PushAsync_WithDefaultClientWinsResolver_ShouldResolveConflictA
context.Handler.AddResponseContent(finalJson, HttpStatusCode.OK);

// Act
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions());
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions(), TestContext.Current.CancellationToken);

// Assert
result.IsSuccessful.Should().BeTrue();
Expand Down Expand Up @@ -281,7 +281,7 @@ public async Task PushAsync_WithClientWinsResolver_ShouldResolveConflictAndRetry
context.Handler.AddResponseContent(finalJson, HttpStatusCode.OK);

// Act
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions());
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions(), TestContext.Current.CancellationToken);

// Assert
result.IsSuccessful.Should().BeTrue();
Expand Down Expand Up @@ -339,7 +339,7 @@ public async Task PushAsync_WithServerWinsResolver_ShouldResolveConflictAndRetry
context.Handler.AddResponseContent(finalJson, HttpStatusCode.OK);

// Act
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions());
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions(), TestContext.Current.CancellationToken);

// Assert
result.IsSuccessful.Should().BeTrue();
Expand Down Expand Up @@ -400,7 +400,7 @@ public async Task PushAsync_WithCustomResolver_ShouldResolveConflictAndRetry()
context.Handler.AddResponseContent(finalJson, HttpStatusCode.OK);

// Act
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions());
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions(), TestContext.Current.CancellationToken);

// Assert
result.IsSuccessful.Should().BeTrue();
Expand Down Expand Up @@ -459,7 +459,7 @@ public async Task PushAsync_WithPreconditionFailed_ShouldResolveConflict()
context.Handler.AddResponseContent(finalJson, HttpStatusCode.OK);

// Act
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions());
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions(), TestContext.Current.CancellationToken);

// Assert
result.IsSuccessful.Should().BeTrue();
Expand Down Expand Up @@ -513,7 +513,7 @@ public async Task PushAsync_WithDeleteOperation_AndConflict_ShouldResolveConflic
context.Handler.AddResponse(HttpStatusCode.NoContent);

// Act
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions());
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions(), TestContext.Current.CancellationToken);

// Assert
result.IsSuccessful.Should().BeTrue();
Expand Down Expand Up @@ -556,7 +556,7 @@ public async Task PushAsync_WithDeleteOperation_AndConflict_ServerWinsResolver_S
context.Handler.AddResponse(HttpStatusCode.NoContent);

// Act
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions());
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions(), TestContext.Current.CancellationToken);

// Assert
result.IsSuccessful.Should().BeTrue();
Expand Down Expand Up @@ -596,7 +596,7 @@ public async Task PushAsync_WithReplaceOperation_AndConflict_ShouldResolveConfli
context.Handler.AddResponseContent(DatasyncSerializer.Serialize(serverMovie), HttpStatusCode.Conflict);

// Act
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions());
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions(), TestContext.Current.CancellationToken);

// Assert
result.IsSuccessful.Should().BeTrue();
Expand Down Expand Up @@ -637,7 +637,7 @@ public async Task PushAsync_WithNull_ConflictResolver_ShouldNotResolveConflict()
context.Handler.AddResponseContent(serverJson, HttpStatusCode.Conflict);

// Act
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions());
var result = await context.QueueManager.PushAsync([typeof(ClientMovie)], new PushOptions(), TestContext.Current.CancellationToken);

// Assert
result.IsSuccessful.Should().BeFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DefaultDeltaTokenStore_Tests : BaseTest
[Fact]
public async Task GetDeltaTokenAsync_ReturnsMinValueWhenMissing()
{
DateTimeOffset actual = await DeltaTokenStore.GetDeltaTokenAsync("abc");
DateTimeOffset actual = await DeltaTokenStore.GetDeltaTokenAsync("abc", TestContext.Current.CancellationToken);
actual.ToUnixTimeMilliseconds().Should().Be(0);
}

Expand All @@ -28,7 +28,7 @@ public async Task GetDeltaTokenAsync_ReturnsValueWhenPresent()
DateTimeOffset expected = DateTimeOffset.UtcNow;
this.context.DatasyncDeltaTokens.Add(new DatasyncDeltaToken() { Id = "abc", Value = expected.ToUnixTimeMilliseconds() });
this.context.SaveChanges();
DateTimeOffset actual = await DeltaTokenStore.GetDeltaTokenAsync("abc");
DateTimeOffset actual = await DeltaTokenStore.GetDeltaTokenAsync("abc", TestContext.Current.CancellationToken);
actual.ToUnixTimeMilliseconds().Should().Be(expected.ToUnixTimeMilliseconds());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,31 @@ await context.DynamicProxiesEntities1.AddAsync(new DynamicProxiesEntity1
Name = $"Test {DateTime.Now}",
LocalNotes = "These notes should not be serialized into DatasyncOperationsQueue",
RelatedEntity = new() { Id = Guid.NewGuid().ToString() }
});
await context.SaveChangesAsync();
}, TestContext.Current.CancellationToken);
await context.SaveChangesAsync(TestContext.Current.CancellationToken);
}

await using (DynamicProxiesTestContext context = new(dbContextOptions))
{
DatasyncOperation operationAfterInsert = await context.DatasyncOperationsQueue.FirstAsync(o => o.ItemId == key);
DatasyncOperation operationAfterInsert = await context.DatasyncOperationsQueue.FirstAsync(o => o.ItemId == key, TestContext.Current.CancellationToken);
operationAfterInsert.EntityType.Should().EndWith("DynamicProxiesEntity1");
operationAfterInsert.Version.Should().Be(0);

// The LocalNotes should not be included
operationAfterInsert.Item.Should().NotContain("\"localNotes\":");

// Update the entity within the DbContext
DynamicProxiesEntity1 entity = await context.DynamicProxiesEntities1.FirstAsync(e => e.Id == key);
DynamicProxiesEntity1 entity = await context.DynamicProxiesEntities1.FirstAsync(e => e.Id == key, TestContext.Current.CancellationToken);
string updatedName = $"Updated name {DateTime.Now}";
entity.Name = updatedName;
await context.SaveChangesAsync();
await context.SaveChangesAsync(TestContext.Current.CancellationToken);

// There should be 1 operation.
int operationsWithItemId = await context.DatasyncOperationsQueue.CountAsync(o => o.ItemId == key);
int operationsWithItemId = await context.DatasyncOperationsQueue.CountAsync(o => o.ItemId == key, TestContext.Current.CancellationToken);
operationsWithItemId.Should().Be(1);

// Here is the operation after edit.
DatasyncOperation operationAfterEdit = await context.DatasyncOperationsQueue.FirstAsync(o => o.ItemId == key);
DatasyncOperation operationAfterEdit = await context.DatasyncOperationsQueue.FirstAsync(o => o.ItemId == key, TestContext.Current.CancellationToken);
operationAfterEdit.EntityType.Should().EndWith("DynamicProxiesEntity1");
operationAfterEdit.Version.Should().Be(1);
operationAfterEdit.Item.Should().Contain($"\"name\":\"{updatedName}\"");
Expand Down
Loading