File: ListContentsTests.cs

package info (click to toggle)
nunit 2.6.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, 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 (82 lines) | stat: -rw-r--r-- 2,315 bytes parent folder | download | duplicates (4)
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
// ****************************************************************
// 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 NUnit.Framework;

namespace NUnit.Framework.Tests
{
	/// <summary>
	/// Summary description for ListContentsTests.
	/// </summary>
	[TestFixture]
	public class ListContentsTests : MessageChecker
	{
		private static readonly object[] testArray = { "abc", 123, "xyz" };

		[Test]
		public void ArraySucceeds()
		{
			Assert.Contains( "abc", testArray );
			Assert.Contains( 123, testArray );
			Assert.Contains( "xyz", testArray );
		}

		[Test,ExpectedException(typeof(AssertionException))]
		public void ArrayFails()
		{
			expectedMessage =
				"  Expected: collection containing \"def\"" + Environment.NewLine + 
				"  But was:  < \"abc\", 123, \"xyz\" >" + Environment.NewLine;	
			Assert.Contains("def", testArray);
		}

		[Test,ExpectedException(typeof(AssertionException))]
		public void EmptyArrayFails()
		{
			expectedMessage =
				"  Expected: collection containing \"def\"" + Environment.NewLine + 
				"  But was:  <empty>" + Environment.NewLine;	
			Assert.Contains( "def", new object[0] );
		}

		[Test,ExpectedException(typeof(ArgumentException))]
		public void NullArrayIsError()
		{
			Assert.Contains( "def", null );
		}

		[Test]
		public void ArrayListSucceeds()
		{
			ArrayList list = new ArrayList( testArray );

			Assert.Contains( "abc", list );
			Assert.Contains( 123, list );
			Assert.Contains( "xyz", list );
		}

		[Test,ExpectedException(typeof(AssertionException))]
		public void ArrayListFails()
		{
			expectedMessage =
				"  Expected: collection containing \"def\"" + Environment.NewLine + 
				"  But was:  < \"abc\", 123, \"xyz\" >" + Environment.NewLine;
			Assert.Contains( "def", new ArrayList( testArray ) );
		}

		[Test]
		public void DifferentTypesMayBeEqual()
		{
			// TODO: Better message for this case
			expectedMessage =
				"  Expected: collection containing 123.0d" + Environment.NewLine + 
				"  But was:  < \"abc\", 123, \"xyz\" >" + Environment.NewLine;
			Assert.Contains( 123.0, new ArrayList( testArray ) );
		}
	}
}