comparison UnitTests/CS/Aspects/MixinAspectTest.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 using System.ComponentModel;
3 using System.Data.SqlTypes;
4
5 using NUnit.Framework;
6
7 using BLToolkit.Aspects;
8 using BLToolkit.ComponentModel;
9 using BLToolkit.Reflection;
10
11 namespace Aspects
12 {
13 [TestFixture]
14 public class MixinAspectTest
15 {
16 public interface ITestInterface
17 {
18 int Test1(ref int value);
19 object Test2(ref object value);
20
21 int Test3(string p);
22 int Test4(double p);
23 int Test5 { get; }
24 int Test6 { get; }
25 }
26
27 public class TestInterfaceImpl : ITestInterface, INullable
28 {
29 int ITestInterface.Test1(ref int value) { return value; }
30 object ITestInterface.Test2(ref object value) { return value; }
31
32 int ITestInterface.Test3(string p) { return 10; }
33 int ITestInterface.Test4(double p) { return 20; }
34
35 int ITestInterface.Test5 { get { return 30; } }
36 int ITestInterface.Test6 { get { return 40; } }
37
38 bool INullable.IsNull { get { return true; } }
39 }
40
41 [Mixin(typeof(ICustomTypeDescriptor), "_typeDescriptor")]
42 [Mixin(typeof(ITestInterface), "TestInterface", "'{0}.{1}' is null.")]
43 [Mixin(typeof(INullable), "TestInterface", "'{0}.{1}' is null.")]
44 public abstract class TestClass
45 {
46 public TestClass()
47 {
48 _typeDescriptor = new CustomTypeDescriptorImpl(GetType());
49 }
50
51 protected object _typeDescriptor;
52
53 private ITestInterface _testInterface;
54 public ITestInterface TestInterface
55 {
56 get
57 {
58 if (_testInterface == null)
59 _testInterface = new TestInterfaceImpl();
60 return _testInterface;
61 }
62 }
63
64 public string Code = "code";
65
66 [MixinOverride]
67 protected int Test3(string p) { return 15; }
68 [MixinOverride(typeof(IDisposable))]
69 protected int Test4(double p) { return 25; }
70
71 protected int Test5 { [MixinOverride] get { return 35; } }
72 }
73
74 [Test]
75 public void Test1()
76 {
77 TestClass tc = (TestClass)TypeAccessor.CreateInstance(typeof(TestClass));
78 ICustomTypeDescriptor td = (ICustomTypeDescriptor)tc;
79
80 PropertyDescriptorCollection col = td.GetProperties();
81
82 Assert.AreNotEqual(0, col.Count);
83 }
84
85 [Test]
86 public void Test2()
87 {
88 TestClass tc = (TestClass)TypeAccessor.CreateInstance(typeof(TestClass));
89 ITestInterface ti = (ITestInterface)tc;
90 INullable tn = (INullable)tc;
91
92 int n = 10;
93 object o = new object();
94
95 Assert.AreEqual(10, ti.Test1(ref n));
96 Assert.AreSame (o, ti.Test2(ref o));
97 Assert.AreEqual(15, ti.Test3(null));
98 Assert.AreEqual(20, ti.Test4(0));
99 Assert.AreEqual(35, ti.Test5);
100 Assert.AreEqual(40, ti.Test6);
101 Assert.That(tn.IsNull, Is.True);
102 }
103 }
104 }