-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjusted Memento to generate the memento child class when missing (wa…
…s not possible before Metalama 2024.2) Fixed and adjusted tests Added a unit test case for when we have an autogenerated memento child class that the user is trying to use in a MementoCreateHook or MementoRestoreHook
- Loading branch information
1 parent
2672348
commit 288e8d7
Showing
11 changed files
with
93 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Moyou.Test/Memento/CreateHookAttributeTests/HasNoParameters.t.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
// Error LAMA0037 on `MementoCreateHook`: `The aspect 'MementoCreateHook' cannot be applied to the method 'HasNoParameters.CreateMementoHook()' because 'HasNoParameters.CreateMementoHook()' must have exactly one parameter.` | ||
// Error LAMA0037 on `MementoCreateHook`: `The aspect 'MementoCreateHook' cannot be applied to the method 'HasNoParameters.CreateMementoHook()' because 'HasNoParameters.CreateMementoHook()' must have exactly one parameter of the Memento type.` |
2 changes: 1 addition & 1 deletion
2
Moyou.Test/Memento/CreateHookAttributeTests/HasTooManyParameters.t.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
// Error LAMA0037 on `MementoCreateHook`: `The aspect 'MementoCreateHook' cannot be applied to the method 'HasTooManyParameters.CreateMementoHook(int, int)' because 'HasTooManyParameters.CreateMementoHook(int, int)' must have exactly one parameter.` | ||
// Error LAMA0037 on `MementoCreateHook`: `The aspect 'MementoCreateHook' cannot be applied to the method 'HasTooManyParameters.CreateMementoHook(int, int)' because 'HasTooManyParameters.CreateMementoHook(int, int)' must have exactly one parameter of the Memento type.` |
39 changes: 38 additions & 1 deletion
39
Moyou.Test/Memento/MementoAttributeTests/NoMementoNestedClass.t.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
// Error LAMA0037 on `Memento`: `The aspect 'Memento' cannot be applied to the type 'NoMementoNestedClass' because 'NoMementoNestedClass' must contain a nested private class, (struct) record or struct called 'Memento''.` | ||
// Warning MOYOU1002 on `NoMementoNestedClass`: `Class NoMementoNestedClass does not have a nested class named Memento. One will be automatically generated. Please note that if you plan on using MementoCreateHook and MementoRestoreHook attributes, you need to either define the nested class yourself or use a fully qualified name (e.g. NoMementoNestedClass.Memento) in the signature of your hook methods.` | ||
using Moyou.Aspects.Memento; | ||
namespace Moyou.CompileTimeTest.MementoTests.MementoAttributeTests; | ||
[Memento] | ||
internal class NoMementoNestedClass : global::Moyou.Aspects.Memento.IOriginator | ||
{ | ||
string A { get; set; } | ||
public global::Moyou.Aspects.Memento.IMemento CreateMemento() | ||
{ | ||
return (global::Moyou.Aspects.Memento.IMemento)this.CreateMementoImpl(); | ||
} | ||
private global::Moyou.Aspects.Memento.IMemento CreateMementoImpl() | ||
{ | ||
var memento = new global::Moyou.CompileTimeTest.MementoTests.MementoAttributeTests.NoMementoNestedClass.Memento(); | ||
memento.A = this.A; | ||
return (global::Moyou.Aspects.Memento.IMemento)memento; | ||
} | ||
public void RestoreMemento(global::Moyou.Aspects.Memento.IMemento memento) | ||
{ | ||
this.RestoreMementoImpl(memento); | ||
} | ||
private void RestoreMementoImpl(global::Moyou.Aspects.Memento.IMemento memento) | ||
{ | ||
try | ||
{ | ||
var cast = ((global::Moyou.CompileTimeTest.MementoTests.MementoAttributeTests.NoMementoNestedClass.Memento)memento); | ||
this.A = ((global::Moyou.CompileTimeTest.MementoTests.MementoAttributeTests.NoMementoNestedClass.Memento)cast!).A; | ||
} | ||
catch (global::System.InvalidCastException icex) | ||
{ | ||
throw new global::System.ArgumentException("Incorrect memento type", nameof(memento), icex); | ||
} | ||
} | ||
class Memento : global::Moyou.Aspects.Memento.IMemento | ||
{ | ||
public global::System.String A; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Moyou.Test/Memento/RestoreHookAttributeTests/HasNoParameters.t.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
// Error LAMA0037 on `Memento`: `The aspect 'Memento' cannot be applied to the type 'HasNoParameters' because 'HasNoParameters' must contain a nested private class, (struct) record or struct called 'Memento''.` | ||
// Error LAMA0037 on `MementoRestoreHook`: `The aspect 'MementoRestoreHook' cannot be applied to the method 'HasNoParameters.RestoreMementoHook()' because 'HasNoParameters.RestoreMementoHook()' must have exactly one parameter of the Memento type.` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Moyou.Test/Memento/RestoreHookAttributeTests/HasParameterOfWrongType.t.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
// Error LAMA0037 on `MementoCreateHook`: `The aspect 'MementoCreateHook' cannot be applied to the method 'HasParameterOfWrongType.CreateMementoHook(int)' because 'HasParameterOfWrongType.CreateMementoHook(int)' must have exactly one parameter of type Moyou.CompileTimeTest.MementoTests.RestoreHookAttributeTests.HasParameterOfWrongType.Memento.` | ||
// Error LAMA0037 on `MementoRestoreHook`: `The aspect 'MementoRestoreHook' cannot be applied to the method 'HasParameterOfWrongType.RestoreMementoHook(int)' because 'HasParameterOfWrongType.RestoreMementoHook(int)' must have exactly one parameter of type Moyou.CompileTimeTest.MementoTests.RestoreHookAttributeTests.HasParameterOfWrongType.Memento.` |
2 changes: 1 addition & 1 deletion
2
Moyou.Test/Memento/RestoreHookAttributeTests/HasTooManyParameters.t.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
// Error LAMA0037 on `MementoRestoreHook`: `The aspect 'MementoRestoreHook' cannot be applied to the method 'HasTooManyParameters.RestoreMementoHook(int, int, int)' because 'HasTooManyParameters.RestoreMementoHook(int, int, int)' must have exactly one parameter.` | ||
// Error LAMA0037 on `MementoRestoreHook`: `The aspect 'MementoRestoreHook' cannot be applied to the method 'HasTooManyParameters.RestoreMementoHook(int, int, int)' because 'HasTooManyParameters.RestoreMementoHook(int, int, int)' must have exactly one parameter of the Memento type.` |