diff --git a/external/FluentIL b/external/FluentIL index 6140c539..6a54939a 160000 --- a/external/FluentIL +++ b/external/FluentIL @@ -1 +1 @@ -Subproject commit 6140c5396e5358c16e72b69ec85b370a9e92a1ea +Subproject commit 6a54939a739f15474f63b1575b059a152db675f3 diff --git a/src/AspectInjector/Program.cs b/src/AspectInjector/Program.cs index 2dfdb077..c4ec3f08 100644 --- a/src/AspectInjector/Program.cs +++ b/src/AspectInjector/Program.cs @@ -56,11 +56,11 @@ private static int Main(string[] args) private static void AttachDebugger() { - Console.WriteLine("DEBUG MODE!!! Waiting 20 sec for debugger to attach!"); + Console.WriteLine("DEBUG MODE!!! Waiting 10 sec for debugger to attach!"); Console.WriteLine($"Process id is '{Process.GetCurrentProcess().Id}'"); Debugger.Launch(); var c = 0; - while (!Debugger.IsAttached && c < 20) + while (!Debugger.IsAttached && c < 10) { Thread.Sleep(1000); Console.Write("."); diff --git a/tests/AspectInjector.Tests.Runtime/Interfaces/GeneralTests.cs b/tests/AspectInjector.Tests.Runtime/Interfaces/GeneralTests.cs index 91014b27..c50fd21c 100644 --- a/tests/AspectInjector.Tests.Runtime/Interfaces/GeneralTests.cs +++ b/tests/AspectInjector.Tests.Runtime/Interfaces/GeneralTests.cs @@ -32,7 +32,7 @@ public void Interfaces_InjectAspectReference_SecondConstructor() int out2; Checker.Passed = false; - var result = ((IGeneralTests)new GeneralTests_Target(1)).Fact("ok", 1, ref ref1, out out1, ref ref2, out out2); + var result = ((IGeneralTests)new GeneralTests_Target(1)).Fact("ok", 1, ref ref1, out out1, ref ref2, out out2, StringSplitOptions.None); Assert.Equal("ok", result); Assert.True(Checker.Passed); } @@ -46,7 +46,7 @@ public void Interfaces_InjectMethodProxy() int out2; Checker.Passed = false; - var result = _testClass.Fact("ok", 1, ref ref1, out out1, ref ref2, out out2); + var result = _testClass.Fact("ok", 1, ref ref1, out out1, ref ref2, out out2, StringSplitOptions.RemoveEmptyEntries); Assert.Equal("ok", result); Assert.True(Checker.Passed); } @@ -106,7 +106,7 @@ public void Do() internal interface IGeneralTests { - string Fact(string data, int value, ref object testRef, out object testOut, ref int testRefValue, out int testOutValue); + string Fact(string data, int value, ref object testRef, out object testOut, ref int testRefValue, out int testOutValue, StringSplitOptions stringSplit); event EventHandler TestEvent; @@ -125,7 +125,7 @@ public class GeneralTests_Aspect : IGeneralTests, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged = (s, e) => { }; - string IGeneralTests.Fact(string data, int value, ref object testRef, out object testOut, ref int testRefValue, out int testOutValue) + string IGeneralTests.Fact(string data, int value, ref object testRef, out object testOut, ref int testRefValue, out int testOutValue, StringSplitOptions stringSplit) { Checker.Passed = true; testOut = new object(); diff --git a/tests/AspectInjector.Tests.Runtime/Issues/0123.cs b/tests/AspectInjector.Tests.Runtime/Issues/0123.cs new file mode 100644 index 00000000..cee3cd51 --- /dev/null +++ b/tests/AspectInjector.Tests.Runtime/Issues/0123.cs @@ -0,0 +1,77 @@ +using AspectInjector.Broker; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace AspectInjector.Tests.Runtime.Issues +{ + + public class Issue_0123 + { + [Fact] + public void Fixed() + { + Checker.Passed = false; + new HomeController().ActionOnlyAdminsCanDo().Wait(); + Assert.True(Checker.Passed); + } + + public enum UserRole + { + Guest, + Normal, + Admin, + } + + public enum UserRole2 : byte + { + Guest, + Normal, + Admin, + } + + public enum UserRole3 : long + { + Guest = long.MaxValue, + Normal = 1, + Admin = 2, + } + + public class HomeController + { + [CheckPrivileges(new UserRole[] { UserRole.Admin }, new UserRole2[] { UserRole2.Admin }, new UserRole3[] { UserRole3.Guest })] + public async Task ActionOnlyAdminsCanDo() + { + await Task.Delay(100); + } + } + + [Injection(typeof(CheckPrivilegesAspect))] + [AttributeUsage(AttributeTargets.Method)] + public sealed class CheckPrivileges : Attribute + { + public UserRole[] Roles { get; } + + public CheckPrivileges(UserRole[] roles, UserRole2[] roles2, UserRole3[] role3s) + { + Roles = roles; + } + } + + [Aspect(Scope.PerInstance)] + public class CheckPrivilegesAspect + { + [Advice(Kind.Before)] + public void Before([Argument(Source.Triggers)] Attribute[] attributes) + { + if (attributes[0] is CheckPrivileges cp && cp.Roles.Contains(UserRole.Admin)) + Checker.Passed = true; + } + } + } +}