domsinclair
domsinclair
MCMetalama Community
Created by Whit on 9/3/2023 in #technical-questions
Unable to get aspect testing to work
I find it easier to set the test project up (and include the metalama testing nuget first (but realistically that shouldn't make too much of a difference when you add it , just as long as you do). However where you source your 'compiled' code from will make a difference. If you haven't watched it yet then I recomend looking at this video ( https://doc.metalama.net/videos/testing ). Note the recomendation to run the test first so that it fails and then use the code that the failed test message expects to see as the 'compiled' code that you add to the .t.cs file.
Lastly it might pay you to go back to xUnit 2.5. Not sure if 2.51 has been tested yet with metalama.
41 replies
MCMetalama Community
Created by domsinclair on 6/23/2023 in #technical-questions
Follow up question from yesterday's meetup
That's my current line of thinking. I'll have to build some more tests into the app to cover those scenarios and see what comes out of them.
5 replies
MCMetalama Community
Created by domsinclair on 6/23/2023 in #technical-questions
Follow up question from yesterday's meetup
Thanks Daniel
5 replies
MCMetalama Community
Created by domsinclair on 6/12/2023 in #technical-questions
Ordering Aspects
What seemed illogical were the error messages. I guess I would have expected two in the first and just one in the second.
6 replies
MCMetalama Community
Created by domsinclair on 6/12/2023 in #technical-questions
Ordering Aspects
Hopefully that has come through, turns ourt that a 2000 character limit can be a little limiting!
6 replies
MCMetalama Community
Created by domsinclair on 6/12/2023 in #technical-questions
Ordering Aspects
[assembly: AspectOrder(typeof(TimedLogMethodAttribute), typeof(RetryAttribute))] 10:40:14.424 +01:00 [Information] Application Starting 10:40:14.565 +01:00 [Information] Entering Calculator.Subtract with these parameters: {"Type = double: Parameter Name = a": 3, "Type = double: Parameter Name = b": 2} 10:40:14.591 +01:00 [Information] Leaving Calculator.Subtract with the following result: 1 10:40:14.598 +01:00 [Information] Calculator.Subtract took 6 ms to complete. 10:40:14.601 +01:00 [Information] Entering Calculator.Multiply with these parameters: {"Type = double: Parameter Name = a": 3, "Type = double: Parameter Name = b": 2} 10:40:14.606 +01:00 [Information] Leaving Calculator.Multiply with the following result: 6 10:40:14.608 +01:00 [Information] Calculator.Multiply took 1 ms to complete. 10:40:14.626 +01:00 [Information] Entering Calculator.Add with these parameters: {"Type = double: Parameter Name = a": 3, "Type = double: Parameter Name = b": 2} 10:40:14.770 +01:00 [Error] An error thrown by retry attribute, Calculator.Add has failed withe the following error System.InvalidOperationException: Operation is not valid due to the current state of the object. at VtlSoftware.MultiAspects.ConsoleApp.Calculator.<>cDisplayClass2_0.<Add>gExecuteCore|0() in D:\source\repos\VtlSoftware.MultiAspectSolution\VtlSoftware.MultiAspects.ConsoleApp\Calculator.cs:line 28
6 replies
MCMetalama Community
Created by domsinclair on 6/12/2023 in #technical-questions
This error has me foxed
No, once I'd deleted the temp file in the Metalama DI folder the problem disappeared. The most common times that I see this though seem to relate to using DI. One other point worth noting is that The only sure fire way I have come across to delete said file is to do so immediately after a restart, but that should come with a healthy caveat of I often have a lot of stuff open and running at any one time.
4 replies
MCMetalama Community
Created by domsinclair on 6/12/2023 in #technical-questions
This error has me foxed
Deleting the relevant temp file solves the issue, but not sure what triggered it in the first place.
4 replies
MCMetalama Community
Created by domsinclair on 6/5/2023 in #technical-questions
Testing Fabrics
Yes, certainly.
14 replies
MCMetalama Community
Created by domsinclair on 6/8/2023 in #technical-questions
AddAspect Refactoring
The project is on github if you want to have a look yourself. Certainly if you add the line:
c#
builder.MustNotHaveAspectOfType(typeof(NoLogAttribute));
c#
builder.MustNotHaveAspectOfType(typeof(NoLogAttribute));
to the BuildEligibility method of either the LogMethodAttribute or the TimedLogMethodAttribute then it will fail with that LAMA error, but as you pointed out to me last week in this context AspectOfType is specifically referring to metalama aspects. Conceivably It shouldn't fall over because of that which in turn makes it a bug, but equally I should have known better than to type what I did. Catch 22? https://github.com/domsinclair/VtlSoftware.LoggingAspects
13 replies
MCMetalama Community
Created by domsinclair on 6/8/2023 in #technical-questions
AddAspect Refactoring
It's not a bug, it's my own stupid fault. The error was one I've made before. The cause was [NoLogAttribute] which is not technically a metalama aspect. I'm tempted to say that MustNotHaveAspectOfType and its partner MustHaveAspectOfType should both be renamed to: MustNotHaveMetalamaAspectOfType and MustHaveMetalamaAspectOfType That or make sure it's very clearly defined in the code comment so that intellisense picks it up.
13 replies
MCMetalama Community
Created by domsinclair on 6/8/2023 in #technical-questions
AddAspect Refactoring
System.InvalidOperationException: Operation is not valid due to the current state of the object. at Metalama.Framework.Engine.Utilities.UserCode.UserCodeExecutionContext.get_CompilationContext() at Metalama.Framework.Engine.Utilities.UserCode.UserCodeExecutionContext.ResolveCompileTimeTypeOf(String id, IReadOnlyDictionary2 substitutions) at VtlSoftware.Logging.LogMethodAttribute.BuildEligibility(IEligibilityBuilder1 builder) in C:\Users\dom\AppData\Local\Temp\Metalama\CompileTime\VtlSoftware.Logging.netcoreapp6.0\024aaf5bfa13ba0f\2023.1.5-preview\LogMethodAt_f67819f8.cs:line 51 at Metalama.Framework.Engine.Utilities.UserCode.UserCodeInvoker.<>cDisplayClass5_0.<TryInvoke>b0() at Metalama.Framework.Engine.Utilities.UserCode.UserCodeInvoker.Invoke[TResult,TPayload](UserCodeFunc2 func, TPayload& payload, UserCodeExecutionContext context) at Metalama.Framework.Engine.Utilities.UserCode.UserCodeInvoker.Invoke[T](Func1 func, UserCodeExecutionContext context) at Metalama.Framework.Engine.Utilities.UserCode.UserCodeInvoker.TryInvoke[T](Func`1 func, UserCodeExecutionContext context, T& result)
13 replies
MCMetalama Community
Created by domsinclair on 6/8/2023 in #technical-questions
AddAspect Refactoring
InvalidOperationException
13 replies
MCMetalama Community
Created by domsinclair on 6/8/2023 in #technical-questions
AddAspect Refactoring
That's interesting I get a Lama0042 error
13 replies
MCMetalama Community
Created by domsinclair on 6/5/2023 in #technical-questions
Testing Fabrics
Your right about it being a small note, however let's see if I can make sense of it. This was the first test that I created;
c#
using Metalama.Framework.Aspects;
using Metalama.Framework.Code;
using Metalama.Framework.Fabrics;

namespace VtlSoftware.Logging.Tests
{
internal class LogAllPublicMethodsTest1
{
#region Private Methods
private void DoSomethingElse()
{
}

#endregion

#region Public Methods
public int Add(int a, int b) { return a + b; }
public void DoSomething()
{
}

#endregion
}

internal class Fabric : ProjectFabric
{
#region Public Methods
public override void AmendProject(IProjectAmender amender) { amender.LogAllPublicMethods(); }

#endregion
}

[CompileTime]
public static class FabricExtensions
{
#region Public Methods

public static void LogAllPublicMethods(this IProjectAmender amender)
{
amender.Outbound
.SelectMany(compilation => compilation.AllTypes)
.Where(
type => type.Accessibility is Accessibility.Public or Accessibility.Internal &&
!type.IsStatic ||
type.Attributes.OfAttributeType(typeof(NoLogAttribute)).Any())
.SelectMany(type => type.Methods)
.Where(method => method.Accessibility is Accessibility.Public && method.Name != "ToString")
.AddAspectIfEligible<LogMethodAttribute>();
}

#endregion
}
}
c#
using Metalama.Framework.Aspects;
using Metalama.Framework.Code;
using Metalama.Framework.Fabrics;

namespace VtlSoftware.Logging.Tests
{
internal class LogAllPublicMethodsTest1
{
#region Private Methods
private void DoSomethingElse()
{
}

#endregion

#region Public Methods
public int Add(int a, int b) { return a + b; }
public void DoSomething()
{
}

#endregion
}

internal class Fabric : ProjectFabric
{
#region Public Methods
public override void AmendProject(IProjectAmender amender) { amender.LogAllPublicMethods(); }

#endregion
}

[CompileTime]
public static class FabricExtensions
{
#region Public Methods

public static void LogAllPublicMethods(this IProjectAmender amender)
{
amender.Outbound
.SelectMany(compilation => compilation.AllTypes)
.Where(
type => type.Accessibility is Accessibility.Public or Accessibility.Internal &&
!type.IsStatic ||
type.Attributes.OfAttributeType(typeof(NoLogAttribute)).Any())
.SelectMany(type => type.Methods)
.Where(method => method.Accessibility is Accessibility.Public && method.Name != "ToString")
.AddAspectIfEligible<LogMethodAttribute>();
}

#endregion
}
}
I currently have seven fabric extensions that I'd like to test, and to do that properly I'd need to have a variety of different class signatures and method signatures for them to run over.
I now know that I can create separate tests for each scenario, I'm wondering if your suggestion would allow them all to be tested at once in some way.
14 replies
MCMetalama Community
Created by domsinclair on 6/5/2023 in #technical-questions
Testing Fabrics
@addabis I have a whole set of fabric extensions that I'd like to test, so it may well be that your suggestion would make eminent sense in this case. Is there an example of that anywhere in the documentation?
14 replies
MCMetalama Community
Created by domsinclair on 6/5/2023 in #technical-questions
Testing Fabrics
Indeed that does seem to work, thanks.
14 replies
MCMetalama Community
Created by domsinclair on 6/2/2023 in #technical-questions
Eligibility MustNotHaveAspectOfType
That makes sense, the aspect I'm looking for is essentially a blank [NoLog] job that inherits from Attribute not aspect.
6 replies
MCMetalama Community
Created by domsinclair on 5/31/2023 in #technical-questions
Testing Issue
That makes perfect sense, Thanks.
11 replies
MCMetalama Community
Created by domsinclair on 5/31/2023 in #technical-questions
Testing Issue
Well I'm well and truly at a loss with this. I'm building out a series of tests to test various possibilities that my logging aspect might encounter.
If I create methods with params and return values to log the test passes, but if it's just a void method it fails. The issue I'm facing is that I would expect the reason being given for failure to be equally applicable to a method with params and yet its not. I suspect that this is my own fault but at the same time I can't account for the discrepancy.
11 replies