File: TypeAssertTest.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 (118 lines) | stat: -rw-r--r-- 3,509 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
// ****************************************************************
// 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 NUnit.Framework.Syntax;

namespace NUnit.Framework.Tests
{
	[TestFixture()]
	public class TypeAssertTests : MessageChecker
	{
		[Test]
		public void ExactType()
		{
			Expect( "Hello", TypeOf( typeof(System.String) ) );
		}

		[Test,ExpectedException(typeof(AssertionException))]
		public void ExactTypeFails()
		{
			expectedMessage =
				"  Expected: <System.Int32>" + Environment.NewLine +
				"  But was:  <System.String>" + Environment.NewLine;
			Expect( "Hello", TypeOf( typeof(System.Int32) ) );
		}

		[Test]
		public void IsInstanceOf()
		{
            ApplicationException ex = new ApplicationException();

			Assert.IsInstanceOf(typeof(System.Exception), ex );
            Expect( ex, InstanceOf(typeof(Exception)));
#if CLR_2_0 || CLR_4_0
            Assert.IsInstanceOf<Exception>( ex );
#endif
		}

		[Test,ExpectedException(typeof(AssertionException))]
		public void IsInstanceOfFails()
		{
			expectedMessage =
				"  Expected: instance of <System.Int32>" + System.Environment.NewLine + 
				"  But was:  <System.String>" + System.Environment.NewLine;
			Expect( "abc123", InstanceOf( typeof(System.Int32) ) );
		}

		[Test]
		public void IsNotInstanceOf()
		{
			Assert.IsNotInstanceOf(typeof(System.Int32), "abc123" );
			Expect( "abc123", Not.InstanceOf(typeof(System.Int32)) );
#if CLR_2_0 || CLR_4_0
            Assert.IsNotInstanceOf<System.Int32>("abc123");
#endif
		}

		[Test,ExpectedException(typeof(AssertionException))]
		public void IsNotInstanceOfFails()
		{
			expectedMessage =
				"  Expected: not instance of <System.Exception>" + System.Environment.NewLine + 
				"  But was:  <System.ApplicationException>" + System.Environment.NewLine;
			Assert.IsNotInstanceOf( typeof(System.Exception), new ApplicationException() );
		}

        [Test()]
        public void IsAssignableFrom()
        {
            int[] array10 = new int[10];

            Assert.IsAssignableFrom(typeof(int[]), array10);
            Expect(array10, AssignableFrom(typeof(int[])));
#if CLR_2_0 || CLR_4_0
            Assert.IsAssignableFrom<int[]>(array10);
#endif
        }

        [Test, ExpectedException(typeof(AssertionException))]
		public void IsAssignableFromFails()
		{
			int [] array10 = new int [10];
			int [,] array2 = new int[2,2];

			expectedMessage =
				"  Expected: assignable from <System.Int32[,]>" + System.Environment.NewLine + 
				"  But was:  <System.Int32[]>" + System.Environment.NewLine;
			Expect( array10, AssignableFrom( array2.GetType() ) );
		}

		[Test()]
		public void IsNotAssignableFrom()
		{
			int [] array10 = new int [10];

			Assert.IsNotAssignableFrom( typeof(int[,] ),array10);
			Expect( array10, Not.AssignableFrom( typeof(int[,] ) ) );
#if CLR_2_0 || CLR_4_0
            Assert.IsNotAssignableFrom<int[,]>(array10);
#endif
		}

		[Test,ExpectedException(typeof(AssertionException))]
		public void IsNotAssignableFromFails()
		{
			int [] array10 = new int [10];
			int [] array2 = new int[2];

			expectedMessage =
				"  Expected: not assignable from <System.Int32[]>" + System.Environment.NewLine + 
				"  But was:  <System.Int32[]>" + System.Environment.NewLine;
			Expect( array10, Not.AssignableFrom( array2.GetType() ) );
		}
	}
}