OpenKeyWord  Version: 426, Datum:
Log2NUnit.cs
1 #region Header
2 /*
3  ==============================================================================
4  Author: Zoltan Hrabovszki <zh@openkeyword.de>
5 
6  Copyright © 2012, 2013, 2014, 2015 IT-Beratung Hrabovszki
7  www.OpenKeyWord.de
8  ==============================================================================
9 
10  This file is part of OpenKeyWord.
11 
12  OpenKeyWord is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  OpenKeyWord is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with OpenKeyWord. If not, see <http://www.gnu.org/licenses/>.
24 
25  Diese Datei ist Teil von OpenKeyWord.
26 
27  OpenKeyWord ist Freie Software: Sie können es unter den Bedingungen
28  der GNU General Public License, wie von der Free Software Foundation,
29  Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
30  veröffentlichten Version, weiterverbreiten und/oder modifizieren.
31 
32  OpenKeyWord wird in der Hoffnung, dass es nützlich sein wird, aber
33  OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
34  Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
35  Siehe die GNU General Public License für weitere Details.
36 
37  Sie sollten eine Kopie der GNU General Public License zusammen mit
38  OpenKeyWord erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
39 */
40 #endregion Header
41 
42 namespace OKW.Log
43 {
44  using System;
45  using System.Collections.Generic;
46 
47  using NUnit.Framework;
48 
49  public class Log2NUnit : ILogger
50  {
51  #region Fields
52 
53  string BlanksBefore = string.Empty;
54  int LevelCounter = 0;
55 
56  #endregion Fields
57 
58  #region Methods
59 
65  public void LogError(string fps_Message)
66  {
67  Log2NUnit_Console.GetInstance.Write(this.BlanksBefore + "Error: ");
68  Log2NUnit_Console.GetInstance.WriteLine(fps_Message);
69  }
70 
76  public void LogException(string fps_Message)
77  {
78  Log2NUnit_Console.GetInstance.Write(this.BlanksBefore + "Exception: ");
79  Log2NUnit_Console.GetInstance.WriteLine(fps_Message);
80  }
81 
87  public void LogFunctionEnd()
88  {
89  this.LogPrint("-------");
90  this.ResCloseList();
91  }
92 
98  public void LogFunctionEnd(string fps_Return)
99  {
100  this.ResOpenList("Return...");
101  this.LogPrint(fps_Return);
102  this.ResCloseList();
103  this.LogPrint("-------");
104  this.ResCloseList();
105  }
106 
112  public void LogFunctionEnd(bool fpb_Return)
113  {
114  this.ResOpenList("Return...");
115  this.LogPrint(OKW_Helper.Boolean2String(fpb_Return));
116  this.ResCloseList();
117  this.LogPrint("-------");
118  this.ResCloseList();
119  }
120 
126  public void LogFunctionEnd(List<string> fpls_Return)
127  {
128  this.ResOpenList("Return...");
129 
130  foreach (string Value in fpls_Return)
131  {
132  this.LogPrint(Value);
133  }
134 
135  this.ResCloseList();
136  this.LogPrint("-------");
137  this.ResCloseList();
138  }
139 
145  public void LogFunctionStart(string fps_FunctionName, params string[] fpsParameter)
146  {
147  this.ResOpenList(fps_FunctionName);
148  this.ResOpenList("Parameter...");
149 
150  for (int i = 0; i < fpsParameter.Length; i += 2)
151  {
152  this.LogPrint(fpsParameter[i] + ": >>" + fpsParameter[i + 1] + "<<");
153  }
154 
155  this.ResCloseList();
156  this.LogPrint("-------");
157 
158  return;
159  }
160 
166  public void LogKeyWordEnd()
167  {
168  this.ResCloseList();
169  }
170 
176  public void LogKeyWordStart(string fps_KeyWordName, params string[] fpsParameter)
177  {
178  String String2Print = fps_KeyWordName;
179 
180  // Keyword without parameter
181  if (fpsParameter.Length == 0)
182  {
183  // Keyword with one Parameter
184  String2Print = String2Print + "()";
185  }
186  // Keyword with one Parameter
187  else if (fpsParameter.Length == 1)
188  {
189  String2Print = String2Print + ": \"" + fpsParameter[0] + "\"";
190  }
191  // Keyword with two Parameters..
192  else if (fpsParameter.Length == 2)
193  {
194  String2Print = String2Print + ": \"" + fpsParameter[0] + "\" = \"" + fpsParameter[1] + "\"";
195  }
196  else
197  {
198  String2Print = String2Print + "(\"" + fpsParameter[0] + "\"";
199 
200  for (int i = 1; i < fpsParameter.Length; i++)
201  {
202  String2Print = String2Print + ", \"" + fpsParameter[i] + "\"";
203  }
204 
205  String2Print = String2Print + ")";
206  }
207 
208  this.ResOpenList(String2Print);
209 
210  return;
211  }
212 
218  public void LogPrint(string fps_Message)
219  {
220  Log2NUnit_Console.GetInstance.WriteLine(this.BlanksBefore + fps_Message);
221  }
222 
228  public void LogVerify(string fps_Actual, string fps_Expected)
229  {
230  Log2NUnit_Console.GetInstance.WriteLine(this.BlanksBefore + fps_Expected);
231 
232  Assert.AreEqual(fps_Expected, fps_Actual);
233 
234  Log2NUnit_Console.GetInstance.WriteLine(this.BlanksBefore + " Actual = >>" + fps_Actual + "<<");
235 
236  // TODO: " Actual = >>" in Sprachdatei auslagern.
237  }
238 
244  public void LogWarning(string fps_Message)
245  {
246  Log2NUnit_Console.GetInstance.Write(this.BlanksBefore + "Warning: ");
247  Log2NUnit_Console.GetInstance.WriteLine(fps_Message);
248  }
249 
255  public void ResCloseList()
256  {
257  if (this.LevelCounter > 0)
258  {
259  this.LevelCounter--;
260  }
261  else
262  {
263  this.LevelCounter = 0;
264  }
265 
266  this.BlankBefore();
267  }
268 
274  public void ResOpenList(string fps_Name)
275  {
276  this.LogPrint(fps_Name);
277  this.LevelCounter++;
278  this.BlankBefore();
279  }
280 
286  private void BlankBefore()
287  {
288  this.BlanksBefore = new string(' ', this.LevelCounter);
289  }
290 
291  #endregion Methods
292 
293  }
294 
301  public class Log2NUnit_Console
302  {
303  #region Fields
304 
310  List<string> cvLs_LogValue = new List<string>();
311  static Log2NUnit_Console instance = null;
312 
313  #endregion Fields
314 
315  #region Constructors
316 
317  private Log2NUnit_Console()
318  {
319  }
320 
321  #endregion Constructors
322 
323  #region Properties
324 
325  public static Log2NUnit_Console GetInstance
326  {
327  get
328  {
329  if (instance == null)
330  {
331  instance = new Log2NUnit_Console();
332  instance.Init();
333  }
334 
335  return instance;
336  }
337  }
338 
350  public List<string> LogValue
351  {
352  get { return cvLs_LogValue; }
353  /*
354  set {
355  foreach (string myString in Value)
356  {
357  cvLs_LogValue.Add(myString);
358  }
359  }
360  */
361  }
362 
363  #endregion Properties
364 
365  #region Methods
366 
372  public void Init()
373  {
374  cvLs_LogValue.Clear();
375  cvLs_LogValue.Add(string.Empty);
376  }
377 
384  public void Write(string fps_Value)
385  {
386  int Aktuelle_Zeile = cvLs_LogValue.Count - 1;
387 
388  cvLs_LogValue[Aktuelle_Zeile] = cvLs_LogValue[Aktuelle_Zeile] + fps_Value;
389  }
390 
398  public void WriteLine(string fps_Value)
399  {
400  this.Write(fps_Value);
401  cvLs_LogValue.Add(string.Empty);
402  }
403 
404  #endregion Methods
405  }
406 }
Klasse enthält OKW-Hilfsfunktionen.
Definition: OKW_Helper.cs:63
void LogFunctionStart(string fps_FunctionName, params string[] fpsParameter)
Definition: Log2NUnit.cs:145
void Init()
Inhalt der virtuellen Konsole wird gelöscht.
Definition: Log2NUnit.cs:372
void LogKeyWordEnd()
Definition: Log2NUnit.cs:166
void LogFunctionEnd(bool fpb_Return)
Definition: Log2NUnit.cs:112
void LogFunctionEnd()
Definition: Log2NUnit.cs:87
void ResOpenList(string fps_Name)
Definition: Log2NUnit.cs:274
Klasse bildet eine virtuelle Konsole nach um das Logging zu prüfen. Die Werte werden via Log2NUnit ge...
Definition: Log2NUnit.cs:301
void LogPrint(string fps_Message)
LogPrint Function: Prints the values of expressions to the results file.
Definition: Log2NUnit.cs:218
void LogException(string fps_Message)
LogException Function: Logs a Script Exception to the results file.
Definition: Log2NUnit.cs:76
void LogKeyWordStart(string fps_KeyWordName, params string[] fpsParameter)
Definition: Log2NUnit.cs:176
List< string > cvLs_LogValue
Diese Liste aus String-s ist für die Überprüfung des Loggings gedacht. Die Klasse Log2NUnit ist der G...
Definition: Log2NUnit.cs:310
void LogVerify(string fps_Actual, string fps_Expected)
Definition: Log2NUnit.cs:228
void WriteLine(string fps_Value)
Schreibt eine neue Zeile in die virtuelle Konsole. Text wird einer bereits mit Write geschriebenen Ze...
Definition: Log2NUnit.cs:398
void Write(string fps_Value)
Fügt den gegebenen Wert in die letzte Zeile der virtuelle Konsole.
Definition: Log2NUnit.cs:384
void BlankBefore()
Definition: Log2NUnit.cs:286
List< string > LogValue
Getter Eigenschaft der Variablen Log2NUnit_Console.cvLs_LogValue. Gettet die Eigenschaft LogValue als...
Definition: Log2NUnit.cs:351
void LogFunctionEnd(List< string > fpls_Return)
Definition: Log2NUnit.cs:126
Debug Logs are not a part of Interface. This functions are Implemented in Logger.cs a Log*Debug funct...
Definition: ILogger.cs:62
void LogFunctionEnd(string fps_Return)
Definition: Log2NUnit.cs:98
void LogWarning(string fps_Message)
LogWarning Function: Logs a warning to the results file.
Definition: Log2NUnit.cs:244
static string Boolean2String(bool fpbTrueOrFalse)
Konvertiert bool true/false nach string "true"/"false".
Definition: OKW_Helper.cs:108
Definition: Core.cs:40
void ResCloseList()
Closes the outline level.
Definition: Log2NUnit.cs:255
void LogError(string fps_Message)
LogError Function: Logs an error message to the results file.
Definition: Log2NUnit.cs:65