Skip to content

Commit dda5497

Browse files
committed
fixed tests
1 parent 024d38f commit dda5497

15 files changed

+405
-48
lines changed

build/Build.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ internal partial class Build : NukeBuild
133133
DotNetPack(s => s
134134
.SetProject(Solution.CoreCraft)
135135
.Apply(PackSettingsBase)
136-
.SetVersion(MakePreviewIfNeeded("0.7.0", "0.8.1"))
136+
.SetVersion(MakePreviewIfNeeded("0.7.0", "0.8.2"))
137137
.SetDescription("A core library to build cross-platform and highly customizable domain models")
138138
.AddPackageTags("Model", "Domain"));
139139

140140
DotNetPack(s => s
141141
.SetProject(Solution.CoreCraft_Generators)
142142
.Apply(PackSettingsBase)
143-
.SetVersion(MakePreviewIfNeeded("0.7.0", "0.8.0"))
143+
.SetVersion(MakePreviewIfNeeded("0.7.0", "0.8.1"))
144144
.SetDescription("Roslyn Source Generators for generating domain models using 'CoreCraft' library")
145145
.AddPackageTags("Model", "Domain", "SourceGenerator", "Generator"));
146146

src/CoreCraft.SourceGeneration/Generators/ModelGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static string Generate(string assemblyName, string modelName, ModelScheme
1515
code.WriteLine($"namespace {@namespace}");
1616
code.Block(() =>
1717
{
18+
code.WriteLine("using CoreCraft;");
1819
code.WriteLine("using CoreCraft.Core;");
1920
code.WriteLine("using CoreCraft.ChangesTracking;");
2021
code.WriteLine("using CoreCraft.Persistence;");

src/CoreCraft.SourceGeneration/Generators/ModelShardGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ private void DefineModelShardViewClass(ModelShard modelShard)
581581

582582
void ImplementCtor(ModelShard modelShard)
583583
{
584-
code.WriteLine($"public {modelShard.Name}ModelShardView(CoreCraft.IDomainModel model)");
584+
code.WriteLine($"public {modelShard.Name}ModelShardView(IDomainModel model)");
585585
code.Block(() =>
586586
{
587587
code.WriteLine($"var builder = model.View<I{modelShard.Name}ModelShard, I{modelShard.Name}ChangesFrame>();");

src/CoreCraft/DomainModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public Task Load<T>(IStorage storage, Func<IModelShardLoader<T>, ILazyLoader> co
202202
where T : IMutableModelShard
203203
{
204204
var changes = new ModelChanges(DateTime.UtcNow.Ticks);
205-
var snapshot = new Snapshot(_modelView.UnsafeModel, new[] { new TrackableFeature(changes) });
205+
var snapshot = new Snapshot(_modelView.UnsafeModel, [new TrackableFeature(changes)]);
206206
var loader = new ModelShardLoader<T>(((IMutableModel)snapshot).Shard<T>());
207207
var configuration = configure(loader);
208208

@@ -233,7 +233,7 @@ internal async Task Apply(IModelChanges changes, CancellationToken token = defau
233233
{
234234
if (changes.HasChanges())
235235
{
236-
var snapshot = new Snapshot(_modelView.UnsafeModel, new[] { new CoWFeature() });
236+
var snapshot = new Snapshot(_modelView.UnsafeModel, [new CoWFeature()]);
237237

238238
try
239239
{

src/CoreCraft/Subscription/Builders/ICollectionSubscriptionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace CoreCraft.Subscription.Builders;
77
/// </summary>
88
/// <typeparam name="TEntity">The type of the entity object</typeparam>
99
/// <typeparam name="TProperties">The type of the properties associated with the entity</typeparam>
10-
public interface ICollectionSubscriptionBuilder<TEntity, TProperties> : ISubscriptionBuilder<ICollectionChangeSet<TEntity, TProperties>>
10+
public interface ICollectionSubscriptionBuilder<TEntity, TProperties> : IObservable<Change<ICollectionChangeSet<TEntity, TProperties>>>
1111
where TEntity : Entity
1212
where TProperties : Properties
1313
{

src/CoreCraft/Subscription/Builders/IModelShardSubscriptionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace CoreCraft.Subscription.Builders;
77
/// Subscription builder which provides a way to subscribe to model shard changes
88
/// </summary>
99
/// <typeparam name="T">A changes frame of the given model shard</typeparam>
10-
public interface IModelShardSubscriptionBuilder<T> : ISubscriptionBuilder<T>
10+
public interface IModelShardSubscriptionBuilder<T> : IObservable<Change<T>>
1111
where T : class, IChangesFrame
1212
{
1313
/// <summary>

src/CoreCraft/Subscription/Builders/IRelationSubscriptionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace CoreCraft.Subscription.Builders;
77
/// </summary>
88
/// <typeparam name="TParent">A type of parent entity</typeparam>
99
/// <typeparam name="TChild">A type of child entity</typeparam>
10-
public interface IRelationSubscriptionBuilder<TParent, TChild> : ISubscriptionBuilder<IRelationChangeSet<TParent, TChild>>
10+
public interface IRelationSubscriptionBuilder<TParent, TChild> : IObservable<Change<IRelationChangeSet<TParent, TChild>>>
1111
where TParent : Entity
1212
where TChild : Entity
1313
{

src/CoreCraft/Subscription/Builders/ISubscribtionBuilder.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/CoreCraft/Subscription/Extensions/SubscriptionBuilderExtensions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace CoreCraft.Subscription.Extensions;
55

66
/// <summary>
7-
/// A collection of extensions methods for <see cref="ISubscriptionBuilder{T}"/>
7+
/// A collection of extensions methods for subscription builders
88
/// </summary>
99
public static class SubscriptionBuilderExtensions
1010
{
@@ -18,7 +18,7 @@ public static class SubscriptionBuilderExtensions
1818
public static IDisposable Subscribe<TFrame>(
1919
this IModelShardSubscriptionBuilder<TFrame> self,
2020
Action<Change<TFrame>> handler)
21-
where TFrame : class, IChangesFrame
21+
where TFrame : class, IChangesFrame
2222
{
2323
return self.Subscribe(new AnonymousObserver<Change<TFrame>>(handler));
2424
}
@@ -34,8 +34,8 @@ public static IDisposable Subscribe<TFrame>(
3434
public static IDisposable Subscribe<TEntity, TProperties>(
3535
this ICollectionSubscriptionBuilder<TEntity, TProperties> self,
3636
Action<Change<ICollectionChangeSet<TEntity, TProperties>>> handler)
37-
where TEntity : Entity
38-
where TProperties : Properties
37+
where TEntity : Entity
38+
where TProperties : Properties
3939
{
4040
return self.Subscribe(new AnonymousObserver<Change<ICollectionChangeSet<TEntity, TProperties>>>(handler));
4141
}
@@ -51,8 +51,8 @@ public static IDisposable Subscribe<TEntity, TProperties>(
5151
public static IDisposable Subscribe<TParent, TChild>(
5252
this IRelationSubscriptionBuilder<TParent, TChild> self,
5353
Action<Change<IRelationChangeSet<TParent, TChild>>> handler)
54-
where TParent : Entity
55-
where TChild : Entity
54+
where TParent : Entity
55+
where TChild : Entity
5656
{
5757
return self.Subscribe(new AnonymousObserver<Change<IRelationChangeSet<TParent, TChild>>>(handler));
5858
}
@@ -68,8 +68,8 @@ public static IDisposable Subscribe<TParent, TChild>(
6868
public static IDisposable Bind<TEntity, TProperties>(
6969
this ICollectionSubscriptionBuilder<TEntity, TProperties> self,
7070
Action<Change<CollectionChangeGroups<TEntity, TProperties>>> handler)
71-
where TEntity : Entity
72-
where TProperties : Properties
71+
where TEntity : Entity
72+
where TProperties : Properties
7373
{
7474
return self.Bind(new AnonymousObserver<Change<CollectionChangeGroups<TEntity, TProperties>>>(handler));
7575
}
@@ -87,8 +87,8 @@ public static IDisposable Bind<TEntity, TProperties>(
8787
this ICollectionSubscriptionBuilder<TEntity, TProperties> self,
8888
TEntity entity,
8989
Action<IEntityChange<TEntity, TProperties>> handler)
90-
where TEntity : Entity
91-
where TProperties : Properties
90+
where TEntity : Entity
91+
where TProperties : Properties
9292
{
9393
return self.Bind(entity, new AnonymousObserver<IEntityChange<TEntity, TProperties>>(handler));
9494
}

tests/CoreCraft.Generators.Tests/VerifiedFiles/ApplicationModelGeneratorTests_OneModelFileSnapshotTest_AllFeatures_g_cs.verified.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace compilation.AllFeatures
1414
{
15+
using CoreCraft;
1516
using CoreCraft.Core;
1617
using CoreCraft.ChangesTracking;
1718
using CoreCraft.Persistence;
@@ -334,6 +335,70 @@ namespace compilation.AllFeatures
334335
}
335336
}
336337

338+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("C# Source Generator", "1.0.0.0")]
339+
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
340+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
341+
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute()]
342+
internal sealed partial class FakeModelShardView : global::System.IDisposable
343+
{
344+
private bool _disposed = false;
345+
346+
public FakeModelShardView(IDomainModel model)
347+
{
348+
var builder = model.View<IFakeModelShard, IFakeChangesFrame>();
349+
350+
FirstCollection = builder.Create(static shard => shard.FirstCollection, static frame => frame.FirstCollection);
351+
SecondCollection = builder.Create(static shard => shard.SecondCollection, static frame => frame.SecondCollection);
352+
353+
OneToOneRelation = builder.Create(static shard => shard.OneToOneRelation, static frame => frame.OneToOneRelation);
354+
OneToManyRelation = builder.Create(static shard => shard.OneToManyRelation, static frame => frame.OneToManyRelation);
355+
ManyToOneRelation = builder.Create(static shard => shard.ManyToOneRelation, static frame => frame.ManyToOneRelation);
356+
ManyToManyRelation = builder.Create(static shard => shard.ManyToManyRelation, static frame => frame.ManyToManyRelation);
357+
}
358+
359+
public ICollectionView<FirstEntity, FirstEntityProperties> FirstCollection { get; private set; }
360+
public ICollectionView<SecondEntity, SecondEntityProperties> SecondCollection { get; private set; }
361+
362+
public IRelationView<FirstEntity, SecondEntity> OneToOneRelation { get; private set; }
363+
public IRelationView<FirstEntity, SecondEntity> OneToManyRelation { get; private set; }
364+
public IRelationView<SecondEntity, FirstEntity> ManyToOneRelation { get; private set; }
365+
public IRelationView<FirstEntity, SecondEntity> ManyToManyRelation { get; private set; }
366+
367+
public void Save(IRepository repository)
368+
{
369+
throw new global::System.InvalidOperationException("Cannot save model shard's view. Call Save on the real model shard.");
370+
}
371+
372+
public void Dispose()
373+
{
374+
Dispose(true);
375+
global::System.GC.SuppressFinalize(this);
376+
}
377+
378+
~FakeModelShardView()
379+
{
380+
Dispose(false);
381+
}
382+
383+
private void Dispose(bool disposing)
384+
{
385+
if (_disposed)
386+
{
387+
return;
388+
}
389+
390+
FirstCollection.Dispose();
391+
SecondCollection.Dispose();
392+
393+
OneToOneRelation.Dispose();
394+
OneToManyRelation.Dispose();
395+
ManyToOneRelation.Dispose();
396+
ManyToManyRelation.Dispose();
397+
398+
_disposed = true;
399+
}
400+
}
401+
337402
}
338403

339404
namespace compilation.AllFeatures.Entities

0 commit comments

Comments
 (0)