1 | // ****************************************************************
|
---|
2 | // This is free software licensed under the NUnit license. You
|
---|
3 | // may obtain a copy of the license as well as information regarding
|
---|
4 | // copyright ownership at http://nunit.org/?p=license&r=2.4.
|
---|
5 | // ****************************************************************
|
---|
6 |
|
---|
7 | package NUnit.Samples;
|
---|
8 |
|
---|
9 | import System.*;
|
---|
10 | import NUnit.Framework.Assert;
|
---|
11 |
|
---|
12 | /** @attribute NUnit.Framework.TestFixture() */
|
---|
13 | public class SimpleJSharpTest
|
---|
14 | {
|
---|
15 | protected int fValue1;
|
---|
16 | protected int fValue2;
|
---|
17 |
|
---|
18 | /** @attribute NUnit.Framework.SetUp() */
|
---|
19 | public void Init()
|
---|
20 | {
|
---|
21 | fValue1 = 2;
|
---|
22 | fValue2 = 3;
|
---|
23 | }
|
---|
24 |
|
---|
25 | /** @attribute NUnit.Framework.Test() */
|
---|
26 | public void Add()
|
---|
27 | {
|
---|
28 | int result= fValue1 + fValue2;
|
---|
29 | Assert.AreEqual(6,result, "Expected Failure");
|
---|
30 | }
|
---|
31 |
|
---|
32 | /** @attribute NUnit.Framework.Test() */
|
---|
33 | public void DivideByZero()
|
---|
34 | {
|
---|
35 | int zero= 0;
|
---|
36 | int result = 8/zero;
|
---|
37 | KeepCompilerFromWarning(result); // never executed, here to avoid compiler warning that result is unused.
|
---|
38 | }
|
---|
39 |
|
---|
40 | /** @attribute NUnit.Framework.Test() */
|
---|
41 | public void Equals()
|
---|
42 | {
|
---|
43 | Assert.AreEqual(12, 12, "Integer");
|
---|
44 | Assert.AreEqual(new Long(12), new Long(13), "Long");
|
---|
45 | Assert.AreEqual('a', 'a', "Char");
|
---|
46 | Assert.AreEqual(new Integer(12), new Integer(12), "Integer Object Cast");
|
---|
47 |
|
---|
48 | Assert.AreEqual(12, 13, "Expected Failure (Integer)");
|
---|
49 | Assert.AreEqual(12.0, 11.99, 0.0, "Expected Failure (Double).");
|
---|
50 | }
|
---|
51 |
|
---|
52 | /** @attribute NUnit.Framework.Test() */
|
---|
53 | /** @attribute NUnit.Framework.Ignore("ignored test") */
|
---|
54 | public void IgnoredTest()
|
---|
55 | {
|
---|
56 | throw new InvalidCastException();
|
---|
57 | }
|
---|
58 |
|
---|
59 | // A useless function, designed to avoid a compiler warning in the the DivideByZero test.
|
---|
60 | private int KeepCompilerFromWarning(int dummy)
|
---|
61 | {
|
---|
62 | return dummy;
|
---|
63 | }
|
---|
64 |
|
---|
65 | }
|
---|