<?xml version="1.0" encoding="utf-8" ?>
<!-- 
XSLT Schema for generating build reports for CCNet Dashboard from unit test report generated by MSTest utility (v. 8.0.50727.26)
Author: Roman V. Gavrilov (clavrg@hotmail.com)
-->
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>

    <xsl:template match="/">
        <!-- 
        TestOutcome:
            1 - Failed
						4 - Inconclusive
            10 - Passed
        -->
        <xsl:variable name="pass_toplevel" select="count(/cruisecontrol/build/Tests/UnitTestResult[outcome=10])"/>
    	<xsl:variable name="pass_multiples" select="count(/cruisecontrol/build/Tests/UnitTestResult/innerResults/element[outcome=10])"/>
    	<xsl:variable name="pass_count" select="$pass_toplevel + $pass_multiples"/>
    	<xsl:variable name="inconclusive_toplevel" select="count(/cruisecontrol/build/Tests/UnitTestResult[outcome=4])"/>
    	<xsl:variable name="inconclusive_multiples" select="count(/cruisecontrol/build/Tests/UnitTestResult/innerResults/element[outcome=4])"/>
    	<xsl:variable name="inconclusive_count" select="$inconclusive_toplevel + $inconclusive_multiples"/>
    	<xsl:variable name="failed_toplevel" select="count(/cruisecontrol/build/Tests/UnitTestResult[outcome=1])"/>
    	<xsl:variable name="failed_multiples" select="count(/cruisecontrol/build/Tests/UnitTestResult/innerResults/element[outcome=1])"/>
    	<xsl:variable name="failed_count" select="$failed_toplevel + $failed_multiples"/>
		<xsl:variable name="total_count" select="$failed_count + $pass_count + $inconclusive_count"/>

        <table class="section-table" width="100%">
            <tr>
                <td class="sectionheader">
                    Tests run: <xsl:value-of select="$total_count"/>, Failures: <xsl:value-of select="$failed_count"/>, Inconclusive: <xsl:value-of select="$inconclusive_count"/>
                </td>
            </tr>

            <tr>
                <td>
                    <table>
                        <tr>
                            <td width="100">
                                <b>Passed:</b>
                            </td>
                            <td>
                                <xsl:value-of select="$pass_count"/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>Failed:</b>
                            </td>
                            <td>
                                <xsl:value-of select="$failed_count"/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>Inconclusive:</b>
                            </td>
                            <td>
                                <xsl:value-of select="$inconclusive_count"/>
                            </td>
                        </tr> 
										</table>
                </td>
            </tr>
            <!-- BAR -->
            <tr>
                <td width="100%">
                    <table border="1" width="100%">
                        <tr height="20">
                            <xsl:choose>
                                <xsl:when test="$total_count=$pass_count">
                                    <td bgcolor="00FF33" align="center">
                                        <b>PASSED</b>
                                    </td>
                                </xsl:when>
                                <xsl:otherwise>
                                    <td bgcolor="FF0000" align="center">
                                        <b>FAILED</b>
                                    </td>
                                </xsl:otherwise>
                            </xsl:choose>
                        </tr>
                    </table>
                </td>
            </tr>
            <!-- DETAILS TABLE -->
            <tr>
                <td>
                    <table border="1" width="100%" frame="box">
                        <tr bgcolor="#2288FF">
                            <th align="center" width="40">Code</th>
                            <th align="left">Method</th>
                            <th align="left">Class</th>
                            <th align="left">Message</th>
                            <th align="left">Duration</th>
                        </tr>

                        <xsl:for-each select="/cruisecontrol/build/Tests/TestRun/tests/value">
                            <xsl:variable name="testId" select="id/id"/>
                            <xsl:variable name="UnitTestResult" select="/cruisecontrol/build/Tests/UnitTestResult[id/testId/id=$testId]"/>
                            <tr>
                                <xsl:choose>
                                    <xsl:when test="$UnitTestResult/outcome = 10">
                                        <td bgcolor="00FF33" align="center"> P </td>
                                    </xsl:when>
                                    <xsl:when test="$UnitTestResult/outcome = 1">
                                        <td bgcolor="FF0000" align="center"> F </td>
                                    </xsl:when>
																	<xsl:when test="$UnitTestResult/outcome = 4">
																		<td bgcolor="FFCC00" align="center"> I </td>
																	</xsl:when>
																	<xsl:otherwise>
                                        <td bgcolor="3399FF" align="center"> ? </td>
                                    </xsl:otherwise>
                                </xsl:choose>
                                <td>
                                    <xsl:value-of select="name"/>
                                </td>
                                <td>
                                    <script type="text/javascript">
                                        var str= &quot; <xsl:value-of select="testMethod/className"/> &quot;
                                        var pos=str.indexOf(",");
                                        if (pos>=0) { var cs = str.substring(0, pos); document.write(cs); }
                                        else { document.write("&lt; class name not specified&gt;"); }
                                    </script>
                                </td>
                                <td>
                                    <xsl:value-of select="$UnitTestResult/errorInfo/message"/>
                                </td>
                                 <td>
                                    <xsl:value-of select="concat(substring-before($UnitTestResult/duration,'.'),'.',substring(substring-after($UnitTestResult/duration,'.'),1,7))"/>
                                </td>
                           </tr>
                        </xsl:for-each>
                    </table>
                </td>
            </tr>
        </table>
    </xsl:template>

</xsl:transform>
