File: ConditionAssertTests.cs

package info (click to toggle)
nunit 2.6.4+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 13,092 kB
  • ctags: 14,310
  • sloc: cs: 87,766; xml: 5,858; cpp: 512; sh: 198; makefile: 48; ansic: 8
file content (205 lines) | stat: -rw-r--r-- 5,653 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// ****************************************************************
// Copyright 2007, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org.
// ****************************************************************

using System;
using System.Collections;
using System.Threading;
using System.Globalization;
using NUnit.Framework;

namespace NUnit.Framework.Tests
{
	[TestFixture]
	public class ConditionAssertTests : MessageChecker
	{
		[Test]
		public void IsTrue()
		{
			Assert.IsTrue(true);
		}

		[Test,ExpectedException(typeof(AssertionException))]
		public void IsTrueFails()
		{
			expectedMessage =
				"  Expected: True" + Environment.NewLine +
				"  But was:  False" + Environment.NewLine;
			Assert.IsTrue(false);
		}

		[Test]
		public void IsFalse()
		{
			Assert.IsFalse(false);
		}

		[Test]
		[ExpectedException(typeof(AssertionException))]
		public void IsFalseFails()
		{
			expectedMessage =
				"  Expected: False" + Environment.NewLine +
				"  But was:  True" + Environment.NewLine;
			Assert.IsFalse(true);
		}
	
		[Test]
		public void IsNull()
		{
			Assert.IsNull(null);
		}

		[Test]
		[ExpectedException(typeof(AssertionException))]
		public void IsNullFails()
		{
			String s1 = "S1";
			expectedMessage =
				"  Expected: null" + Environment.NewLine +
				"  But was:  \"S1\"" + Environment.NewLine;
			Assert.IsNull(s1);
		}
	
		[Test]
		public void IsNotNull()
		{
			String s1 = "S1";
			Assert.IsNotNull(s1);
		}

		[Test]
		[ExpectedException(typeof(AssertionException))]
		public void IsNotNullFails()
		{
			expectedMessage =
				"  Expected: not null" + Environment.NewLine +
				"  But was:  null" + Environment.NewLine;
			Assert.IsNotNull(null);
		}
	
		[Test]
		public void IsNaN()
		{
			Assert.IsNaN(double.NaN);
		}

		[Test]
		[ExpectedException(typeof(AssertionException))]
		public void IsNaNFails()
		{
			expectedMessage =
				"  Expected: NaN" + Environment.NewLine +
				"  But was:  10.0d" + Environment.NewLine;
			Assert.IsNaN(10.0);
		}

		[Test]
		public void IsEmpty()
		{
			Assert.IsEmpty( "", "Failed on empty String" );
			Assert.IsEmpty( new int[0], "Failed on empty Array" );
			Assert.IsEmpty( new ArrayList(), "Failed on empty ArrayList" );
			Assert.IsEmpty( new Hashtable(), "Failed on empty Hashtable" );
            Assert.IsEmpty( (IEnumerable)new int[0], "Failed on empty IEnumerable");
		}

		[Test, ExpectedException(typeof(AssertionException))]
		public void IsEmptyFailsOnString()
		{
			expectedMessage =
				"  Expected: <empty>" + Environment.NewLine +
				"  But was:  \"Hi!\"" + Environment.NewLine;
			Assert.IsEmpty( "Hi!" );
		}

		[Test, ExpectedException(typeof(AssertionException))]
		public void IsEmptyFailsOnNullString()
		{
			expectedMessage =
				"  Expected: <empty>" + Environment.NewLine +
				"  But was:  null" + Environment.NewLine;
			Assert.IsEmpty( (string)null );
		}

        [Test, ExpectedException(typeof(AssertionException))]
        public void IsEmptyFailsOnNonEmptyArray()
        {
            expectedMessage =
                "  Expected: <empty>" + Environment.NewLine +
                "  But was:  < 1, 2, 3 >" + Environment.NewLine;
            Assert.IsEmpty(new int[] { 1, 2, 3 });
        }

        [Test, ExpectedException(typeof(AssertionException))]
        public void IsEmptyFailsOnNonEmptyIEnumerable()
        {
            expectedMessage =
                "  Expected: <empty>" + Environment.NewLine +
                "  But was:  < 1, 2, 3 >" + Environment.NewLine;
            Assert.IsEmpty((IEnumerable)new int[] { 1, 2, 3 });
        }

        [Test]
		public void IsNotEmpty()
		{
			int[] array = new int[] { 1, 2, 3 };
			ArrayList list = new ArrayList( array );
			Hashtable hash = new Hashtable();
			hash.Add( "array", array );

			Assert.IsNotEmpty( "Hi!", "Failed on String" );
			Assert.IsNotEmpty( array, "Failed on Array" );
			Assert.IsNotEmpty( list, "Failed on ArrayList" );
			Assert.IsNotEmpty( hash, "Failed on Hashtable" );
            Assert.IsNotEmpty((IEnumerable)array, "Failed on IEnumerable");
		}

		[Test, ExpectedException(typeof(AssertionException))]
		public void IsNotEmptyFailsOnEmptyString()
		{
			expectedMessage =
				"  Expected: not <empty>" + Environment.NewLine +
				"  But was:  <string.Empty>" + Environment.NewLine;
			Assert.IsNotEmpty( "" );
		}

		[Test, ExpectedException(typeof(AssertionException))]
		public void IsNotEmptyFailsOnEmptyArray()
		{
			expectedMessage =
				"  Expected: not <empty>" + Environment.NewLine +
				"  But was:  <empty>" + Environment.NewLine;
			Assert.IsNotEmpty( new int[0] );
		}

		[Test, ExpectedException(typeof(AssertionException))]
		public void IsNotEmptyFailsOnEmptyArrayList()
		{
			expectedMessage =
				"  Expected: not <empty>" + Environment.NewLine +
				"  But was:  <empty>" + Environment.NewLine;
			Assert.IsNotEmpty( new ArrayList() );
		}

        [Test, ExpectedException(typeof(AssertionException))]
        public void IsNotEmptyFailsOnEmptyHashTable()
        {
            expectedMessage =
                "  Expected: not <empty>" + Environment.NewLine +
                "  But was:  <empty>" + Environment.NewLine;
            Assert.IsNotEmpty(new Hashtable());
        }

        [Test, ExpectedException(typeof(AssertionException))]
        public void IsNotEmptyFailsOnEmptyIEnumerable()
        {
            expectedMessage =
                "  Expected: not <empty>" + Environment.NewLine +
                "  But was:  <empty>" + Environment.NewLine;
            Assert.IsNotEmpty((IEnumerable)new int[0]);
        }
    }
}