~nunit-core/nunitv2/2.5

« back to all changes in this revision

Viewing changes to addins/RowTest/NUnitExtension.RowTest.AddIn/RowTestNameBuilder.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 System.Text;
 
8
 
 
9
namespace NUnitExtension.RowTest.AddIn
 
10
{
 
11
        public class RowTestNameBuilder
 
12
        {
 
13
                private MethodInfo _method;
 
14
                private string _baseTestName;
 
15
                private object[] _arguments;
 
16
                private string _argumentList;
 
17
 
 
18
                public RowTestNameBuilder(MethodInfo method, string baseTestName, object[] arguments)
 
19
                {
 
20
                        _method = method;
 
21
                        _baseTestName = baseTestName;
 
22
                        _arguments = arguments;
 
23
                }
 
24
                
 
25
                public MethodInfo Method
 
26
                {
 
27
                        get { return _method; }
 
28
                }
 
29
                
 
30
                public string BaseTestName
 
31
                {
 
32
                        get { return _baseTestName; }
 
33
                }
 
34
                
 
35
                public object[] Arguments
 
36
                {
 
37
                        get { return _arguments; }
 
38
                }
 
39
                
 
40
                public string TestName
 
41
                {
 
42
                        get 
 
43
                        {
 
44
                                string baseTestName = _baseTestName;
 
45
                                
 
46
                                if (baseTestName == null || baseTestName.Length == 0)
 
47
                                        baseTestName = _method.Name;
 
48
                                        
 
49
                                return baseTestName + GetArgumentList();
 
50
                        }
 
51
                }
 
52
                
 
53
                public string FullTestName
 
54
                {
 
55
                        get { return _method.DeclaringType.FullName + "." + TestName; }
 
56
                }
 
57
                
 
58
                private string GetArgumentList()
 
59
                {
 
60
                        if (_argumentList == null)
 
61
                                _argumentList = "(" + CreateArgumentList() + ")";
 
62
                        
 
63
                        return _argumentList;
 
64
                }
 
65
                
 
66
                private string CreateArgumentList()
 
67
                {
 
68
                        if (_arguments == null)
 
69
                                return "null";
 
70
                        
 
71
                        StringBuilder argumentListBuilder = new StringBuilder();
 
72
 
 
73
                        for (int i = 0; i < _arguments.Length; i++)
 
74
                        {
 
75
                                if (i > 0)
 
76
                                        argumentListBuilder.Append(", ");
 
77
                                
 
78
                                argumentListBuilder.Append (GetArgumentString (_arguments[i]));
 
79
                        }
 
80
                        
 
81
                        return argumentListBuilder.ToString();
 
82
                }
 
83
                
 
84
                private string GetArgumentString (object argument)
 
85
                {
 
86
                        if (argument == null)
 
87
                                return "null";
 
88
                        
 
89
                        return argument.ToString();
 
90
                }
 
91
        }
 
92
}