using System;
using NUnit.Framework;
using BLToolkit.Aspects;
using BLToolkit.Reflection;
namespace HowTo.Aspects
{
[TestFixture]
public class MixinAspectTest
{
public interface ITestInterface1
{
int TestMethod(int value);
}
public class TestInterface1Impl : ITestInterface1
{
public int TestMethod(int value) { return value; }
}
public interface ITestInterface2
{
int TestMethod1(int value);
int TestMethod2(int value);
}
public class TestInterface2Impl : ITestInterface2
{
public int TestMethod1(int value) { return value; }
public int TestMethod2(int value) { return value; }
}
[Mixin(typeof(ITestInterface1), "_testInterface1")]
[Mixin(typeof(ITestInterface2), "TestInterface2", "'{0}.{1}' is null.")]
public abstract class TestClass
{
public TestClass()
{
_testInterface1 = new TestInterface1Impl();
}
protected object _testInterface1;
private ITestInterface2 _testInterface2;
public ITestInterface2 TestInterface2
{
get { return _testInterface2 ?? (_testInterface2 = new TestInterface2Impl()); }
}
[MixinOverride(typeof(ITestInterface2))]
protected int TestMethod1(int value) { return 15; }
}
[Test]
public void Test()
{
TestClass tc = TypeAccessor<TestClass>.CreateInstance();
ITestInterface1 i1 = (ITestInterface1)tc;
ITestInterface2 i2 = (ITestInterface2)tc;
Assert.AreEqual(10, i1.TestMethod (10));
Assert.AreEqual(15, i2.TestMethod1(20));
Assert.AreEqual(30, i2.TestMethod2(30));
}
}
} |