Skip to content

Commit b8fcc93

Browse files
committed
Converted EFCoreUpdateDelete to mostly-sync, keeping a single async smoke test for coverage (matching the pattern used elsewhere in the EF Core test project).
1 parent b0ac908 commit b8fcc93

1 file changed

Lines changed: 36 additions & 16 deletions

File tree

SqlServerSimulator.Tests.EFCore/EFCoreUpdateDelete.cs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private static TestDbContext SeededContext()
2929
}
3030

3131
[TestMethod]
32-
public async Task SaveChanges_ModifyExisting_EmitsUpdate()
32+
public void SaveChanges_ModifyExisting_EmitsUpdate()
3333
{
3434
// The most basic real-app workflow: load an entity, change a
3535
// property, save. EF Core emits UPDATE [People] SET [Name] = @p0
@@ -38,7 +38,7 @@ public async Task SaveChanges_ModifyExisting_EmitsUpdate()
3838
using var context = SeededContext();
3939
var alice = context.People.Single(p => p.Name == "alice");
4040
alice.Name = "ALICE";
41-
_ = await context.SaveChangesAsync(this.TestContext.CancellationToken);
41+
_ = context.SaveChanges();
4242

4343
// Read back through a fresh context (different connection) to
4444
// confirm the update persisted at the simulation level, not
@@ -48,14 +48,34 @@ public async Task SaveChanges_ModifyExisting_EmitsUpdate()
4848
Assert.AreEqual("ALICE", reloaded.Name);
4949
}
5050

51+
/// <summary>
52+
/// Mirrors <see cref="SaveChanges_ModifyExisting_EmitsUpdate"/> through
53+
/// the async path. The simulator is fully synchronous, so this exists
54+
/// only to ensure EF Core's default async-over-sync wrapper still works
55+
/// for the UPDATE shape — same role <see cref="EFCoreBasics.InsertRowAsync"/>
56+
/// plays for INSERT.
57+
/// </summary>
58+
[TestMethod]
59+
public async Task SaveChangesAsync_ModifyExisting_AsyncPathSmoke()
60+
{
61+
using var context = SeededContext();
62+
var alice = context.People.Single(p => p.Name == "alice");
63+
alice.Name = "ALICE";
64+
_ = await context.SaveChangesAsync(this.TestContext.CancellationToken);
65+
66+
using var fresh = new TestDbContext(context.Simulation);
67+
var reloaded = fresh.People.Single(p => p.Id == alice.Id);
68+
Assert.AreEqual("ALICE", reloaded.Name);
69+
}
70+
5171
[TestMethod]
52-
public async Task SaveChanges_ModifyMultipleProperties_OneUpdate()
72+
public void SaveChanges_ModifyMultipleProperties_OneUpdate()
5373
{
5474
using var context = SeededContext();
5575
var bob = context.People.Single(p => p.Name == "bob");
5676
bob.Name = "BOB";
5777
bob.Code = "BB";
58-
_ = await context.SaveChangesAsync(this.TestContext.CancellationToken);
78+
_ = context.SaveChanges();
5979

6080
using var fresh = new TestDbContext(context.Simulation);
6181
var reloaded = fresh.People.Single(p => p.Id == bob.Id);
@@ -64,35 +84,35 @@ public async Task SaveChanges_ModifyMultipleProperties_OneUpdate()
6484
}
6585

6686
[TestMethod]
67-
public async Task SaveChanges_RemoveEntity_EmitsDelete()
87+
public void SaveChanges_RemoveEntity_EmitsDelete()
6888
{
6989
using var context = SeededContext();
7090
var carol = context.People.Single(p => p.Name == "carol");
7191
_ = context.People.Remove(carol);
72-
_ = await context.SaveChangesAsync(this.TestContext.CancellationToken);
92+
_ = context.SaveChanges();
7393

7494
using var fresh = new TestDbContext(context.Simulation);
7595
var names = fresh.People.OrderBy(p => p.Id).Select(p => p.Name).ToArray();
7696
CollectionAssert.AreEqual(new[] { "alice", "bob", "dave" }, names);
7797
}
7898

7999
[TestMethod]
80-
public async Task SaveChanges_ModifyAndRemove_BothApplied()
100+
public void SaveChanges_ModifyAndRemove_BothApplied()
81101
{
82102
using var context = SeededContext();
83103
var alice = context.People.Single(p => p.Name == "alice");
84104
alice.Name = "AAA";
85105
var bob = context.People.Single(p => p.Name == "bob");
86106
_ = context.People.Remove(bob);
87-
_ = await context.SaveChangesAsync(this.TestContext.CancellationToken);
107+
_ = context.SaveChanges();
88108

89109
using var fresh = new TestDbContext(context.Simulation);
90110
var rows = fresh.People.OrderBy(p => p.Id).Select(p => p.Name).ToArray();
91111
CollectionAssert.AreEqual(new[] { "AAA", "carol", "dave" }, rows);
92112
}
93113

