comparison UnitTests/CS/Common/NameOrIndexParameterTest.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.Common;
6
7 namespace Common
8 {
9 [TestFixture]
10 public class NameOrIndexParameterTest
11 {
12 [Test]
13 public void DefaultValueTest()
14 {
15 int expectedValue = 0;
16 NameOrIndexParameter nip = new NameOrIndexParameter();
17 Assert.IsFalse(nip.ByName);
18 Assert.AreEqual(nip.Index, expectedValue);
19 }
20
21 [Test]
22 public void StringTest()
23 {
24 string expectedValue = "54321";
25 NameOrIndexParameter nip = "54321";
26 Assert.IsTrue(nip.ByName);
27 Assert.AreEqual(nip.Name, expectedValue);
28 }
29
30 [Test]
31 public void IntTest()
32 {
33 int expectedValue = 12345;
34 NameOrIndexParameter nip = 12345;
35 Assert.IsFalse(nip.ByName);
36 Assert.AreEqual(nip.Index, expectedValue);
37 }
38
39 [Test]
40 public void ArrayTest()
41 {
42 NameOrIndexParameter[] nips = new NameOrIndexParameter[]{ 12345, "54321" };
43 Assert.AreEqual(nips[0].Index, 12345);
44 Assert.AreEqual(nips[1].Name, "54321");
45 }
46
47 [Test]
48 public void StringArrayTest()
49 {
50 NameOrIndexParameter[] nips = NameOrIndexParameter.FromStringArray(new string[] { "98765", "54321" });
51 Assert.AreEqual(nips[0].Name, "98765");
52 Assert.AreEqual(nips[1].Name, "54321");
53 }
54
55 [Test]
56 public void IntArrayTest()
57 {
58 NameOrIndexParameter[] nips = NameOrIndexParameter.FromIndexArray(new int[] { 12345, 56789 });
59 Assert.AreEqual(nips[0].Index, 12345);
60 Assert.AreEqual(nips[1].Index, 56789);
61 }
62
63 [Test, ExpectedException(typeof(ArgumentNullException))]
64 public void IllegalStringTest()
65 {
66 NameOrIndexParameter nip = null;
67 }
68
69 [Test, ExpectedException(typeof(ArgumentException))]
70 public void IllegalStringTest2()
71 {
72 NameOrIndexParameter nip = string.Empty;
73 }
74
75 [Test, ExpectedException(typeof(ArgumentException))]
76 public void IllegalIntTest()
77 {
78 NameOrIndexParameter nip = -12345;
79 }
80
81 [Test, ExpectedException(typeof(InvalidOperationException))]
82 public void IllegalAccessTest()
83 {
84 // Init by index
85 NameOrIndexParameter nip = 12345;
86 Assert.IsFalse(nip.ByName);
87
88 // Exception here
89 string value = nip.Name;
90 }
91
92 [Test, ExpectedException(typeof(InvalidOperationException))]
93 public void IllegalAccessTest2()
94 {
95 // Init by name
96 NameOrIndexParameter nip = "54321";
97 Assert.IsTrue(nip.ByName);
98
99 // Exception here
100 int value = nip.Index;
101 }
102
103 public static object SomeFunc(NameOrIndexParameter nip)
104 {
105 if (nip.ByName)
106 {
107 return nip.Name;
108 }
109 else
110 {
111 return nip.Index;
112 }
113 }
114
115 [Test]
116 public void FunctionTest()
117 {
118 int expectedValue = 12345;
119 object o = SomeFunc(12345);
120 Assert.AreEqual(o, expectedValue);
121 }
122
123 [Test]
124 public void FunctionTest2()
125 {
126 string expectedValue = "54321";
127 object o = SomeFunc("54321");
128 Assert.AreEqual(o, expectedValue);
129 }
130 }
131 }