Skip to content

Commit b631f14

Browse files
committed
Refactor Jet concurrency tests for List<byte> row versions
Refactored F1JetFixture to use a custom value converter and comparer for List<byte> as row version. Extended OptimisticConcurrencyJetTest to cover TPH, TPT, and TPC mappings with List<byte> row versions. Removed F1ULongJetFixture and improved test clarity and coverage for custom concurrency token types.
1 parent 1ab5734 commit b631f14

2 files changed

Lines changed: 390 additions & 309 deletions

File tree

test/EFCore.Jet.FunctionalTests/F1JetFixture.cs

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,109 @@
22

33
using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities;
44
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.ChangeTracking;
6+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
57
using Microsoft.EntityFrameworkCore.TestModels.ConcurrencyModel;
68
using Microsoft.EntityFrameworkCore.TestUtilities;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.ComponentModel.DataAnnotations;
12+
using System.Linq;
13+
14+
#nullable disable
715

816
namespace EntityFrameworkCore.Jet.FunctionalTests
917
{
10-
public class F1ULongJetFixture : F1JetFixtureBase<ulong>
11-
{
12-
}
13-
1418
public class F1JetFixture : F1JetFixtureBase<byte[]>
1519
{
20+
protected override void BuildModelExternal(ModelBuilder modelBuilder)
21+
{
22+
base.BuildModelExternal(modelBuilder);
23+
24+
var converter = new BinaryVersionConverter();
25+
var comparer = new BinaryVersionComparer();
26+
27+
modelBuilder
28+
.Entity<Fan>()
29+
.Property(e => e.BinaryVersion)
30+
.HasConversion(converter, comparer)
31+
.IsRowVersion();
32+
33+
modelBuilder
34+
.Entity<FanTpt>()
35+
.Property(e => e.BinaryVersion)
36+
.HasConversion(converter, comparer)
37+
.IsRowVersion();
38+
39+
modelBuilder
40+
.Entity<FanTpc>()
41+
.Property(e => e.BinaryVersion)
42+
.HasConversion(converter, comparer)
43+
.IsRowVersion();
44+
45+
modelBuilder
46+
.Entity<Circuit>()
47+
.Property(e => e.BinaryVersion)
48+
.HasConversion(converter, comparer)
49+
.IsRowVersion();
50+
51+
modelBuilder
52+
.Entity<CircuitTpt>()
53+
.Property(e => e.BinaryVersion)
54+
.HasConversion(converter, comparer)
55+
.IsRowVersion();
56+
57+
modelBuilder
58+
.Entity<CircuitTpc>()
59+
.Property(e => e.BinaryVersion)
60+
.HasConversion(converter, comparer)
61+
.IsRowVersion();
62+
}
63+
64+
private class BinaryVersionConverter() : ValueConverter<List<byte>, byte[]>(
65+
v => v == null ? null : v.ToArray(),
66+
v => v == null ? null : v.ToList());
67+
68+
private class BinaryVersionComparer() : ValueComparer<List<byte>>(
69+
(l, r) => (l == null && r == null) || (l != null && r != null && l.SequenceEqual(r)),
70+
v => CalculateHashCode(v),
71+
v => v == null ? null : v.ToList())
72+
{
73+
private static int CalculateHashCode(List<byte> source)
74+
{
75+
if (source == null)
76+
{
77+
return 0;
78+
}
79+
80+
var hash = new HashCode();
81+
foreach (var el in source)
82+
{
83+
hash.Add(el);
84+
}
85+
86+
return hash.ToHashCode();
87+
}
88+
}
1689
}
1790

1891
public abstract class F1JetFixtureBase<TRowVersion> : F1RelationalFixture<TRowVersion>
1992
{
20-
protected override ITestStoreFactory TestStoreFactory => JetTestStoreFactory.Instance;
21-
93+
protected override ITestStoreFactory TestStoreFactory
94+
=> JetTestStoreFactory.Instance;
95+
2296
public override TestHelpers TestHelpers
2397
=> JetTestHelpers.Instance;
2498

2599
protected override void BuildModelExternal(ModelBuilder modelBuilder)
26100
{
27101
base.BuildModelExternal(modelBuilder);
28102

29-
modelBuilder.Entity<Chassis>().Property<byte[]>("Version").IsRowVersion();
30-
modelBuilder.Entity<Driver>().Property<byte[]>("Version").IsRowVersion();
31-
32-
modelBuilder.Entity<Team>().Property<byte[]>("Version")
33-
.ValueGeneratedOnAddOrUpdate()
34-
.IsConcurrencyToken();
35-
36-
modelBuilder.Entity<Sponsor>(
37-
eb =>
38-
{
39-
eb.Property<byte[]>("Version").IsRowVersion().HasColumnName("Version");
40-
eb.Property<int?>(Sponsor.ClientTokenPropertyName).HasColumnName(Sponsor.ClientTokenPropertyName);
41-
});
42103
modelBuilder.Entity<TitleSponsor>()
43104
.OwnsOne(
44105
s => s.Details, eb =>
45106
{
46107
eb.Property(d => d.Space).HasColumnType("decimal(18,2)");
47-
eb.Property<byte[]>("Version").IsRowVersion().HasColumnName("Version");
48-
eb.Property<int?>(Sponsor.ClientTokenPropertyName).IsConcurrencyToken()
49-
.HasColumnName(Sponsor.ClientTokenPropertyName);
50108
});
51109
}
52110
}

0 commit comments

Comments
 (0)