|
9 | 9 | using CommunityToolkit.Datasync.TestCommon.Databases; |
10 | 10 | using Microsoft.EntityFrameworkCore; |
11 | 11 | using System.Net; |
| 12 | +using Microsoft.Data.Sqlite; |
12 | 13 | using TestData = CommunityToolkit.Datasync.TestCommon.TestData; |
13 | 14 |
|
14 | 15 | namespace CommunityToolkit.Datasync.Client.Test.Offline; |
@@ -39,7 +40,7 @@ public void GetEntityMap_Works() |
39 | 40 | public async Task GetExistingOperationAsync_InvalidId_Throws() |
40 | 41 | { |
41 | 42 | ClientMovie movie = new() { Id = "###" }; |
42 | | - Func<Task> act = async () => _ = await queueManager.GetExistingOperationAsync(movie); |
| 43 | + Func<Task> act = async () => _ = await queueManager.GetExistingOperationAsync(context.Entry(movie)); |
43 | 44 | await act.Should().ThrowAsync<DatasyncException>(); |
44 | 45 | } |
45 | 46 | #endregion |
@@ -482,5 +483,29 @@ public async Task LLP_PushAsync_Replacement_Works() |
482 | 483 |
|
483 | 484 | llpContext.DatasyncOperationsQueue.Should().BeEmpty(); |
484 | 485 | } |
| 486 | + |
| 487 | + [Fact] |
| 488 | + public async Task LLP_ModifyAfterInsertInNewContext_NoPush_ShouldUpdateOperationsQueue() |
| 489 | + { |
| 490 | + // Arrange |
| 491 | + await using SqliteConnection connection = CreateAndOpenConnection(); |
| 492 | + string id = Guid.NewGuid().ToString("N"); |
| 493 | + await using (TestDbContext llpContext = CreateContext(connection, x => x.UseLazyLoadingProxies())) |
| 494 | + { |
| 495 | + ClientMovie clientMovie = new(TestData.Movies.BlackPanther) { Id = id }; |
| 496 | + llpContext.Movies.Add(clientMovie); |
| 497 | + llpContext.SaveChanges(); |
| 498 | + } |
| 499 | + |
| 500 | + // Act |
| 501 | + await using TestDbContext newLlpContext = CreateContext(connection, x => x.UseLazyLoadingProxies()); |
| 502 | + |
| 503 | + ClientMovie storedClientMovie = newLlpContext.Movies.First(m => m.Id == id); |
| 504 | + storedClientMovie.Title = TestData.Movies.MovieList[0].Title; |
| 505 | + newLlpContext.SaveChanges(); |
| 506 | + |
| 507 | + // Assert |
| 508 | + newLlpContext.DatasyncOperationsQueue.Should().ContainSingle(op => op.ItemId == id); |
| 509 | + } |
485 | 510 | #endregion |
486 | 511 | } |
0 commit comments