-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #18710
- Loading branch information
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore.TestUtilities; | ||
using Xunit; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Cosmos | ||
{ | ||
public class ReloadTest | ||
{ | ||
public static IEnumerable<object[]> IsAsyncData = new[] | ||
{ | ||
new object[] { true }, | ||
new object[] { false } | ||
}; | ||
|
||
[ConditionalTheory] | ||
[MemberData(nameof(IsAsyncData))] | ||
public async Task Entity_reference_can_be_reloaded(bool async) | ||
{ | ||
await using var testDatabase = CosmosTestStore.CreateInitialized("ReloadTest"); | ||
|
||
using var context = new ReloadTestContext(testDatabase); | ||
await context.Database.EnsureCreatedAsync(); | ||
|
||
var entry = context.Add(new Item { Id = 1337 }); | ||
|
||
await context.SaveChangesAsync(); | ||
|
||
var itemJson = entry.Property<JObject>("__jObject").CurrentValue; | ||
itemJson["unmapped"] = 2; | ||
|
||
if (async) | ||
{ | ||
await entry.ReloadAsync(); | ||
} | ||
else | ||
{ | ||
entry.Reload(); | ||
} | ||
|
||
itemJson = entry.Property<JObject>("__jObject").CurrentValue; | ||
Assert.Null(itemJson["unmapped"]); | ||
} | ||
|
||
public class ReloadTestContext : DbContext | ||
{ | ||
private readonly string _connectionUri; | ||
private readonly string _authToken; | ||
private readonly string _name; | ||
|
||
public ReloadTestContext(CosmosTestStore testStore) | ||
{ | ||
_connectionUri = testStore.ConnectionUri; | ||
_authToken = testStore.AuthToken; | ||
_name = testStore.Name; | ||
} | ||
|
||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
optionsBuilder | ||
.UseCosmos( | ||
_connectionUri, | ||
_authToken, | ||
_name, | ||
b => b.ApplyConfiguration()); | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
} | ||
|
||
public DbSet<Item> Items { get; set; } | ||
} | ||
|
||
public class Item | ||
{ | ||
public int Id { get; set; } | ||
} | ||
} | ||
} |