Skip to content

Commit

Permalink
fixed #123
Browse files Browse the repository at this point in the history
  • Loading branch information
pamidur committed Feb 18, 2020
1 parent 7152872 commit bc35d88
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
2 changes: 1 addition & 1 deletion external/FluentIL
4 changes: 2 additions & 2 deletions src/AspectInjector/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(".");
Expand Down
8 changes: 4 additions & 4 deletions tests/AspectInjector.Tests.Runtime/Interfaces/GeneralTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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<EventArgs> TestEvent;

Expand All @@ -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();
Expand Down
77 changes: 77 additions & 0 deletions tests/AspectInjector.Tests.Runtime/Issues/0123.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}

0 comments on commit bc35d88

Please sign in to comment.