~nunit-core/nunitv2/2.5

« back to all changes in this revision

Viewing changes to addins/RowTest/NUnitExtension.RowTest.AddIn/RowTestFactory.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 System.Reflection;
 
7
using NUnit.Core;
 
8
 
 
9
namespace NUnitExtension.RowTest.AddIn
 
10
{
 
11
        public class RowTestFactory
 
12
        {
 
13
                public RowTestFactory()
 
14
                {
 
15
                }
 
16
                
 
17
                public RowTestSuite CreateRowTestSuite(MethodInfo method)
 
18
                {
 
19
                        if (method == null)
 
20
                                throw new ArgumentNullException("method");
 
21
                        
 
22
                        RowTestSuite testSuite = new RowTestSuite(method);
 
23
                        NUnitFramework.ApplyCommonAttributes(method, testSuite);
 
24
                        
 
25
                        return testSuite;
 
26
                }
 
27
                
 
28
                public RowTestCase CreateRowTestCase(Attribute row, MethodInfo method)
 
29
                {
 
30
                        if (row == null)
 
31
                                throw new ArgumentNullException("row");
 
32
                        
 
33
                        if (method == null)
 
34
                                throw new ArgumentNullException("method");
 
35
                        
 
36
                        object[] rowArguments = RowTestFramework.GetRowArguments(row);
 
37
                        rowArguments = FilterSpecialValues(rowArguments);
 
38
                        
 
39
                        string testName = RowTestFramework.GetTestName(row);
 
40
                        Type expectedExceptionType = RowTestFramework.GetExpectedExceptionType(row);
 
41
                        
 
42
                        RowTestCase testCase = new RowTestCase(method, testName, rowArguments);
 
43
                        if (expectedExceptionType != null)
 
44
                        {
 
45
                                testCase.ExceptionExpected = true;
 
46
                                testCase.ExpectedExceptionType = expectedExceptionType;
 
47
                                testCase.ExpectedMessage = RowTestFramework.GetExpectedExceptionMessage(row);
 
48
                        }
 
49
 
 
50
                        return testCase;
 
51
                }
 
52
                
 
53
                private object[] FilterSpecialValues(object[] arguments)
 
54
                {
 
55
                        if (arguments == null)
 
56
                                return null;
 
57
                        
 
58
                        for (int i = 0; i < arguments.Length; i++)
 
59
                        {
 
60
                                if (RowTestFramework.IsSpecialValue(arguments[i]))
 
61
                                        arguments[i] = MapSpecialValue(arguments[i]);
 
62
                        }
 
63
                        
 
64
                        return arguments;
 
65
                }
 
66
                
 
67
                private object MapSpecialValue(object specialValue)
 
68
                {
 
69
                        switch (specialValue.ToString())
 
70
                        {
 
71
                                case "Null":
 
72
                                        return null;
 
73
                                
 
74
                                default:
 
75
                                        return specialValue;
 
76
                        }
 
77
                }
 
78
        }
 
79
}