Skip to content

Commit

Permalink
Fixed up new messaging and integration tests to support nested test c…
Browse files Browse the repository at this point in the history
…lass names better
  • Loading branch information
staxmanade committed Feb 27, 2010
1 parent 602e4a6 commit 8abb459
Show file tree
Hide file tree
Showing 19 changed files with 237 additions and 199 deletions.
3 changes: 2 additions & 1 deletion integrationTestRunHelper.ps1
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
& 'C:\Program Files\NUnit 2.5.3\bin\net-2.0\nunit-console.exe' /noshadow .\src\StatLight.IntegrationTests\StatLight.IntegrationTests.nunit /run StatLight.IntegrationTests.ProviderTests.MSTest.when_testing_the_runner_with_MSTest_tests
& 'C:\Program Files\NUnit 2.5.3\bin\net-2.0\nunit-console.exe' /noshadow .\src\StatLight.IntegrationTests\StatLight.IntegrationTests.nunit /run StatLight.IntegrationTests.ProviderTests.MSTest.when_testing_the_runner_with_MSTest_tests
#& 'C:\Program Files\NUnit 2.5.3\bin\net-2.0\nunit-console.exe' /noshadow .\src\StatLight.IntegrationTests\StatLight.IntegrationTests.nunit /run StatLight.IntegrationTests.ProviderTests.MSTest.when_testing_the_runner_with_MSTest_tests_filtered_by_certain_methods
Binary file added sampleMSTestRunReport.xml
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace StatLight.Client.Harness.ClientEventMapping
{
public static class ReflectionInfoHelper
{
public static string ReadClassName(this Type type)
{
return type.FullName.Substring(type.Namespace.Length+1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Silverlight.Testing.UnitTesting.Harness;
using Microsoft.Silverlight.Testing.UnitTesting.Metadata;
using StatLight.Client.Harness.Events;
using System.Reflection;

namespace StatLight.Client.Harness.ClientEventMapping
{
Expand All @@ -27,7 +28,7 @@ public ClientEvent Translate(LogMessage message)
var testClass = (ITestClass)message.Decorators[UnitTestLogDecorator.TestClassMetadata];
var clientEventX = new TestExecutionClassBeginClientEvent
{
ClassName = testClass.Name,
ClassName = testClass.Type.ReadClassName(),
NamespaceName = testClass.Type.Namespace,
};
return clientEventX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ClientEvent Translate(LogMessage message)
var testClass = (ITestClass)message.Decorators[UnitTestLogDecorator.TestClassMetadata];
var clientEventX = new TestExecutionClassCompletedClientEvent
{
ClassName = testClass.Name,
ClassName = testClass.Type.ReadClassName(),
NamespaceName = testClass.Type.Namespace,
};
return clientEventX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ClientEvent Translate(LogMessage message)
var testMethod = (ITestMethod)message.Decorators[UnitTestLogDecorator.TestMethodMetadata];
var clientEventX = new TestExecutionMethodBeginClientEvent
{
ClassName = testMethod.Method.DeclaringType.Name,
ClassName = testMethod.Method.DeclaringType.ReadClassName(),
NamespaceName = testMethod.Method.DeclaringType.Namespace,
MethodName = testMethod.Method.Name,
Started = DateTime.Now,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ClientEvent Translate(LogMessage message)
var clientEventX = new TestExecutionMethodFailedClientEvent
{
ExceptionInfo = exception,
ClassName = testMethod.Method.DeclaringType.Name,
ClassName = testMethod.Method.DeclaringType.ReadClassName(),
NamespaceName = testMethod.Method.DeclaringType.Namespace,
MethodName = testMethod.Method.Name,
Finished = scenarioResult.Finished,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ClientEvent Translate(LogMessage message)

var clientEventX = new TestExecutionMethodPassedClientEvent
{
ClassName = testMethod.Method.DeclaringType.Name,
ClassName = testMethod.Method.DeclaringType.ReadClassName(),
NamespaceName = testMethod.Method.DeclaringType.Namespace,
MethodName = testMethod.Method.Name,
Finished = scenarioResult.Finished,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="AssemblyInfo.This.cs" />
<Compile Include="ClientEventMapping\ReflectionInfoHelper.cs" />
<Compile Include="ClientEventMapping\TestExecutionDoNotReportMessageMap.cs" />
<Compile Include="ClientEventMapping\TestExecutionMethodPassedClientEventMap.cs" />
<Compile Include="ClientEventMapping\LogMessageTranslator.cs" />
Expand Down
30 changes: 15 additions & 15 deletions src/StatLight.Core/Reporting/Providers/Xml/XmlReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ public void WriteXmlReport(string outputFilePath)
public string GetXmlReport()
{
throw new NotImplementedException();
var root =
new XElement("StatLightTestResults",
new XAttribute("xapFileName", _testXapFileName),
new XAttribute("total", this._report.TotalResults),
new XAttribute("ignored", this._report.TotalIgnored),
new XAttribute("failed", this._report.TotalFailed),
new XAttribute("dateRun", this._report.DateTimeRunCompleted.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentCulture)),
//var root =
// new XElement("StatLightTestResults",
// new XAttribute("xapFileName", _testXapFileName),
// new XAttribute("total", this._report.TotalResults),
// new XAttribute("ignored", this._report.TotalIgnored),
// new XAttribute("failed", this._report.TotalFailed),
// new XAttribute("dateRun", this._report.DateTimeRunCompleted.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentCulture)),

new XElement("tests",
(from x in _report.Results
select GetResult(x))
//(from x in _report.OtherMessages
// select GetOtherMessage(x))
)
);
return root.ToString();
// new XElement("tests",
// (from x in _report.Results
// select GetResult(x))
// //(from x in _report.OtherMessages
// // select GetOtherMessage(x))
// )
// );
//return root.ToString();
}

//private static object GetOtherMessage(MobilOtherMessageType result)
Expand Down
8 changes: 2 additions & 6 deletions src/StatLight.Core/Reporting/TestReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ namespace StatLight.Core.Reporting
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections.ObjectModel;
using StatLight.Client.Harness.Events;
using StatLight.Core.Reporting.Messages;
using System.Diagnostics;

public class Result
{
Expand All @@ -19,6 +18,7 @@ public Result(ResultType resultType)

}

[DebuggerDisplay("Result=[{ResultType}], Method={NamespaceName}.{ClassName}.{MethodName}")]
public class TestCaseResult : Result
{
public TestCaseResult(ResultType resultType)
Expand Down Expand Up @@ -73,10 +73,6 @@ public TestReport()

public IEnumerable<Result> TestResults { get { return _testCaseResults; } }


private Collection<MobilScenarioResult> results = new Collection<MobilScenarioResult>();
public Collection<MobilScenarioResult> Results { get { return results; } }

public DateTime DateTimeRunCompleted { get; private set; }

public RunCompletedState FinalResult
Expand Down
111 changes: 56 additions & 55 deletions src/StatLight.Core/WebServer/TestRunConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,70 @@

namespace StatLight.Core.WebServer
{
using System.Runtime.Serialization;
using StatLight.Core.UnitTestProviders;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
using StatLight.Core.UnitTestProviders;
using System.Collections.Generic;
using System.Reflection;
using StatLight.Client.Harness;

[DataContract]
public class TestRunConfiguration
{
private string _tagFilters = string.Empty;
[DataContract]
public class TestRunConfiguration
{
private string _tagFilters = string.Empty;

[DataMember]
public string TagFilter
{
get
{
return _tagFilters;
}
set
{
if (value == null)
_tagFilters = string.Empty;
else
_tagFilters = value;
}
}
[DataMember]
public string TagFilter
{
get
{
return _tagFilters;
}
set
{
if (value == null)
_tagFilters = string.Empty;
else
_tagFilters = value;
}
}

[DataMember]
public UnitTestProviderType UnitTestProviderType { get; set; }
[DataMember]
public UnitTestProviderType UnitTestProviderType { get; set; }

private List<string> _methodsToTest;
private List<string> _methodsToTest;

[DataMember]
public List<string> MethodsToTest
{
get { return (_methodsToTest ?? (_methodsToTest = new List<string>())); }
set { _methodsToTest = value; }
}
[DataMember]
public List<string> MethodsToTest
{
get { return (_methodsToTest ?? (_methodsToTest = new List<string>())); }
set { _methodsToTest = value; }
}

public static TestRunConfiguration CreateDefault()
{
return new TestRunConfiguration
{
TagFilter = string.Empty,
UnitTestProviderType = UnitTestProviderType.MSTest,
};
}
public static TestRunConfiguration CreateDefault()
{
return new TestRunConfiguration
{
TagFilter = string.Empty,
UnitTestProviderType = UnitTestProviderType.MSTest,
};
}

public static TestRunConfiguration CurrentTestRunConfiguration { get; set; }
public static bool ContainsMethod(MethodInfo methodInfo)
{
if (CurrentTestRunConfiguration == null)
return false;
if (methodInfo == null)
throw new ArgumentNullException("methodInfo");
public static TestRunConfiguration CurrentTestRunConfiguration { get; set; }
public static bool ContainsMethod(MethodInfo methodInfo)
{
if (CurrentTestRunConfiguration == null)
return false;
if (methodInfo == null)
throw new ArgumentNullException("methodInfo");

if (CurrentTestRunConfiguration.MethodsToTest.Count == 0)
return true;
if (CurrentTestRunConfiguration.MethodsToTest.Count == 0)
return true;

string methodString = methodInfo.DeclaringType.FullName + "." + methodInfo.Name;
if (CurrentTestRunConfiguration.MethodsToTest.Contains(methodString))
return true;
string methodString = methodInfo.DeclaringType.FullName + "." + methodInfo.Name;
if (CurrentTestRunConfiguration.MethodsToTest.Contains(methodString))
return true;

return false;
}
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static void AssertTestExecutionClassData(TestExecutionClass e)
{
e.NamespaceName.ShouldEqual("StatLight.IntegrationTests.Silverlight", "{0} - NamespaceName property should be correct.".FormatWith(e.GetType().FullName));

var validClassNames = new List<string> { "MSTestNestedClassTests", "MSTestTests" };
var validClassNames = new List<string> { "MSTestTests+MSTestNestedClassTests", "MSTestTests" };
if (!validClassNames.Contains(e.ClassName))
Assert.Fail("e.ClassName is not equal to MSTestNestedClassTests or MSTestTest - actual=" + e.ClassName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,41 @@

namespace StatLight.IntegrationTests.ProviderTests.MSTest
{
[TestFixture]
public class when_testing_the_runner_with_MSTest_tests_filtered_by_certain_methods
: filtered_tests____
{
private TestRunConfiguration _testRunConfiguration;

protected override TestRunConfiguration TestRunConfiguration
{
get { return this._testRunConfiguration; }
}

protected override void Before_all_tests()
{
base.PathToIntegrationTestXap = TestXapFileLocations.MSTest;

_testRunConfiguration = new TestRunConfiguration
{
TagFilter = string.Empty,
UnitTestProviderType = UnitTestProviderType.MSTest,
MethodsToTest = new List<string>()
{
(base.NormalClassTestName = "StatLight.IntegrationTests.Silverlight.MSTestTests+MSTestNestedClassTests") + ".this_should_be_a_passing_test",
(base.NestedClassTestName = "StatLight.IntegrationTests.Silverlight.MSTestTests") + ".this_should_be_a_passing_test",
}
};

base.Before_all_tests();

TestResults = base.Runner.Run();
}
}
[TestFixture]
public class when_testing_the_runner_with_MSTest_tests_filtered_by_certain_methods
: filtered_tests____
{
private TestRunConfiguration _testRunConfiguration;

protected override TestRunConfiguration TestRunConfiguration
{
get { return _testRunConfiguration; }
}

protected override void Before_all_tests()
{
PathToIntegrationTestXap = TestXapFileLocations.MSTest;

const string namespaceToTestFrom = "StatLight.IntegrationTests.Silverlight.";

NormalClassTestName = "MSTestTests";
NestedClassTestName = "MSTestTests+MSTestNestedClassTests";

_testRunConfiguration = new TestRunConfiguration
{
TagFilter = string.Empty,
UnitTestProviderType = UnitTestProviderType.MSTest,
MethodsToTest = new List<string>
{
namespaceToTestFrom + NormalClassTestName + ".this_should_be_a_passing_test",
namespaceToTestFrom + NestedClassTestName + ".this_should_be_a_passing_test",
}
};

base.Before_all_tests();

TestResults = base.Runner.Run();
}
}

}
Loading

0 comments on commit 8abb459

Please sign in to comment.