comparison HowTo/TypeBuilder/InitialValues.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.Reflection;
6 using BLToolkit.TypeBuilder;
7
8 namespace HowTo.TypeBuilder
9 {
10 [TestFixture]
11 public class InitialValueTest
12 {
13 [AttributeUsage(AttributeTargets.Property)]
14 public class NewGuidParameterAttribute : /*[a]*/ParameterAttribute/*[/a]*/
15 {
16 public NewGuidParameterAttribute() : base(/*[a]*/Guid.NewGuid().ToByteArray()/*[/a]*/)
17 {
18 }
19 }
20
21 public abstract class TestObject1
22 {
23 /*[a]*/[Parameter("t")]/*[/a]*/ public abstract string Str { get; set; }
24 /*[a]*/[Parameter(20)]/*[/a]*/ public abstract string this[int i] { get; set; }
25 /*[a]*/[Parameter(54)]/*[/a]*/ public abstract int Int { get; set; }
26 /*[a]*/[Parameter(2,2,2)]/*[/a]*/ public abstract DateTime Date { get; set; }
27 /*[a]*/[Parameter(222L)]/*[/a]*/ public abstract Decimal Decimal1 { get; set; }
28 /*[a]*/[Parameter(-2.05)]/*[/a]*/ public abstract Decimal Decimal2 { get; set; }
29 /*[a]*/[NewGuidParameter]/*[/a]*/ public abstract Guid Guid { get; set; }
30 }
31
32 [Test]
33 public void Test()
34 {
35 TestObject1 o = (TestObject1)TypeAccessor.CreateInstance(typeof(TestObject1));
36
37 Assert.That(o.Str, Is.EqualTo("t"));
38 Assert.That(o.Int, Is.EqualTo(54));
39 Assert.That(o.Date, Is.EqualTo(new DateTime(2,2,2)));
40 Assert.That(o.Decimal1, Is.EqualTo(222m));
41 Assert.That(o.Decimal2, Is.EqualTo(-2.05m));
42 Assert.That(o.Guid, Is.Not.EqualTo(Guid.Empty));
43 }
44 }
45 }