94114
[TestMethod]
95-
public async Task SaveChanges_ModifyMultipleEntities_BatchedAsSemicolonSeparatedUpdates()
115+
public void SaveChanges_ModifyMultipleEntities_BatchedAsSemicolonSeparatedUpdates()
96116
{
97117
// EF Core 9 emits N semicolon-separated UPDATE statements (one per
98118
// modified entity) on SaveChanges of a multi-entity update — not a
@@ -103,15 +123,15 @@ public async Task SaveChanges_ModifyMultipleEntities_BatchedAsSemicolonSeparated
103123
var people = context.People.OrderBy(p => p.Id).ToList();
104124
foreach (var p in people)
105125
p.Code += "x";
106-
_ = await context.SaveChangesAsync(this.TestContext.CancellationToken);
126+
_ = context.SaveChanges();
107127

108128
using var fresh = new TestDbContext(context.Simulation);
109129
var rows = fresh.People.OrderBy(p => p.Id).Select(p => p.Code).ToArray();
110130
CollectionAssert.AreEqual(new[] { "Ax", "Bx", "Cx", "Dx" }, rows);
111131
}
112132

113133
[TestMethod]
114-
public async Task SaveChanges_ModifyMultipleTimestampedEntities_BatchedUpdatesWithRowVersion()
134+
public void SaveChanges_ModifyMultipleTimestampedEntities_BatchedUpdatesWithRowVersion()
115135
{
116136
// EF Core 9 with [Timestamp] emits N semicolon-separated
117137
// UPDATE [T] SET [c] = @p OUTPUT INSERTED.[RowVersion]
@@ -130,21 +150,21 @@ public async Task SaveChanges_ModifyMultipleTimestampedEntities_BatchedUpdatesWi
130150
new TimestampedItem { Id = 1, Name = "a" },
131151
new TimestampedItem { Id = 2, Name = "b" },
132152
new TimestampedItem { Id = 3, Name = "c" });
133-
_ = await seed.SaveChangesAsync(this.TestContext.CancellationToken);
153+
_ = seed.SaveChanges();
134154

135155
using var ctx = new TimestampedDbContext(simulation);
136156
var items = ctx.Items.OrderBy(i => i.Id).ToList();
137157
foreach (var i in items)
138158
i.Name += "!";
139-
_ = await ctx.SaveChangesAsync(this.TestContext.CancellationToken);
159+
_ = ctx.SaveChanges();
140160

141161
using var fresh = new TimestampedDbContext(simulation);
142162
var names = fresh.Items.OrderBy(i => i.Id).Select(i => i.Name).ToArray();
143163
CollectionAssert.AreEqual(new[] { "a!", "b!", "c!" }, names);
144164
}
145165

146166
[TestMethod]
147-
public async Task SaveChanges_TimestampEntity_ReadsBackAutoBumpedRowVersion()
167+
public void SaveChanges_TimestampEntity_ReadsBackAutoBumpedRowVersion()
148168
{
149169
// EF Core's [Timestamp]-tracked entity emits
150170
// UPDATE [T] SET [Name] = @p0 OUTPUT INSERTED.[RowVersion] WHERE [Id] = @p1 AND [RowVersion] = @p2;
@@ -159,11 +179,11 @@ public async Task SaveChanges_TimestampEntity_ReadsBackAutoBumpedRowVersion()
159179
using var context = new TimestampedDbContext(simulation);
160180
var item = new TimestampedItem { Id = 1, Name = "first" };
161181
_ = context.Items.Add(item);
162-
_ = await context.SaveChangesAsync(this.TestContext.CancellationToken);
182+
_ = context.SaveChanges();
163183
var initialRv = item.RowVersion!.ToArray();
164184

165185
item.Name = "second";
166-
_ = await context.SaveChangesAsync(this.TestContext.CancellationToken);
186+
_ = context.SaveChanges();
167187
var bumpedRv = item.RowVersion!.ToArray();
168188

169189
Assert.IsFalse(initialRv.SequenceEqual(bumpedRv), "rowversion must change after SaveChanges of a modified entity");

0 commit comments

Comments
 (0)