From ec65bf34e47b1c9b70c5d0aff018a118421cf8ab Mon Sep 17 00:00:00 2001 From: halgari Date: Mon, 11 Nov 2024 18:22:19 -0700 Subject: [PATCH] Fix broken test files --- ...sts_MyModelArrayTest.Generated.verified.cs | 73 +++++++++++++++++-- ...erator_Tests_MyModel.Generated.verified.cs | 73 +++++++++++++++++-- 2 files changed, 134 insertions(+), 12 deletions(-) diff --git a/tests/NexusMods.MnemonicDB.SourceGenerator.Tests/ArrayTest#NexusMods_MnemonicDB_SourceGenerator_Tests_MyModelArrayTest.Generated.verified.cs b/tests/NexusMods.MnemonicDB.SourceGenerator.Tests/ArrayTest#NexusMods_MnemonicDB_SourceGenerator_Tests_MyModelArrayTest.Generated.verified.cs index 99dc3f6..d2abfd3 100644 --- a/tests/NexusMods.MnemonicDB.SourceGenerator.Tests/ArrayTest#NexusMods_MnemonicDB_SourceGenerator_Tests_MyModelArrayTest.Generated.verified.cs +++ b/tests/NexusMods.MnemonicDB.SourceGenerator.Tests/ArrayTest#NexusMods_MnemonicDB_SourceGenerator_Tests_MyModelArrayTest.Generated.verified.cs @@ -26,6 +26,10 @@ namespace NexusMods.MnemonicDB.SourceGenerator.Tests; using __COMPARERS__ = NexusMods.MnemonicDB.Abstractions.ElementComparers; +/// +/// The top level model definition for the MyModelArrayTest model. This class is rarely +/// used directly, instead, the ReadOnly struct or the New class should be used. +/// public partial class MyModelArrayTest : __MODELS__.IModelFactory { @@ -115,22 +119,34 @@ public static bool TryGet(__ABSTRACTIONS__.IDb db, __ABSTRACTIONS__.EntityId id, #endregion + /// + /// Constructs a new MyModelArrayTest model from the given entity id, used to provide a typed structured + /// way to interact with the entity before it is commited to the database. + /// public partial class New : __MODELS__.ITemporaryEntity, __MODELS__.IHasEntityId { - + /// + /// Constructs a new MyModelArrayTest model from the given transaction with a generated temporary id. + /// public New(__ABSTRACTIONS__.ITransaction tx) : base() { Id = tx.TempId(); tx.Attach(this); } + /// + /// Constructs a new MyModelArrayTest model from the given transaction with the given entity id. + /// public New(__ABSTRACTIONS__.ITransaction tx, __ABSTRACTIONS__.EntityId eid) : base() { Id = eid; tx.Attach(this); } + /// + /// Adds this model to the given transaction. + /// public void AddTo(__ABSTRACTIONS__.ITransaction tx) { tx.Add(Id, NexusMods.MnemonicDB.SourceGenerator.Tests.MyModelArrayTest.MyAttribute, MyAttribute, false); @@ -162,10 +178,15 @@ public static implicit operator MyModelArrayTestId(MyModelArrayTest.New model) { #region Attributes + /// public required int[] MyAttribute { get; set; } #endregion } + /// + /// The ReadOnly struct is a read-only version of the entity, it is used to access the entity + /// in a read context. It immutable and must be reloaded to get updated data when the entity changes. + /// public readonly partial struct ReadOnly : __MODELS__.IReadOnlyModel { @@ -177,6 +198,9 @@ public static implicit operator MyModelArrayTestId(MyModelArrayTest.New model) { __SEGMENTS__.IndexSegment __MODELS__.IHasIdAndIndexSegment.IndexSegment => this.IndexSegment; + /// + /// Constructs a new ReadOnly model of the entity from the given segment and id. + /// public ReadOnly(__ABSTRACTIONS__.IDb db, __SEGMENTS__.IndexSegment segment, __ABSTRACTIONS__.EntityId id) { Db = db; Id = id; @@ -250,11 +274,13 @@ public bool Contains(IAttribute attribute) return false; } + /// public override string ToString() { return "MyModelArrayTest<" + Id + ">"; } + /// public bool IsValid() { // This is true when the struct is a default value. @@ -264,6 +290,7 @@ public bool IsValid() } + /// public int[] MyAttribute => NexusMods.MnemonicDB.SourceGenerator.Tests.MyModelArrayTest.MyAttribute.Get(this); @@ -284,6 +311,9 @@ public static implicit operator __ABSTRACTIONS__.EntityId(MyModelArrayTest.ReadO return model.Id; } + /// + /// Implicit conversion from the model to the model id. + /// public static implicit operator MyModelArrayTestId(MyModelArrayTest.ReadOnly? model) { return MyModelArrayTestId.From(model!.Value.Id); } @@ -296,8 +326,14 @@ public static implicit operator MyModelArrayTestId(MyModelArrayTest.ReadOnly? mo [global::System.Text.Json.Serialization.JsonConverter(typeof(MyModelArrayTestId.JsonConverter))] public readonly partial struct MyModelArrayTestId : IEquatable, IEquatable<__ABSTRACTIONS__.EntityId> { + /// + /// The generic EntityId value this typed id wraps. + /// public readonly __ABSTRACTIONS__.EntityId Value; + /// + /// Constructs a new MyModelArrayTestId from the given entity id. + /// public MyModelArrayTestId(__ABSTRACTIONS__.EntityId id) => Value = id; /// @@ -310,41 +346,60 @@ public static implicit operator MyModelArrayTestId(MyModelArrayTest.ReadOnly? mo /// public static MyModelArrayTestId From(ulong id) => new MyModelArrayTestId(__ABSTRACTIONS__.EntityId.From(id)); + /// + /// Implicit conversion from the model id to the entity id. + /// public static implicit operator __ABSTRACTIONS__.EntityId(MyModelArrayTestId id) => id.Value; + + /// + /// Implicit conversion from the entity id to the model id. + /// public static implicit operator MyModelArrayTestId(EntityId id) => MyModelArrayTestId.From(id); - + /// + /// Equality comparison between two MyModelArrayTestId values. + /// public bool Equals(MyModelArrayTestId other) { return Value.Value == other.Value.Value; } - + /// + /// Equality comparison between a MyModelArrayTestId and an EntityId. + /// public bool Equals(__ABSTRACTIONS__.EntityId other) { return Value.Value == other.Value; } + /// public override string ToString() { return "MyModelArrayTestId:" + Value.Value.ToString("x"); } + /// public static bool operator ==(MyModelArrayTestId left, MyModelArrayTestId right) => left.Equals(right); - + + /// public static bool operator !=(MyModelArrayTestId left, MyModelArrayTestId right) => !left.Equals(right); + /// public override bool Equals(object? obj) { return obj is MyModelArrayTestId id && Equals(id); } + /// public override int GetHashCode() { return Value.GetHashCode(); } - public class JsonConverter : global::System.Text.Json.Serialization.JsonConverter + /// + /// A JsonConverter for the MyModelArrayTestId value object. + /// + internal class JsonConverter : global::System.Text.Json.Serialization.JsonConverter { private readonly global::System.Text.Json.Serialization.JsonConverter<__ABSTRACTIONS__.EntityId> _innerConverter = new __ABSTRACTIONS__.EntityId.JsonConverter(); @@ -370,8 +425,14 @@ public override void WriteAsPropertyName(global::System.Text.Json.Utf8JsonWriter } } - +/// +/// Extension methods for the MyModelArrayTest model. +/// public static class MyModelArrayTestExtensions { + + /// + /// Adds the MyModelArrayTest model to the service collection. + /// public static __DI__.IServiceCollection AddMyModelArrayTestModel(this __DI__.IServiceCollection services) { services.AddSingleton<__ABSTRACTIONS__.IAttribute>(_ => NexusMods.MnemonicDB.SourceGenerator.Tests.MyModelArrayTest.MyAttribute); return services; diff --git a/tests/NexusMods.MnemonicDB.SourceGenerator.Tests/BasicTest#NexusMods_MnemonicDB_SourceGenerator_Tests_MyModel.Generated.verified.cs b/tests/NexusMods.MnemonicDB.SourceGenerator.Tests/BasicTest#NexusMods_MnemonicDB_SourceGenerator_Tests_MyModel.Generated.verified.cs index 057e391..5794100 100644 --- a/tests/NexusMods.MnemonicDB.SourceGenerator.Tests/BasicTest#NexusMods_MnemonicDB_SourceGenerator_Tests_MyModel.Generated.verified.cs +++ b/tests/NexusMods.MnemonicDB.SourceGenerator.Tests/BasicTest#NexusMods_MnemonicDB_SourceGenerator_Tests_MyModel.Generated.verified.cs @@ -26,6 +26,10 @@ namespace NexusMods.MnemonicDB.SourceGenerator.Tests; using __COMPARERS__ = NexusMods.MnemonicDB.Abstractions.ElementComparers; +/// +/// The top level model definition for the MyModel model. This class is rarely +/// used directly, instead, the ReadOnly struct or the New class should be used. +/// public partial class MyModel : __MODELS__.IModelFactory { @@ -115,22 +119,34 @@ public static bool TryGet(__ABSTRACTIONS__.IDb db, __ABSTRACTIONS__.EntityId id, #endregion + /// + /// Constructs a new MyModel model from the given entity id, used to provide a typed structured + /// way to interact with the entity before it is commited to the database. + /// public partial class New : __MODELS__.ITemporaryEntity, __MODELS__.IHasEntityId { - + /// + /// Constructs a new MyModel model from the given transaction with a generated temporary id. + /// public New(__ABSTRACTIONS__.ITransaction tx) : base() { Id = tx.TempId(); tx.Attach(this); } + /// + /// Constructs a new MyModel model from the given transaction with the given entity id. + /// public New(__ABSTRACTIONS__.ITransaction tx, __ABSTRACTIONS__.EntityId eid) : base() { Id = eid; tx.Attach(this); } + /// + /// Adds this model to the given transaction. + /// public void AddTo(__ABSTRACTIONS__.ITransaction tx) { tx.Add(Id, NexusMods.MnemonicDB.SourceGenerator.Tests.MyModel.Name, Name, false); @@ -162,10 +178,15 @@ public static implicit operator MyModelId(MyModel.New model) { #region Attributes + /// public required string Name { get; set; } #endregion } + /// + /// The ReadOnly struct is a read-only version of the entity, it is used to access the entity + /// in a read context. It immutable and must be reloaded to get updated data when the entity changes. + /// public readonly partial struct ReadOnly : __MODELS__.IReadOnlyModel { @@ -177,6 +198,9 @@ public static implicit operator MyModelId(MyModel.New model) { __SEGMENTS__.IndexSegment __MODELS__.IHasIdAndIndexSegment.IndexSegment => this.IndexSegment; + /// + /// Constructs a new ReadOnly model of the entity from the given segment and id. + /// public ReadOnly(__ABSTRACTIONS__.IDb db, __SEGMENTS__.IndexSegment segment, __ABSTRACTIONS__.EntityId id) { Db = db; Id = id; @@ -250,11 +274,13 @@ public bool Contains(IAttribute attribute) return false; } + /// public override string ToString() { return "MyModel<" + Id + ">"; } + /// public bool IsValid() { // This is true when the struct is a default value. @@ -264,6 +290,7 @@ public bool IsValid() } + /// public string Name => NexusMods.MnemonicDB.SourceGenerator.Tests.MyModel.Name.Get(this); @@ -284,6 +311,9 @@ public static implicit operator __ABSTRACTIONS__.EntityId(MyModel.ReadOnly model return model.Id; } + /// + /// Implicit conversion from the model to the model id. + /// public static implicit operator MyModelId(MyModel.ReadOnly? model) { return MyModelId.From(model!.Value.Id); } @@ -296,8 +326,14 @@ public static implicit operator MyModelId(MyModel.ReadOnly? model) { [global::System.Text.Json.Serialization.JsonConverter(typeof(MyModelId.JsonConverter))] public readonly partial struct MyModelId : IEquatable, IEquatable<__ABSTRACTIONS__.EntityId> { + /// + /// The generic EntityId value this typed id wraps. + /// public readonly __ABSTRACTIONS__.EntityId Value; + /// + /// Constructs a new MyModelId from the given entity id. + /// public MyModelId(__ABSTRACTIONS__.EntityId id) => Value = id; /// @@ -310,41 +346,60 @@ public static implicit operator MyModelId(MyModel.ReadOnly? model) { /// public static MyModelId From(ulong id) => new MyModelId(__ABSTRACTIONS__.EntityId.From(id)); + /// + /// Implicit conversion from the model id to the entity id. + /// public static implicit operator __ABSTRACTIONS__.EntityId(MyModelId id) => id.Value; + + /// + /// Implicit conversion from the entity id to the model id. + /// public static implicit operator MyModelId(EntityId id) => MyModelId.From(id); - + /// + /// Equality comparison between two MyModelId values. + /// public bool Equals(MyModelId other) { return Value.Value == other.Value.Value; } - + /// + /// Equality comparison between a MyModelId and an EntityId. + /// public bool Equals(__ABSTRACTIONS__.EntityId other) { return Value.Value == other.Value; } + /// public override string ToString() { return "MyModelId:" + Value.Value.ToString("x"); } + /// public static bool operator ==(MyModelId left, MyModelId right) => left.Equals(right); - + + /// public static bool operator !=(MyModelId left, MyModelId right) => !left.Equals(right); + /// public override bool Equals(object? obj) { return obj is MyModelId id && Equals(id); } + /// public override int GetHashCode() { return Value.GetHashCode(); } - public class JsonConverter : global::System.Text.Json.Serialization.JsonConverter + /// + /// A JsonConverter for the MyModelId value object. + /// + internal class JsonConverter : global::System.Text.Json.Serialization.JsonConverter { private readonly global::System.Text.Json.Serialization.JsonConverter<__ABSTRACTIONS__.EntityId> _innerConverter = new __ABSTRACTIONS__.EntityId.JsonConverter(); @@ -370,8 +425,14 @@ public override void WriteAsPropertyName(global::System.Text.Json.Utf8JsonWriter } } - +/// +/// Extension methods for the MyModel model. +/// public static class MyModelExtensions { + + /// + /// Adds the MyModel model to the service collection. + /// public static __DI__.IServiceCollection AddMyModelModel(this __DI__.IServiceCollection services) { services.AddSingleton<__ABSTRACTIONS__.IAttribute>(_ => NexusMods.MnemonicDB.SourceGenerator.Tests.MyModel.Name); return services;