Advertisement
Advertisement
| 08.14.2008 at 06:48AM PDT, ID: 23648063 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: |
// This program generates a report of the Unit Test results
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.IO;
namespace WindowsApplication25
{
public partial class Form1 : Form
{
private const string TESTSUITEBEGIN = "11";
private const string TESTCASEBEGIN = "13";
private const string TESTRESULT = "5";
private Dictionary<string, string> filesPath = new Dictionary<string, string>();
public Form1()
{
InitializeComponent();
}
//Create the DataSet from the XML file
private DataSet mDS = new DataSet();
private void GenerateData()
{
string sucessfulFile = "Files process successfully:\r\n";
string failedFile = "Files failed to process:\r\n";
string[] logFiles = System.IO.Directory.GetFiles(txtHTMLPath.Text, "*.tlog", SearchOption.AllDirectories);
mDS = new DataSet("TestReport");
for (int i = 0; i < logFiles.Length; i++)
{
bool readSuccessfully = true;
DataSet ds = new DataSet();
try
{
ds.ReadXml(logFiles[i]);
sucessfulFile += logFiles[i] + "\r\n";
}
catch
{
readSuccessfully = false;
failedFile += logFiles[i] + "\r\n";
}
if (readSuccessfully)
{
System.IO.FileInfo fileInfo = new FileInfo(logFiles[i]);
string TableName = fileInfo.Name;
filesPath.Add(TableName, fileInfo.FullName);
DataTable DTCust = new DataTable(TableName);
DataColumn colCust = new DataColumn("TestSuiteName", System.Type.GetType("System.String"));
DTCust.Columns.Add(colCust);
colCust = new DataColumn("NumTestCase", System.Type.GetType("System.String"));
DTCust.Columns.Add(colCust);
colCust = new DataColumn("NumOfPass", System.Type.GetType("System.String"));
DTCust.Columns.Add(colCust);
colCust = new DataColumn("NumOfFailed", System.Type.GetType("System.String"));
DTCust.Columns.Add(colCust);
colCust = new DataColumn("Note", System.Type.GetType("System.String"));
DTCust.Columns.Add(colCust);
mDS.Tables.Add(DTCust);
DataView dv = new DataView(ds.Tables["TestMessage"]);
dv.RowFilter = "TestCase ='' AND KIND='" + TESTSUITEBEGIN + "'";
for (int j = 0; j < dv.Count; j++)
{
DataRow row = mDS.Tables[TableName].NewRow();
row["TestSuiteName"] = dv[j]["TestSuite"].ToString();
DataView dvCase = new DataView(ds.Tables["TestMessage"]);
dvCase.RowFilter = "TestSuite='" + dv[j]["TestSuite"].ToString() + "' AND KIND='" + TESTCASEBEGIN + "'";
row["NumTestCase"] = dvCase.Count;
DataView dvResult = new DataView(ds.Tables["TestMessage"]);
dvResult.RowFilter = "TestSuite='" + dv[j]["TestSuite"].ToString() + "' AND KIND='" + TESTRESULT + "' AND MESSAGE='FAILED'";
if (dvResult.Count == 0)
{
row["NumOfFailed"] = 0;
}
else
{
row["NumOfFailed"] = dvResult.Count;
}
dvResult.RowFilter = "TestSuite='" + dv[j]["TestSuite"].ToString() + "' AND KIND='" + TESTRESULT + "' AND MESSAGE='OK'";
if (dvResult.Count == 0)
{
row["NumOfPass"] = 0;
}
else
{
row["NumOfPass"] = dvResult.Count;
}
row["Note"] = "";
mDS.Tables[TableName].Rows.Add(row);
}
}
}
/* When RTF file is automatically created
if (File.Exists("UnitTestResults.rtf"))
{
File.Delete("UnitTestResults.rtf");
}
*/
//System.IO.TextWriter tw = new System.IO.StreamWriter(txtOutputPath.Text.Replace(".rtf", "RESULT.txt"));
System.IO.TextWriter tw = new System.IO.StreamWriter(Path.Combine(txtOutputPath.Text, "results.txt"));
tw.WriteLine(sucessfulFile + "\r\n \r\n" + failedFile);
tw.Close();
}
private void PopulateResult(string[] logFiles)
{
}
private void button1_Click(object sender, EventArgs e)
{
GenerateData();
XMLTransfrom();
filesPath.Clear();
}
private void XMLTransfrom()
{
StringWriter wr = new StringWriter();
wr.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
wr.WriteLine("<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">");
wr.WriteLine("<xsl:template match=\"/\">");
wr.WriteLine("<html><body>");
for (int i = 0; i < mDS.Tables.Count; i++)
{
//wr.WriteLine("<a href=\"" + filesPath[mDS.Tables[i].TableName] + "\">" + mDS.Tables[i].TableName.Replace(".tlog", "") + "</a>");
wr.WriteLine("<a href=\"" + Path.GetDirectoryName(filesPath[mDS.Tables[i].TableName]) + "\">" + mDS.Tables[i].TableName.Replace(".tlog", "") + "</a>");
wr.WriteLine("<table border=\"1\"><tr bgcolor=\"#9acd32\"><th width=\"260\" align=\"left\">Test Suite Name</th><th align=\"left\"># Test Cases</th><th align=\"left\"># Pass</th><th align=\"left\"># Failed</th><th width=\"240\" align=\"left\">Note</th></tr>");
wr.WriteLine("<xsl:for-each select=\"" + mDS.DataSetName + "/" + mDS.Tables[i].TableName + "\"><tr>");
wr.WriteLine("<td><xsl:value-of select=\"TestSuiteName\"/></td>");
wr.WriteLine("<td><xsl:value-of select=\"NumTestCase\"/></td>");
wr.WriteLine("<td><xsl:value-of select=\"NumOfPass\"/></td>");
wr.WriteLine("<td><xsl:value-of select=\"NumOfFailed\"/></td>");
//wr.WriteLine("</tr></xsl:for-each></table>");
wr.WriteLine("</tr></xsl:for-each>");
wr.WriteLine("<tr><td colspan=\"3\"> Unit Test Coverage </td><td> N/A </td></tr>");
wr.WriteLine("</table><br></br>");
}
wr.WriteLine("</body></html></xsl:template></xsl:stylesheet>");
StringReader sr = new StringReader(wr.ToString());
XmlTextReader xslSource = new XmlTextReader(sr);
XslCompiledTransform xsltDoc = new XslCompiledTransform();
xsltDoc.Load(xslSource);
sr.Close();
wr.Close();
StringWriter wrXML = new StringWriter();
mDS.WriteXml(wrXML);
StringReader srXML = new StringReader(wrXML.ToString());
XmlTextReader xmlSource = new XmlTextReader(srXML);
XPathDocument xpathDoc = new XPathDocument(xmlSource);
srXML.Close();
wrXML.Close();
//XmlTextWriter writer = new XmlTextWriter(txtOutputPath.Text, System.Text.Encoding.Default);
XmlTextWriter writer = new XmlTextWriter(Path.Combine(txtOutputPath.Text, "UnitTestResults.rtf"),System.Text.Encoding.Default);
xsltDoc.Transform(xpathDoc, writer);
//Close the Writer after Transformation
writer.Close();
writer = null;
mDS = null;
MessageBox.Show("Document created successfully.....","Document Complete");
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
|