diff --git a/build/Build.cs b/build/Build.cs index ad26c190..ca6ea8cf 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -133,28 +133,28 @@ internal partial class Build : NukeBuild DotNetPack(s => s .SetProject(Solution.CoreCraft) .Apply(PackSettingsBase) - .SetVersion(MakePreviewIfNeeded("0.6.0", "0.6.7")) + .SetVersion(MakePreviewIfNeeded("0.6.0", "0.6.8")) .SetDescription("A core library to build cross-platform and highly customizable domain models") .AddPackageTags("Model", "Domain")); DotNetPack(s => s .SetProject(Solution.CoreCraft_Generators) .Apply(PackSettingsBase) - .SetVersion(MakePreviewIfNeeded("0.6.0", "0.6.7")) + .SetVersion(MakePreviewIfNeeded("0.6.0", "0.6.8")) .SetDescription("Roslyn Source Generators for generating domain models using 'CoreCraft' library") .AddPackageTags("Model", "Domain", "SourceGenerator", "Generator")); DotNetPack(s => s .SetProject(Solution.CoreCraft_Storage_Sqlite) .Apply(PackSettingsBase) - .SetVersion(MakePreviewIfNeeded("0.6.0", "0.6.7")) + .SetVersion(MakePreviewIfNeeded("0.6.0", "0.6.8")) .SetDescription("SQLite storage implementation for 'CoreCraft' library") .AddPackageTags("Model", "Domain", "SQLite")); DotNetPack(s => s .SetProject(Solution.CoreCraft_Storage_Json) .Apply(PackSettingsBase) - .SetVersion(MakePreviewIfNeeded("0.3.0", "0.3.7")) + .SetVersion(MakePreviewIfNeeded("0.3.0", "0.3.8")) .SetDescription("Json storage implementation for 'CoreCraft' library") .AddPackageTags("Model", "Domain", "Json")); diff --git a/src/CoreCraft.SourceGeneration/Generators/ModelShardGenerator.cs b/src/CoreCraft.SourceGeneration/Generators/ModelShardGenerator.cs index 2bd759da..587408ac 100644 --- a/src/CoreCraft.SourceGeneration/Generators/ModelShardGenerator.cs +++ b/src/CoreCraft.SourceGeneration/Generators/ModelShardGenerator.cs @@ -283,11 +283,7 @@ private void DefineChangesFrameClass(ModelShard modelShard) code.EmptyLine(); DefineMergeMethod(modelShard); code.EmptyLine(); - ImplementUpdateMethod(modelShard); - code.EmptyLine(); - ImplementSaveMethod(modelShard); - code.EmptyLine(); - ImplementLoadMethod(modelShard); + ImplementDoMethod(modelShard); code.EmptyLine(); }); @@ -438,56 +434,21 @@ void DefineMergeMethod(ModelShard modelShard) }); } - void ImplementUpdateMethod(ModelShard modelShard) - { - code.WriteLine($"public void Update(IRepository repository)"); - code.Block(() => - { - foreach (var collection in modelShard.Collections) - { - code.WriteLine($"repository.Update({collection.Name});"); - } - code.EmptyLine(); - - foreach (var relation in modelShard.Relations) - { - code.WriteLine($"repository.Update({relation.Name});"); - } - }); - } - - void ImplementSaveMethod(ModelShard modelShard) - { - code.WriteLine($"public void Save(long changeId, IHistoryRepository repository)"); - code.Block(() => - { - foreach (var collection in modelShard.Collections) - { - code.WriteLine($"repository.Save(changeId, {collection.Name});"); - } - code.EmptyLine(); - - foreach (var relation in modelShard.Relations) - { - code.WriteLine($"repository.Save(changeId, {relation.Name});"); - } - }); - } - - void ImplementLoadMethod(ModelShard modelShard) + void ImplementDoMethod(ModelShard modelShard) { - code.WriteLine($"public void Load(long changeId, IHistoryRepository repository)"); + code.WriteLine($"public void Do(T operation)"); + code.WithIndent(c => c.WriteLine("where T : IChangesFrameOperation")); code.Block(() => { foreach (var collection in modelShard.Collections) { - code.WriteLine($"repository.Load(changeId, {collection.Name});"); + code.WriteLine($"operation.OnCollection({collection.Name});"); } code.EmptyLine(); foreach (var relation in modelShard.Relations) { - code.WriteLine($"repository.Load(changeId, {relation.Name});"); + code.WriteLine($"operation.OnRelation({relation.Name});"); } }); } diff --git a/src/CoreCraft.Storage.Json/JsonStorage.cs b/src/CoreCraft.Storage.Json/JsonStorage.cs index 052b1dd4..9a7f437c 100644 --- a/src/CoreCraft.Storage.Json/JsonStorage.cs +++ b/src/CoreCraft.Storage.Json/JsonStorage.cs @@ -3,6 +3,7 @@ using CoreCraft.Persistence; using CoreCraft.Persistence.History; using CoreCraft.Persistence.Lazy; +using CoreCraft.Persistence.Operations; using CoreCraft.Storage.Json.Model; using Newtonsoft.Json; @@ -43,7 +44,7 @@ public void Update(IEnumerable modelChanges) foreach (var change in modelChanges.Cast()) { - change.Update(repository); + change.Do(new UpdateChangesFrameOperation(repository)); } _jsonFileHandler.WriteModelShardsToFile(_path, shards, _settings); diff --git a/src/CoreCraft.Storage.Sqlite/SqliteRepository.cs b/src/CoreCraft.Storage.Sqlite/SqliteRepository.cs index 259fc4af..842583d4 100644 --- a/src/CoreCraft.Storage.Sqlite/SqliteRepository.cs +++ b/src/CoreCraft.Storage.Sqlite/SqliteRepository.cs @@ -4,6 +4,7 @@ using System.Text.Json.Serialization.Metadata; using CoreCraft.ChangesTracking; using CoreCraft.Core; +using CoreCraft.Persistence.Operations; using Microsoft.Data.Sqlite; using static CoreCraft.Storage.Sqlite.QueryBuilder; @@ -38,8 +39,7 @@ public IDbTransaction BeginTransaction() public int GetDatabaseVersion() { - using var command = _connection.CreateCommand(); - command.CommandText = QueryBuilder.Migrations.GetDatabaseVersion; + using var command = CreateCommand(QueryBuilder.Migrations.GetDatabaseVersion); Log(command); @@ -50,17 +50,19 @@ public int GetDatabaseVersion() public void SetDatabaseVersion(int version) { - using var command = _connection.CreateCommand(); - command.CommandText = QueryBuilder.Migrations.SetDatabaseVersion(version); + using var command = CreateCommand(QueryBuilder.Migrations.SetDatabaseVersion(version)); + Log(command); + command.ExecuteNonQuery(); } public void ExecuteNonQuery(string query) { - using var command = _connection.CreateCommand(); - command.CommandText = query; + using var command = CreateCommand(query); + Log(command); + command.ExecuteNonQuery(); } @@ -287,8 +289,7 @@ public void Load(IMutableRelation relation, IE return; } - using var command = _connection.CreateCommand(); - command.CommandText = Relations.Select(relation.Info); + using var command = CreateCommand(Relations.Select(relation.Info)); Log(command); @@ -311,6 +312,8 @@ public void Load(long changeId, ICollectionChangeSet(long changeId, ICollectionChangeSet(reader, 3); changes.Add(action, entity!, oldProperty, newProperty); - - Log(command); } } @@ -331,6 +332,8 @@ public void Load(long changeId, IRelationChangeSet(long changeId, IRelationChangeSet(reader, 2); changes.Add(action, parent!, child!); - - Log(command); } } @@ -360,7 +361,7 @@ public IEnumerable LoadChanges(IEnumerable shards) foreach (var shard in shards.Cast()) { var change = (IChangesFrameEx)shard.Create(); - change.Load(timestamp, this); + change.Do(new LoadChangesFrameOperation(timestamp, this)); if (change.HasChanges()) { modelChanges.AddOrGet(change); @@ -456,8 +457,7 @@ private void Delete(SqliteCommand command, TEntity entity) private bool Exists(string name) { - using var command = _connection.CreateCommand(); - command.CommandText = IfTableExists(name); + using var command = CreateCommand(IfTableExists(name)); Log(command); diff --git a/src/CoreCraft.Storage.Sqlite/SqliteStorage.cs b/src/CoreCraft.Storage.Sqlite/SqliteStorage.cs index a169f194..f46584b4 100644 --- a/src/CoreCraft.Storage.Sqlite/SqliteStorage.cs +++ b/src/CoreCraft.Storage.Sqlite/SqliteStorage.cs @@ -3,6 +3,7 @@ using CoreCraft.Persistence; using CoreCraft.Persistence.History; using CoreCraft.Persistence.Lazy; +using CoreCraft.Persistence.Operations; using CoreCraft.Storage.Sqlite.Migrations; using System.Data; @@ -48,7 +49,7 @@ public void Update(IEnumerable modelChanges) { foreach (var change in modelChanges.Cast()) { - change.Update(repository); + change.Do(new UpdateChangesFrameOperation(repository)); } }); } diff --git a/src/CoreCraft/ChangesTracking/IChangesFrameEx.cs b/src/CoreCraft/ChangesTracking/IChangesFrameEx.cs index 733206a6..3b58d237 100644 --- a/src/CoreCraft/ChangesTracking/IChangesFrameEx.cs +++ b/src/CoreCraft/ChangesTracking/IChangesFrameEx.cs @@ -1,7 +1,4 @@ -using CoreCraft.Persistence; -using CoreCraft.Persistence.History; - -namespace CoreCraft.ChangesTracking; +namespace CoreCraft.ChangesTracking; /// /// An extension of the which used internally in the @@ -54,32 +51,8 @@ public interface IChangesFrameEx : IChangesFrame IChangesFrame Invert(); /// - /// Saves the changes frame using the provided repository. - /// - /// The repository used to save the changes frame. - void Update(IRepository repository); - - /// - /// Saves the changes stored in this frame to the specified repository. + /// TODO: write documentation /// - /// A unique identifier for the change set. - /// The instance used to persist the changes. - /// - /// This method persists the changes tracked within this instance to the history storage using the provided `repository`. - /// - The `changeId` parameter allows for associating the changes with a specific event or action. - /// - The `repository` parameter is an instance responsible for handling the storage and retrieval of history data. - /// - void Save(long changeId, IHistoryRepository repository); - - /// - /// Loads changes history from the specified repository for the given change identifier. - /// - /// A unique identifier for the change set to load. - /// The instance used to retrieve the changes. - /// - /// This method retrieves changes associated with the provided `changeId` from the storage using the specified `repository`. - /// - The `changeId` parameter specifies the unique identifier of the change set to be loaded. - /// - The `repository` parameter is an instance responsible for providing access to changes. - /// - void Load(long changeId, IHistoryRepository repository); + /// + void Do(T operation) where T : IChangesFrameOperation; } diff --git a/src/CoreCraft/ChangesTracking/IChangesFrameOperation.cs b/src/CoreCraft/ChangesTracking/IChangesFrameOperation.cs new file mode 100644 index 00000000..8daf054a --- /dev/null +++ b/src/CoreCraft/ChangesTracking/IChangesFrameOperation.cs @@ -0,0 +1,29 @@ +namespace CoreCraft.ChangesTracking; + +/// +/// TODO: write documentation +/// +public interface IChangesFrameOperation +{ + /// + /// + /// A type of an entity + /// A type of properties + /// A base collection which will be wrapped in this method + /// A new collection with adjusted behavior + void OnCollection( + ICollectionChangeSet collection) + where TEntity : Entity + where TProperties : Properties; + + /// + /// + /// A type of a parent entity + /// A type of a child entity + /// A base relation which will be wrapped in this method + /// A new relation with adjusted behavior + void OnRelation( + IRelationChangeSet relation) + where TParent : Entity + where TChild : Entity; +} diff --git a/src/CoreCraft/ChangesTracking/IModelChanges.cs b/src/CoreCraft/ChangesTracking/IModelChanges.cs index e98a46ab..e3a78ddf 100644 --- a/src/CoreCraft/ChangesTracking/IModelChanges.cs +++ b/src/CoreCraft/ChangesTracking/IModelChanges.cs @@ -40,7 +40,7 @@ bool TryGetFrame(out T frame) IModelChanges Invert(); /// - /// + /// TODO: write documentation /// /// void Save(IHistoryRepository repository); diff --git a/src/CoreCraft/ChangesTracking/ModelChanges.cs b/src/CoreCraft/ChangesTracking/ModelChanges.cs index 43a93b0d..f40eb6ca 100644 --- a/src/CoreCraft/ChangesTracking/ModelChanges.cs +++ b/src/CoreCraft/ChangesTracking/ModelChanges.cs @@ -1,5 +1,6 @@ using System.Collections; using CoreCraft.Persistence.History; +using CoreCraft.Persistence.Operations; namespace CoreCraft.ChangesTracking; @@ -83,7 +84,7 @@ public void Save(IHistoryRepository repository) { foreach (var frame in _frames) { - frame.Save(_timestamp, repository); + frame.Do(new SaveChangesFrameOperation(_timestamp, repository)); } } diff --git a/src/CoreCraft/Persistence/Operations/LoadChangesFrameOperation.cs b/src/CoreCraft/Persistence/Operations/LoadChangesFrameOperation.cs new file mode 100644 index 00000000..827e8618 --- /dev/null +++ b/src/CoreCraft/Persistence/Operations/LoadChangesFrameOperation.cs @@ -0,0 +1,33 @@ +using System.Diagnostics.CodeAnalysis; +using CoreCraft.ChangesTracking; +using CoreCraft.Persistence.History; + +namespace CoreCraft.Persistence.Operations; + +/// +/// TODO: write documentation +/// +/// +/// +[ExcludeFromCodeCoverage] +public readonly struct LoadChangesFrameOperation(long timestamp, IHistoryRepository repository) : IChangesFrameOperation +{ + private readonly long _timestamp = timestamp; + private readonly IHistoryRepository _repository = repository; + + /// + public void OnCollection(ICollectionChangeSet collection) + where TEntity : Entity + where TProperties : Properties + { + _repository.Load(_timestamp, collection); + } + + /// + public void OnRelation(IRelationChangeSet relation) + where TParent : Entity + where TChild : Entity + { + _repository.Load(_timestamp, relation); + } +} diff --git a/src/CoreCraft/Persistence/Operations/SaveChangesFrameOperation.cs b/src/CoreCraft/Persistence/Operations/SaveChangesFrameOperation.cs new file mode 100644 index 00000000..c0ace4e0 --- /dev/null +++ b/src/CoreCraft/Persistence/Operations/SaveChangesFrameOperation.cs @@ -0,0 +1,26 @@ +using System.Diagnostics.CodeAnalysis; +using CoreCraft.ChangesTracking; +using CoreCraft.Persistence.History; + +namespace CoreCraft.Persistence.Operations; + +[ExcludeFromCodeCoverage] +internal readonly struct SaveChangesFrameOperation(long timestamp, IHistoryRepository repository) : IChangesFrameOperation +{ + private readonly long _timestamp = timestamp; + private readonly IHistoryRepository _repository = repository; + + public void OnCollection(ICollectionChangeSet collection) + where TEntity : Entity + where TProperties : Properties + { + _repository.Save(_timestamp, collection); + } + + public void OnRelation(IRelationChangeSet relation) + where TParent : Entity + where TChild : Entity + { + _repository.Save(_timestamp, relation); + } +} diff --git a/src/CoreCraft/Persistence/Operations/UpdateChangesFrameOperation.cs b/src/CoreCraft/Persistence/Operations/UpdateChangesFrameOperation.cs new file mode 100644 index 00000000..7d6cce45 --- /dev/null +++ b/src/CoreCraft/Persistence/Operations/UpdateChangesFrameOperation.cs @@ -0,0 +1,30 @@ +using System.Diagnostics.CodeAnalysis; +using CoreCraft.ChangesTracking; + +namespace CoreCraft.Persistence.Operations; + +/// +/// TODO: write documentation +/// +/// +[ExcludeFromCodeCoverage] +public readonly struct UpdateChangesFrameOperation(IRepository repository) : IChangesFrameOperation +{ + private readonly IRepository _repository = repository; + + /// + public void OnCollection(ICollectionChangeSet collection) + where TEntity : Entity + where TProperties : Properties + { + _repository.Update(collection); + } + + /// + public void OnRelation(IRelationChangeSet relation) + where TParent : Entity + where TChild : Entity + { + _repository.Update(relation); + } +} diff --git a/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_AllFeatures_g_cs.verified.txt b/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_AllFeatures_g_cs.verified.txt index fbe7899b..f38420fd 100644 --- a/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_AllFeatures_g_cs.verified.txt +++ b/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_AllFeatures_g_cs.verified.txt @@ -276,37 +276,16 @@ namespace compilation.AllFeatures }; } - public void Update(IRepository repository) + public void Do(T operation) + where T : IChangesFrameOperation { - repository.Update(FirstCollection); - repository.Update(SecondCollection); + operation.OnCollection(FirstCollection); + operation.OnCollection(SecondCollection); - repository.Update(OneToOneRelation); - repository.Update(OneToManyRelation); - repository.Update(ManyToOneRelation); - repository.Update(ManyToManyRelation); - } - - public void Save(int changeId, IHistoryRepository repository) - { - repository.Save(changeId, FirstCollection); - repository.Save(changeId, SecondCollection); - - repository.Save(changeId, OneToOneRelation); - repository.Save(changeId, OneToManyRelation); - repository.Save(changeId, ManyToOneRelation); - repository.Save(changeId, ManyToManyRelation); - } - - public void Load(int changeId, IHistoryRepository repository) - { - repository.Load(changeId, FirstCollection); - repository.Load(changeId, SecondCollection); - - repository.Load(changeId, OneToOneRelation); - repository.Load(changeId, OneToManyRelation); - repository.Load(changeId, ManyToOneRelation); - repository.Load(changeId, ManyToManyRelation); + operation.OnRelation(OneToOneRelation); + operation.OnRelation(OneToManyRelation); + operation.OnRelation(ManyToOneRelation); + operation.OnRelation(ManyToManyRelation); } } diff --git a/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_LoadManually_g_cs.verified.txt b/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_LoadManually_g_cs.verified.txt index d6c7d6ac..2a6fb5b5 100644 --- a/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_LoadManually_g_cs.verified.txt +++ b/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_LoadManually_g_cs.verified.txt @@ -236,31 +236,14 @@ namespace compilation.LoadManually }; } - public void Update(IRepository repository) + public void Do(T operation) + where T : IChangesFrameOperation { - repository.Update(FirstCollection); - repository.Update(SecondCollection); - repository.Update(ThirdCollection); + operation.OnCollection(FirstCollection); + operation.OnCollection(SecondCollection); + operation.OnCollection(ThirdCollection); - repository.Update(OneToOneRelation); - } - - public void Save(int changeId, IHistoryRepository repository) - { - repository.Save(changeId, FirstCollection); - repository.Save(changeId, SecondCollection); - repository.Save(changeId, ThirdCollection); - - repository.Save(changeId, OneToOneRelation); - } - - public void Load(int changeId, IHistoryRepository repository) - { - repository.Load(changeId, FirstCollection); - repository.Load(changeId, SecondCollection); - repository.Load(changeId, ThirdCollection); - - repository.Load(changeId, OneToOneRelation); + operation.OnRelation(OneToOneRelation); } } @@ -441,17 +424,8 @@ namespace compilation.LoadManually }; } - public void Update(IRepository repository) - { - - } - - public void Save(int changeId, IHistoryRepository repository) - { - - } - - public void Load(int changeId, IHistoryRepository repository) + public void Do(T operation) + where T : IChangesFrameOperation { } diff --git a/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_VisibilityImplementations_g_cs.verified.txt b/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_VisibilityImplementations_g_cs.verified.txt index a1b397cb..279d8e78 100644 --- a/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_VisibilityImplementations_g_cs.verified.txt +++ b/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_VisibilityImplementations_g_cs.verified.txt @@ -276,37 +276,16 @@ namespace compilation.VisibilityImplementations }; } - public void Update(IRepository repository) + public void Do(T operation) + where T : IChangesFrameOperation { - repository.Update(FirstCollection); - repository.Update(SecondCollection); + operation.OnCollection(FirstCollection); + operation.OnCollection(SecondCollection); - repository.Update(OneToOneRelation); - repository.Update(OneToManyRelation); - repository.Update(ManyToOneRelation); - repository.Update(ManyToManyRelation); - } - - public void Save(int changeId, IHistoryRepository repository) - { - repository.Save(changeId, FirstCollection); - repository.Save(changeId, SecondCollection); - - repository.Save(changeId, OneToOneRelation); - repository.Save(changeId, OneToManyRelation); - repository.Save(changeId, ManyToOneRelation); - repository.Save(changeId, ManyToManyRelation); - } - - public void Load(int changeId, IHistoryRepository repository) - { - repository.Load(changeId, FirstCollection); - repository.Load(changeId, SecondCollection); - - repository.Load(changeId, OneToOneRelation); - repository.Load(changeId, OneToManyRelation); - repository.Load(changeId, ManyToOneRelation); - repository.Load(changeId, ManyToManyRelation); + operation.OnRelation(OneToOneRelation); + operation.OnRelation(OneToManyRelation); + operation.OnRelation(ManyToOneRelation); + operation.OnRelation(ManyToManyRelation); } } diff --git a/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_TwoModelFilesSnapshotTest_AllFeatures_g_cs.verified.txt b/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_TwoModelFilesSnapshotTest_AllFeatures_g_cs.verified.txt index fbe7899b..f38420fd 100644 --- a/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_TwoModelFilesSnapshotTest_AllFeatures_g_cs.verified.txt +++ b/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_TwoModelFilesSnapshotTest_AllFeatures_g_cs.verified.txt @@ -276,37 +276,16 @@ namespace compilation.AllFeatures }; } - public void Update(IRepository repository) + public void Do(T operation) + where T : IChangesFrameOperation { - repository.Update(FirstCollection); - repository.Update(SecondCollection); + operation.OnCollection(FirstCollection); + operation.OnCollection(SecondCollection); - repository.Update(OneToOneRelation); - repository.Update(OneToManyRelation); - repository.Update(ManyToOneRelation); - repository.Update(ManyToManyRelation); - } - - public void Save(int changeId, IHistoryRepository repository) - { - repository.Save(changeId, FirstCollection); - repository.Save(changeId, SecondCollection); - - repository.Save(changeId, OneToOneRelation); - repository.Save(changeId, OneToManyRelation); - repository.Save(changeId, ManyToOneRelation); - repository.Save(changeId, ManyToManyRelation); - } - - public void Load(int changeId, IHistoryRepository repository) - { - repository.Load(changeId, FirstCollection); - repository.Load(changeId, SecondCollection); - - repository.Load(changeId, OneToOneRelation); - repository.Load(changeId, OneToManyRelation); - repository.Load(changeId, ManyToOneRelation); - repository.Load(changeId, ManyToManyRelation); + operation.OnRelation(OneToOneRelation); + operation.OnRelation(OneToManyRelation); + operation.OnRelation(ManyToOneRelation); + operation.OnRelation(ManyToManyRelation); } } diff --git a/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_TwoModelFilesSnapshotTest_AnotherModelFile_g_cs.verified.txt b/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_TwoModelFilesSnapshotTest_AnotherModelFile_g_cs.verified.txt index 5d3286e4..02dca038 100644 --- a/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_TwoModelFilesSnapshotTest_AnotherModelFile_g_cs.verified.txt +++ b/src/Tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_TwoModelFilesSnapshotTest_AnotherModelFile_g_cs.verified.txt @@ -276,37 +276,16 @@ namespace compilation.AnotherModelFile }; } - public void Update(IRepository repository) + public void Do(T operation) + where T : IChangesFrameOperation { - repository.Update(FirstCollection); - repository.Update(SecondCollection); + operation.OnCollection(FirstCollection); + operation.OnCollection(SecondCollection); - repository.Update(OneToOneRelation); - repository.Update(OneToManyRelation); - repository.Update(ManyToOneRelation); - repository.Update(ManyToManyRelation); - } - - public void Save(int changeId, IHistoryRepository repository) - { - repository.Save(changeId, FirstCollection); - repository.Save(changeId, SecondCollection); - - repository.Save(changeId, OneToOneRelation); - repository.Save(changeId, OneToManyRelation); - repository.Save(changeId, ManyToOneRelation); - repository.Save(changeId, ManyToManyRelation); - } - - public void Load(int changeId, IHistoryRepository repository) - { - repository.Load(changeId, FirstCollection); - repository.Load(changeId, SecondCollection); - - repository.Load(changeId, OneToOneRelation); - repository.Load(changeId, OneToManyRelation); - repository.Load(changeId, ManyToOneRelation); - repository.Load(changeId, ManyToManyRelation); + operation.OnRelation(OneToOneRelation); + operation.OnRelation(OneToManyRelation); + operation.OnRelation(ManyToOneRelation); + operation.OnRelation(ManyToManyRelation); } } diff --git a/src/Tests/CoreCraft.Storage.Json.Tests/JsonStorageTests.cs b/src/Tests/CoreCraft.Storage.Json.Tests/JsonStorageTests.cs index c68080f6..88f2b151 100644 --- a/src/Tests/CoreCraft.Storage.Json.Tests/JsonStorageTests.cs +++ b/src/Tests/CoreCraft.Storage.Json.Tests/JsonStorageTests.cs @@ -1,6 +1,7 @@ using CoreCraft.ChangesTracking; using CoreCraft.Persistence; using CoreCraft.Persistence.Lazy; +using CoreCraft.Persistence.Operations; using CoreCraft.Storage.Json.Model; using Newtonsoft.Json; @@ -28,7 +29,7 @@ public void UpdateTest() A.CallTo(() => jsonFileHandler.ReadModelShardsFromFile(A.Ignored, A.Ignored)) .MustHaveHappenedOnceExactly(); - A.CallTo(() => change.Update(A.Ignored)) + A.CallTo(() => change.Do(A.Ignored)) .MustHaveHappenedOnceExactly(); A.CallTo(() => jsonFileHandler.WriteModelShardsToFile(A.Ignored, A>.Ignored, A.Ignored)) .MustHaveHappenedOnceExactly(); diff --git a/src/Tests/CoreCraft.Storage.Sqlite.Tests/SqliteStorageTests.cs b/src/Tests/CoreCraft.Storage.Sqlite.Tests/SqliteStorageTests.cs index 75efb717..22e4bfb2 100644 --- a/src/Tests/CoreCraft.Storage.Sqlite.Tests/SqliteStorageTests.cs +++ b/src/Tests/CoreCraft.Storage.Sqlite.Tests/SqliteStorageTests.cs @@ -4,6 +4,7 @@ using CoreCraft.Storage.Sqlite.Migrations; using System.Data; using CoreCraft.Persistence.Lazy; +using CoreCraft.Persistence.Operations; namespace CoreCraft.Storage.Sqlite.Tests; @@ -28,10 +29,11 @@ public void SetUp() public void UpdateTransactionRollbackOnExceptionTest() { var change = A.Fake(); - A.CallTo(() => change.Update(A.Ignored)).Throws(); + A.CallTo(() => change.Do(A.Ignored)) + .Throws(); var modelChanges = A.Fake(c => c.Implements()); - var storage = new SqliteStorage("", Array.Empty(), _factory!); + var storage = new SqliteStorage("", [], _factory!); Assert.Throws(() => storage.Update([change])); @@ -49,7 +51,8 @@ public void UpdateIsCalledOnModelShardStorageTest() storage.Update([change]); - A.CallTo(() => change.Update(A.Ignored)).MustHaveHappenedOnceExactly(); + A.CallTo(() => change.Do(A.Ignored)) + .MustHaveHappenedOnceExactly(); } [Test] diff --git a/src/Tests/CoreCraft.Tests/Persistence/ModelShardStorageTests.cs b/src/Tests/CoreCraft.Tests/Persistence/ModelShardStorageTests.cs index 8ccd7fd8..819d156d 100644 --- a/src/Tests/CoreCraft.Tests/Persistence/ModelShardStorageTests.cs +++ b/src/Tests/CoreCraft.Tests/Persistence/ModelShardStorageTests.cs @@ -2,6 +2,7 @@ using CoreCraft.Core; using CoreCraft.Features.CoW; using CoreCraft.Persistence; +using CoreCraft.Persistence.Operations; namespace CoreCraft.Tests.Persistence; @@ -18,9 +19,9 @@ public void SetUp() [Test] public void UpdateCollectionTest() { - var shard = new FakeChangesFrame(); + var changes = new FakeChangesFrame(); - shard.Update(_repository!); + changes.Do(new UpdateChangesFrameOperation(_repository!)); A.CallTo(() => _repository!.Update( A>.Ignored)) @@ -30,9 +31,9 @@ public void UpdateCollectionTest() [Test] public void UpdateRelationTest() { - var shard = new FakeChangesFrame(); + var changes = new FakeChangesFrame(); - shard.Update(_repository!); + changes.Do(new UpdateChangesFrameOperation(_repository!)); A.CallTo(() => _repository!.Update( A>.Ignored))