Path: redb/redb.Tests.Integration/Tests/Base/MigrationTransformArithmeticTestsBase.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/Base/MigrationTransformArithmeticTestsBase.cs ---- using AwesomeAssertions.Execution; using Microsoft.Extensions.DependencyInjection; using redb.Core; using redb.Core.Attributes; using redb.Core.Models.Entities; using redb.Core.Pro.Migration; using redb.Core.Pro.Query; namespace redb.Tests.Integration.Tests.Base; [RedbScheme("Migrations: transform arithmetic probe", Name = "migration_transform_arithmetic_probe")] public class MigrationTransformArithmeticProbeProps { public long Amount { get; set; } public long? Bonus { get; set; } public long Total { get; set; } } public class MigrationTransformMultiply : IRedbMigration { public void Configure(IMigrationBuilder builder) => builder.Property(p => p.Amount).Transform(v => v * 2); } public class MigrationTransformAdd : IRedbMigration { public void Configure(IMigrationBuilder builder) => builder.Property(p => p.Amount).Transform(v => v + 1); } public class MigrationTransformParameterOnTheRight : IRedbMigration { public void Configure(IMigrationBuilder builder) => builder.Property(p => p.Amount).Transform(v => 100 - v); } public class MigrationTransformMixed : IRedbMigration { public void Configure(IMigrationBuilder builder) => builder.Property(p => p.Amount).Transform(v => 2 * (v + 3) - 1); } public class MigrationComputedWithCoalesce : IRedbMigration { public void Configure(IMigrationBuilder builder) => builder.Property(p => p.Total).ComputedFrom(p => p.Amount + (p.Bonus ?? 0)); } /// /// A Transform whose value takes part in arithmetic: the value is the lambda's parameter itself, and every place it /// appears must read the property's column. /// public abstract class MigrationTransformArithmeticTestsBase { private readonly IRedbService _redb; private readonly ISqlDialectPro _dialect; protected MigrationTransformArithmeticTestsBase(IRedbService redb, IServiceProvider services) { _redb = redb; _dialect = services.GetRequiredService(); } [Fact] public async Task Transform_Multiply_DoublesTheValue() { var (results, amount) = await RunAsync(); using (new AssertionScope()) { results.Should().OnlyContain(r => r.Success, "the transform compiles and runs"); amount.Should().Be(10); } } [Fact] public async Task Transform_Add_AddsOne() { var (results, amount) = await RunAsync(); using (new AssertionScope()) { results.Should().OnlyContain(r => r.Success, "the transform compiles and runs"); amount.Should().Be(6); } } [Fact] public async Task Transform_ParameterOnTheRight_SubtractsTheValue() { var (results, amount) = await RunAsync(); using (new AssertionScope()) { results.Should().OnlyContain(r => r.Success, "the transform compiles and runs"); amount.Should().Be(95); } } [Fact] public async Task Transform_MixedWithAConstantOnEachSide_ComputesTheValue() { var (results, amount) = await RunAsync(); using (new AssertionScope()) { results.Should().OnlyContain(r => r.Success, "the transform compiles and runs"); amount.Should().Be(15); } } [Fact] public async Task ComputedFrom_CoalesceInsideAnOperator_KeepsWhatCameBeforeIt() { var (results, _) = await RunAsync(); var total = (await _redb.LoadAsync(_lastId))!.Props.Total; using (new AssertionScope()) { results.Should().OnlyContain(r => r.Success, "the computation compiles and runs"); total.Should().Be(8, "Amount 5 plus Bonus 3"); } } private long _lastId; private async Task<(List Results, long Amount)> RunAsync() where TMigration : IRedbMigration, new() { var scheme = await _redb.SyncSchemeAsync(); await _redb.Context.ExecuteAsync($"DELETE FROM _migrations WHERE _scheme_id = {scheme.Id}"); await _redb.Context.ExecuteAsync( $"DELETE FROM _values WHERE _id_object IN (SELECT _id FROM _objects WHERE _id_scheme = {scheme.Id})"); await _redb.Context.ExecuteAsync($"DELETE FROM _objects WHERE _id_scheme = {scheme.Id}"); var id = await _redb.SaveAsync(new RedbObject { name = "transform-arithmetic", Props = new MigrationTransformArithmeticProbeProps { Amount = 5, Bonus = 3, Total = -1 } }); _lastId = id; var results = await _redb.MigrateAsync(_dialect); var amount = (await _redb.LoadAsync(id))!.Props.Amount; return (results, amount); } }