-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
ReloadTest.cs
73 lines (57 loc) · 2.05 KB
/
ReloadTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
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 = await context.AddAsync(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; }
}
}