~nunit-core/nunitv2/2.5

« back to all changes in this revision

Viewing changes to addins/RowTest/NUnitExtension.RowTest.Tests/RowTests.cs

  • Committer: charliepoole
  • Date: 2008-05-05 22:17:22 UTC
  • Revision ID: vcs-imports@canonical.com-20080505221722-7bdjujqed8pk6al3
Add back RowTestExtension as a separately compiled assembly, bundled
with NUnit, and modify build script to handle addins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// *********************************************************************
 
2
// Copyright 2007, Andreas Schlapsi
 
3
// This is free software licensed under the MIT license. 
 
4
// *********************************************************************
 
5
using System;
 
6
using NUnit.Framework;
 
7
using NUnitExtension.RowTest;
 
8
 
 
9
namespace NUnitExtension.RowTest.Tests
 
10
{
 
11
        [TestFixture]
 
12
        public class RowTests
 
13
        {
 
14
                private static string s_staticField;
 
15
                
 
16
                [TestFixtureSetUp]
 
17
                public void TestFixtureSetUp()
 
18
                {
 
19
                        s_staticField = "Class Member";
 
20
                }
 
21
                
 
22
                [RowTest]
 
23
                [Row("Other string", "Class Member")]
 
24
                [Row("Class Member", "Other string")]
 
25
                public void StaticFieldTest (string compareTo, string setNext)
 
26
                {
 
27
                        Assert.AreEqual (s_staticField, compareTo);
 
28
                        s_staticField = setNext;
 
29
                }
 
30
                
 
31
                [RowTest]
 
32
                [Category("Category - 1")]
 
33
                [Row( 1000, 10, 100.0000)]
 
34
                [Row(-1000, 10, -100.0000)]
 
35
                [Row( 1000, 7, 142.85715)]
 
36
                [Row( 1000, 0.00001, 100000000)]
 
37
                [Row(4195835, 3145729, 1.3338196)]
 
38
                [Row( 1000, 0, 0, ExpectedException = typeof(DivideByZeroException))]
 
39
                public void DivisionTest(double numerator, double denominator, double result)
 
40
                {
 
41
                        if (denominator == 0)
 
42
                                throw new DivideByZeroException();
 
43
                
 
44
                        Assert.AreEqual(result, numerator / denominator, 0.00001);
 
45
                }
 
46
                
 
47
                [RowTest]
 
48
                [Category("Category - 2")]
 
49
                [Row(1, 2, 3)]
 
50
                [Row(2, 3, 5)]
 
51
                [Row(3, 4, 8, TestName="Special case")]
 
52
                [Row(4, 5, 9)]
 
53
                [Row(10, 10, 0, TestName="ExceptionTest1",
 
54
                     ExpectedException=typeof(ArgumentException), ExceptionMessage="x and y may not be equal.")]
 
55
                [Row(1, 1, 0, TestName="ExceptionTest2",
 
56
                     ExpectedException=typeof(ArgumentException), ExceptionMessage="x and y may not be equal.")]
 
57
                public void AddTest(int x, int y, int expectedSum)
 
58
                {
 
59
                        int sum = Sum(x, y);
 
60
 
 
61
                        Assert.AreEqual(expectedSum, sum);
 
62
                }
 
63
                
 
64
                [RowTest]
 
65
                [Row(null)]
 
66
                public void NullArgument(string argument)
 
67
                {
 
68
                        Assert.IsNull(argument);
 
69
                }
 
70
                
 
71
                [RowTest]
 
72
                [Row(SpecialValue.Null)]
 
73
                public void SpecialValueNullArgument(string argument)
 
74
                {
 
75
                        Assert.IsNull(argument);
 
76
                }
 
77
                
 
78
                private int Sum(int x, int y)
 
79
                {
 
80
                        int sum = x + y;
 
81
                        
 
82
                        if (x == 3 && y == 4)
 
83
                                sum++;
 
84
                        
 
85
                        if (x == y)
 
86
                                throw new ArgumentException("x and y may not be equal.");
 
87
                        
 
88
                        return sum;
 
89
                }
 
90
        }
 
91
}