Path: redb/redb.Tests.Integration/Tests/SqlitePro/SqliteProSaveIntoOtherSchemeTests.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/SqlitePro/SqliteProSaveIntoOtherSchemeTests.cs ---- using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using redb.Core; using redb.Core.Attributes; using redb.Core.Exceptions; using redb.Core.Models.Entities; using redb.Core.Pro.Extensions; using redb.SQLite.Pro.Extensions; namespace redb.Tests.Integration.Tests.SqlitePro; [RedbScheme("Save: other scheme probe A", Name = "save_other_scheme_probe_a")] public class SaveOtherSchemeAProps { public string? Title { get; set; } } [RedbScheme("Save: other scheme probe B", Name = "save_other_scheme_probe_b")] public class SaveOtherSchemeBProps { public string? Label { get; set; } public long Amount { get; set; } } /// /// A save of RedbObject<A> under the id of an existing object of scheme B kept the object in scheme B, /// deleted its values and wrote the values of A's fields into it: B's values were gone and nothing reported it. The /// save is refused before anything is written, and so is a save over an object in the trash. /// public class SqliteProSaveIntoOtherSchemeTests { private const string Cs = "Data Source=redb_tests_save_other_scheme_pro.db"; private static async Task<(ServiceProvider Provider, IRedbService Redb)> StartAsync() { var services = new ServiceCollection(); services.AddLogging(b => b.SetMinimumLevel(LogLevel.Warning)); services.AddRedbPro(options => options.UseSqlite(Cs)); var provider = services.BuildServiceProvider(); var redb = provider.GetRequiredService(); await redb.InitializeAsync(ensureCreated: true); await redb.SyncSchemeAsync(); await redb.SyncSchemeAsync(); return (provider, redb); } [Fact] public async Task SaveUnderTheIdOfAnObjectOfAnotherScheme_IsRefused_AndKeepsItsValues() { Fixtures.SqliteTestSupport.DeleteDbFiles(Cs); var (provider, redb) = await StartAsync(); await using var _ = provider; var id = await redb.SaveAsync(new RedbObject { name = "b", Props = new SaveOtherSchemeBProps { Label = "kept", Amount = 42 } }); var act = () => redb.SaveAsync(new RedbObject { id = id, name = "a", Props = new SaveOtherSchemeAProps { Title = "intruder" } }); await act.Should().ThrowAsync(); var b = await redb.LoadAsync(id); b.Should().NotBeNull(); b!.name.Should().Be("b"); b.Props.Label.Should().Be("kept"); b.Props.Amount.Should().Be(42); } [Fact] public async Task SaveUnderTheIdOfATrashedObject_IsRefused() { Fixtures.SqliteTestSupport.DeleteDbFiles(Cs); var (provider, redb) = await StartAsync(); await using var _ = provider; var id = await redb.SaveAsync(new RedbObject { name = "a", Props = new SaveOtherSchemeAProps { Title = "trashed" } }); await redb.SoftDeleteAsync(new[] { id }); // marks the object for deletion: its scheme becomes the trash scheme var act = () => redb.SaveAsync(new RedbObject { id = id, name = "a", Props = new SaveOtherSchemeAProps { Title = "back" } }); await act.Should().ThrowAsync(); } }