-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
117 additions
and
20 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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
// SPDX-FileCopyrightText: 2024 Frans van Dorsselaer | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
namespace UnitTests; | ||
|
||
sealed class MemoryDbContext : DbContext | ||
{ | ||
public const string TestTableName = "TestTable"; | ||
public const string IdName = "Id"; | ||
public const string RowVersionName = "RowVersion"; | ||
|
||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
optionsBuilder | ||
.UseSqlite("DataSource=:memory:") | ||
.UseSqliteTimestamp() | ||
.LogTo(Console.WriteLine); | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity(TestTableName, b => | ||
{ | ||
b.Property<long>(IdName) | ||
.ValueGeneratedOnAdd(); | ||
b.Property<byte[]>(RowVersionName) | ||
.IsRowVersion(); | ||
b.HasKey(IdName); | ||
}); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
UnitTests/SqliteTimestampDbContextOptionsBuilderExtensions_Tests.cs
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,24 @@ | ||
// SPDX-FileCopyrightText: 2024 Frans van Dorsselaer | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
namespace UnitTests; | ||
|
||
[TestClass] | ||
sealed class SqliteTimestampDbContextOptionsBuilderExtensions_Tests | ||
{ | ||
sealed class TestDbContext : DbContext | ||
{ | ||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
optionsBuilder | ||
.UseSqliteTimestamp(); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void UseSqliteTimestamp() | ||
{ | ||
using var db = new TestDbContext(); | ||
} | ||
} |
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,20 @@ | ||
// SPDX-FileCopyrightText: 2024 Frans van Dorsselaer | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
namespace UnitTests; | ||
|
||
[TestClass] | ||
sealed class SqliteTimestampModelCustomizer_Tests | ||
{ | ||
[TestMethod] | ||
public void SqliteTimestampModelCustomizer_Customize() | ||
{ | ||
using var db = new MemoryDbContext(); | ||
|
||
var TestTable = db.Model.FindEntityType(MemoryDbContext.TestTableName)!; | ||
var RowVersion = TestTable.FindProperty(MemoryDbContext.RowVersionName)!; | ||
|
||
Assert.AreEqual(typeof(long), RowVersion.GetProviderClrType()); | ||
} | ||
} |
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,38 @@ | ||
// SPDX-FileCopyrightText: 2024 Frans van Dorsselaer | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
using Dorssel.EntityFrameworkCore.Storage.ValueConversion; | ||
|
||
namespace UnitTests; | ||
|
||
[TestClass] | ||
sealed class TimestampToLongConverter_Tests | ||
{ | ||
static IEnumerable<object[]> KnownGoodConversions | ||
{ | ||
get => [ | ||
[0, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }], | ||
[1, new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }], | ||
[long.MaxValue, new byte[] { 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }], | ||
[-1, new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }], | ||
[long.MinValue, new byte[] { 0x80, 0, 0, 0, 0, 0, 0, 0 }], | ||
]; | ||
} | ||
|
||
[TestMethod] | ||
[DynamicData(nameof(KnownGoodConversions))] | ||
public void TimestampToLongConverter_ConvertToProviderTyped(long expectedLong, byte[] expectedTimestamp) | ||
{ | ||
var result = TimestampToLongConverter.Singleton.ConvertToProviderTyped(expectedTimestamp); | ||
Assert.AreEqual(expectedLong, result); | ||
} | ||
|
||
[TestMethod] | ||
[DynamicData(nameof(KnownGoodConversions))] | ||
public void TimestampToLongConverter_ConvertFromProviderTyped(long expectedLong, byte[] expectedTimestamp) | ||
{ | ||
var result = TimestampToLongConverter.Singleton.ConvertFromProviderTyped(expectedLong); | ||
CollectionAssert.AreEqual(expectedTimestamp, result); | ||
} | ||
} |