comparison HowTo/Aspects/MixinAspect.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2
3 using NUnit.Framework;
4
5 using BLToolkit.Aspects;
6 using BLToolkit.Reflection;
7
8 namespace HowTo.Aspects
9 {
10 [TestFixture]
11 public class MixinAspectTest
12 {
13 public interface ITestInterface1
14 {
15 int TestMethod(int value);
16 }
17
18 public class TestInterface1Impl : ITestInterface1
19 {
20 public int TestMethod(int value) { return value; }
21 }
22
23 public interface ITestInterface2
24 {
25 int TestMethod1(int value);
26 int TestMethod2(int value);
27 }
28
29 public class TestInterface2Impl : ITestInterface2
30 {
31 public int TestMethod1(int value) { return value; }
32 public int TestMethod2(int value) { return value; }
33 }
34
35 [/*[a]*/Mixin/*[/a]*/(/*[a]*/typeof/*[/a]*/(/*[a]*/ITestInterface1/*[/a]*/), /*[a]*/"_testInterface1"/*[/a]*/)]
36 [/*[a]*/Mixin/*[/a]*/(/*[a]*/typeof/*[/a]*/(/*[a]*/ITestInterface2/*[/a]*/), /*[a]*/"TestInterface2"/*[/a]*/, "'{0}.{1}' is null.")]
37 public /*[a]*/abstract/*[/a]*/ class TestClass
38 {
39 public TestClass()
40 {
41 /*[a]*/_testInterface1/*[/a]*/ = new /*[a]*/TestInterface1Impl/*[/a]*/();
42 }
43
44 /*[a]*/protected/*[/a]*/ /*[a]*/object/*[/a]*/ /*[a]*/_testInterface1/*[/a]*/;
45
46 private ITestInterface2 _testInterface2;
47 public /*[a]*/ITestInterface2/*[/a]*/ /*[a]*/TestInterface2/*[/a]*/
48 {
49 get { return _testInterface2 ?? (_testInterface2 = new /*[a]*/TestInterface2Impl/*[/a]*/()); }
50 }
51
52 [/*[a]*/MixinOverride/*[/a]*/(typeof(/*[a]*/ITestInterface2/*[/a]*/))]
53 protected int TestMethod1(int value) { return /*[a]*/15/*[/a]*/; }
54 }
55
56 [Test]
57 public void Test()
58 {
59 TestClass tc = /*[a]*/TypeAccessor/*[/a]*/<TestClass>.CreateInstance();
60 ITestInterface1 i1 = (ITestInterface1)tc;
61 ITestInterface2 i2 = (ITestInterface2)tc;
62
63 Assert.AreEqual(/*[a]*/10/*[/a]*/, i1.TestMethod (/*[a]*/10/*[/a]*/));
64 Assert.AreEqual(/*[a]*/15/*[/a]*/, i2.TestMethod1(/*[a]*/20/*[/a]*/));
65 Assert.AreEqual(/*[a]*/30/*[/a]*/, i2.TestMethod2(/*[a]*/30/*[/a]*/));
66 }
67 }
68 }