Skip to content

Commit 846d917

Browse files
authored
Simplify no-op commit (#2098)
1 parent 89aa91c commit 846d917

File tree

1 file changed

+9
-35
lines changed

1 file changed

+9
-35
lines changed

backend/FwLite/LcmCrdt.Tests/Data/MigrationTests.cs

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System.Diagnostics.CodeAnalysis;
22
using System.Runtime.CompilerServices;
33
using System.Text.Json;
4-
using LcmCrdt.Changes;
54
using Microsoft.EntityFrameworkCore;
65
using Microsoft.Extensions.DependencyInjection;
76
using Microsoft.Extensions.Options;
8-
using SIL.Harmony.Changes;
97
using SIL.Harmony.Core;
108
using SIL.Harmony.Db;
119

@@ -116,17 +114,13 @@ public async Task VerifyRegeneratedSnapshotsAfterMigrationFromScriptedDb(Regress
116114
await using var dataModel = _helper.Services.GetRequiredService<DataModel>();
117115
var syncable = dataModel as ISyncable;
118116

119-
// slighty hacky way to regenerate snapshots
120-
// could also use dataModel.RegenerateSnapshots(), but that currently has a connection issue
121-
// and it also doesn't support regenerating from a given point in time
122-
var (noOpCommit, noOpEntityId) = NewNoOpCommit(new HybridDateTime(DateTimeOffset.MinValue, 0));
117+
var noOpCommit = FakeCommit.NoOp(new HybridDateTime(DateTimeOffset.MinValue, 0));
123118
await syncable.AddRangeFromSync([noOpCommit]);
124119

125120
var commits = await dbContext.Commits.AsNoTracking().ToArrayAsync();
126121
var commitIdToHybridDateTime = commits.ToDictionary(c => c.Id, c => c.HybridDateTime);
127122

128123
var latestSnapshots = (await dataModel.GetLatestSnapshots()
129-
.Where(s => s.EntityId != noOpEntityId)
130124
.ToArrayAsync())
131125
.OrderBy(s => s.TypeName)
132126
.ThenBy(s => s.EntityId)
@@ -166,37 +160,17 @@ await api.GetComplexFormTypes()
166160
await api.GetWritingSystems());
167161
}
168162

169-
private static (Commit Commit, Guid EntityId) NewNoOpCommit(HybridDateTime hybridDate)
163+
private class FakeCommit : Commit
170164
{
171-
var commitId = Guid.NewGuid();
172-
var entityId = Guid.NewGuid();
173-
return (new FakeCommit(commitId, hybridDate)
165+
public static Commit NoOp(HybridDateTime hybridDateTime)
174166
{
175-
ClientId = Guid.NewGuid(),
176-
ChangeEntities = [
177-
new ChangeEntity<IChange>()
178-
{
179-
Index = 0,
180-
CommitId = commitId,
181-
EntityId = entityId,
182-
Change = new CreateEntryChange(new Entry()
183-
{
184-
Id = entityId,
185-
}),
186-
},
187-
new ChangeEntity<IChange>()
188-
{
189-
Index = 1,
190-
CommitId = commitId,
191-
EntityId = entityId,
192-
Change = new DeleteChange<Entry>(Guid.NewGuid()),
193-
},
194-
],
195-
}, entityId);
196-
}
167+
return new FakeCommit(Guid.NewGuid(), hybridDateTime)
168+
{
169+
ClientId = Guid.NewGuid(),
170+
ChangeEntities = [],
171+
};
172+
}
197173

198-
private class FakeCommit : Commit
199-
{
200174
[SetsRequiredMembers]
201175
public FakeCommit(Guid id, HybridDateTime hybridDateTime) : base(id, "", NullParentHash, hybridDateTime)
202176
{

0 commit comments

Comments
 (0)