Add Nunit2
[mono.git] / mcs / nunit20 / framework / SummaryVisitor.cs
1 #region Copyright (c) 2002, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Philip A. Craig
2 /************************************************************************************
3 '
4 ' Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
5 ' Copyright © 2000-2002 Philip A. Craig
6 '
7 ' This software is provided 'as-is', without any express or implied warranty. In no 
8 ' event will the authors be held liable for any damages arising from the use of this 
9 ' software.
10
11 ' Permission is granted to anyone to use this software for any purpose, including 
12 ' commercial applications, and to alter it and redistribute it freely, subject to the 
13 ' following restrictions:
14 '
15 ' 1. The origin of this software must not be misrepresented; you must not claim that 
16 ' you wrote the original software. If you use this software in a product, an 
17 ' acknowledgment (see the following) in the product documentation is required.
18 '
19 ' Portions Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov 
20 ' or Copyright © 2000-2002 Philip A. Craig
21 '
22 ' 2. Altered source versions must be plainly marked as such, and must not be 
23 ' misrepresented as being the original software.
24 '
25 ' 3. This notice may not be removed or altered from any source distribution.
26 '
27 '***********************************************************************************/
28 #endregion
29
30 namespace NUnit.Core
31 {
32         using System;
33
34         /// <summary>
35         /// Summary description for SiummaryVisitor.
36         /// </summary>
37         public class SummaryVisitor : ResultVisitor
38         {
39                 private int totalCount;
40                 private int failureCount;
41                 private int testsNotRun;
42                 private int suitesNotRun;
43                 
44                 private double time;
45                 private string name;
46                 private bool initialized;
47
48                 public SummaryVisitor()
49                 {
50                         totalCount = 0;
51                         initialized = false;
52                 }
53
54                 public void visit(TestCaseResult caseResult) 
55                 {
56                         SetNameandTime(caseResult.Name, caseResult.Time);
57
58                         if(caseResult.Executed)
59                         {
60                                 totalCount++;
61                                 if(caseResult.IsFailure)
62                                         failureCount++;
63                         }
64                         else
65                                 testsNotRun++;
66                 }
67
68                 public void visit(TestSuiteResult suiteResult) 
69                 {
70                         SetNameandTime(suiteResult.Name, suiteResult.Time);
71
72                         
73                         
74                         foreach (TestResult result in suiteResult.Results)
75                         {
76                                 result.Accept(this);
77                         }
78                         
79                         if(!suiteResult.Executed)
80                                 suitesNotRun++;
81                 }
82
83                 public double Time
84                 {
85                         get { return time; }
86                 }
87
88                 private void SetNameandTime(string name, double time)
89                 {
90                         if(!initialized)
91                         {
92                                 this.time = time;
93                                 this.name = name;
94                                 initialized = true;
95                         }
96                 }
97
98                 public bool Success
99                 {
100                         get { return (failureCount == 0); }
101                 }
102
103                 public int Count
104                 {
105                         get { return totalCount; }
106                 }
107
108                 public int Failures
109                 {
110                         get { return failureCount; }
111                 }
112
113                 public int TestsNotRun
114                 {
115                         get { return testsNotRun; }
116                 }
117
118                 public int SuitesNotRun
119                 {
120                         get { return suitesNotRun; }
121                 }
122
123                 public string Name
124                 {
125                         get { return name; }
126                 }
127         }
128 }