Skip to content

Commit

Permalink
Added an unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Jun 29, 2013
1 parent 592933c commit 0b6b55c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/VS 2010/KingAOP.Tests/KingAOP.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Compile Include="MethodBoundaryTests\OnEntry\Aspects.cs" />
<Compile Include="MethodBoundaryTests\OnEntry\MyTestClass.cs" />
<Compile Include="MethodBoundaryTests\OnEntry\OnEntryTests.cs" />
<Compile Include="MethodBoundaryTests\OnSuccess\Aspects.cs" />
<Compile Include="MethodBoundaryTests\OnSuccess\IncrementArgumentValueAspect.cs" />
<Compile Include="MethodBoundaryTests\OnSuccess\IncrementReturnValueAspect.cs" />
<Compile Include="MethodBoundaryTests\OnSuccess\InitTestEntityAspect.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Dynamic;
using System.Linq.Expressions;
using KingAOP.Tests.MethodInterceptionTests.OnInvoke;

namespace KingAOP.Tests.MethodBoundaryTests.OnEntry
{
Expand Down
17 changes: 17 additions & 0 deletions src/VS 2010/KingAOP.Tests/MethodBoundaryTests/OnSuccess/Aspects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using KingAOP.Aspects;

namespace KingAOP.Tests.MethodBoundaryTests.OnSuccess
{
class ChangeArgumentAspect : OnMethodBoundaryAspect
{
public override void OnSuccess(MethodExecutionArgs args)
{
for (int i = 0; i < args.Arguments.Count; i++)
{
if (args.Arguments[i] is int) args.Arguments[i] = -1;

else if (args.Arguments[i] is string) args.Arguments[i] = "I changed your value";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Dynamic;
using System.Linq.Expressions;
using KingAOP.Core;
using KingAOP.Tests.TestData;

namespace KingAOP.Tests.MethodBoundaryTests.OnSuccess
{
internal class MyTestClass : IDynamicMetaObjectProvider
{
public bool OriginalMethodCalled { get; private set; }

[IncrementReturnValueAspect]
public int ReturnArgumentValue(int number)
{
Expand All @@ -33,6 +34,12 @@ public void InitTestEntity(TestEntity testEntity)
testEntity.Number = 0;
}

[ChangeArgumentAspect]
public void MethodWithRefArgs(ref int value)
{
OriginalMethodCalled = true;
}

public DynamicMetaObject GetMetaObject(Expression parameter)
{
return new AspectWeaver(parameter, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,16 @@ public void OnSuccess_AfterCall_InitTestEntity_ShouldBeApplied_IncrementArgument
Assert.AreEqual(entity.Name, "KingAOP_OnSuccess");
Assert.AreEqual(entity.Number, 100);
}

[TestMethod]
public void IntByRefArgumentShouldBeUpdatedByAspect()
{
dynamic test = new MyTestClass();

int value = 5;
test.MethodWithRefArgs(ref value);

Assert.IsTrue(value == -1);
}
}
}

0 comments on commit 0b6b55c

Please sign in to comment.