Skip to content

Commit

Permalink
Cleaned up messages - issue #442 (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
parrainc authored and jayaranigarg committed Oct 8, 2018
1 parent 45d2f41 commit 8b35d9a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 43 deletions.
20 changes: 8 additions & 12 deletions src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ internal class TypeCache : MarshalByRefObject
/// <summary>
/// Helper for reflection API's.
/// </summary>
private ReflectHelper reflectionHelper;
private readonly ReflectHelper reflectionHelper;

/// <summary>
/// Assembly info cache
/// </summary>
private Dictionary<Assembly, TestAssemblyInfo> testAssemblyInfoCache;
private readonly Dictionary<Assembly, TestAssemblyInfo> testAssemblyInfoCache;

/// <summary>
/// ClassInfo cache
/// </summary>
private Dictionary<string, TestClassInfo> classInfoCache;
private readonly Dictionary<string, TestClassInfo> classInfoCache;

private object assemblyInfoSyncObject;
private object classInfoSyncObject;
private readonly object assemblyInfoSyncObject;
private readonly object classInfoSyncObject;

/// <summary>
/// Initializes a new instance of the <see cref="TypeCache"/> class.
Expand Down Expand Up @@ -174,9 +174,7 @@ private TestClassInfo GetClassInfo(TestMethod testMethod)

var typeName = testMethod.FullClassName;

TestClassInfo classInfo;

if (!this.classInfoCache.TryGetValue(typeName, out classInfo))
if (!this.classInfoCache.TryGetValue(typeName, out TestClassInfo classInfo))
{
// Aquiring a lock is usually a costly operation which does not need to be
// performed every time if the type is found in the cache.
Expand Down Expand Up @@ -363,9 +361,8 @@ private PropertyInfo ResolveTestContext(Type classType)
private TestAssemblyInfo GetAssemblyInfo(Type type)
{
var assembly = type.GetTypeInfo().Assembly;
TestAssemblyInfo assemblyInfo;

if (!this.testAssemblyInfoCache.TryGetValue(assembly, out assemblyInfo))
if (!this.testAssemblyInfoCache.TryGetValue(assembly, out TestAssemblyInfo assemblyInfo))
{
// Aquiring a lock is usually a costly operation which does not need to be
// performed every time if the assembly is found in the cache.
Expand Down Expand Up @@ -713,8 +710,7 @@ private bool ValidateAndAssignTestProperty(
return false;
}

object existingValue;
if (testContext.TryGetPropertyValue(propertyName, out existingValue))
if (testContext.TryGetPropertyValue(propertyName, out object existingValue))
{
// Do not add to the test context because it would conflict with an already existing value.
// We were at one point reporting a warning here. However with extensibility centered around TestProperty where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class TestExecutionManagerTests

private TestExecutionManager TestExecutionManager { get; set; }

private TestProperty[] tcmKnownProperties = new TestProperty[]
private readonly TestProperty[] tcmKnownProperties = new TestProperty[]
{
TestAdapterConstants.TestRunIdProperty,
TestAdapterConstants.TestPlanIdProperty,
Expand Down Expand Up @@ -417,11 +417,12 @@ public void RunTestsForMultipleSourcesShouldRunEachTestJustOnce()
{
int testsCount = 0;
var sources = new List<string> { Assembly.GetExecutingAssembly().Location, Assembly.GetExecutingAssembly().Location };
TestableTestExecutionManager testableTestExecutionmanager = new TestableTestExecutionManager();

testableTestExecutionmanager.ExecuteTestsWrapper = (tests, runContext, frameworkHandle, isDeploymentDone) =>
TestableTestExecutionManager testableTestExecutionmanager = new TestableTestExecutionManager
{
testsCount += tests.Count();
ExecuteTestsWrapper = (tests, runContext, frameworkHandle, isDeploymentDone) =>
{
testsCount += tests.Count();
}
};

testableTestExecutionmanager.RunTests(sources, this.runContext, this.frameworkHandle, this.cancellationToken);
Expand Down Expand Up @@ -792,8 +793,10 @@ private TestCase GetTestCase(Type typeOfClass, string testName, bool ignore = fa
{
var methodInfo = typeOfClass.GetMethod(testName);
var testMethod = new TestMethod(methodInfo.Name, typeOfClass.FullName, Assembly.GetExecutingAssembly().FullName, isAsync: false);
UnitTestElement element = new UnitTestElement(testMethod);
element.Ignored = ignore;
UnitTestElement element = new UnitTestElement(testMethod)
{
Ignored = ignore
};
return element.ToTestCase();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ public class TestMethodRunnerTests

private readonly TestMethod testMethod;

private TestablePlatformServiceProvider testablePlatformServiceProvider;
private readonly TestMethodOptions globaltestMethodOptions;

private readonly TestMethodOptions testMethodOptions;

private TestMethodOptions globaltestMethodOptions;
private TestMethodOptions testMethodOptions;
private Mock<ReflectHelper> mockReflectHelper;
private readonly Mock<ReflectHelper> mockReflectHelper;

private TestablePlatformServiceProvider testablePlatformServiceProvider;

public TestMethodRunnerTests()
{
Expand Down Expand Up @@ -222,10 +224,12 @@ public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIs
public void ExecuteForAssemblyInitializeThrowingExceptionShouldReturnUnitTestResultWithFailedOutcome()
{
// Arrange.
var tai = new TestAssemblyInfo();
tai.AssemblyInitializeMethod = typeof(TestMethodRunnerTests).GetMethod(
var tai = new TestAssemblyInfo
{
AssemblyInitializeMethod = typeof(TestMethodRunnerTests).GetMethod(
"InitMethodThrowingException",
BindingFlags.Static | BindingFlags.NonPublic);
BindingFlags.Static | BindingFlags.NonPublic)
};

var constructorInfo = typeof(DummyTestClass).GetConstructors().Single();
var classAttribute = new UTF.TestClassAttribute();
Expand Down Expand Up @@ -263,11 +267,12 @@ public void ExecuteForClassInitializeThrowingExceptionShouldReturnUnitTestResult
constructor: constructorInfo,
testContextProperty: testContextProperty,
classAttribute: classAttribute,
parent: tai);

tci.ClassInitializeMethod = typeof(TestMethodRunnerTests).GetMethod(
parent: tai)
{
ClassInitializeMethod = typeof(TestMethodRunnerTests).GetMethod(
"InitMethodThrowingException",
BindingFlags.Static | BindingFlags.NonPublic);
BindingFlags.Static | BindingFlags.NonPublic)
};

var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, tci, this.testMethodOptions, () => { throw new Exception("DummyException"); });
var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);
Expand Down Expand Up @@ -506,8 +511,10 @@ public void RunTestMethodShouldRunDataDrivenTestsWhenDataIsProvidedUsingDataSour
[TestMethodV1]
public void RunTestMethodShouldRunDataDrivenTestsWhenDataIsProvidedUsingDataRowAttribute()
{
UTF.TestResult testResult = new UTF.TestResult();
testResult.Outcome = UTF.UnitTestOutcome.Inconclusive;
UTF.TestResult testResult = new UTF.TestResult
{
Outcome = UTF.UnitTestOutcome.Inconclusive
};

var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);
Expand Down Expand Up @@ -589,10 +596,10 @@ public void RunTestMethodShouldFillInDisplayNameWithDataRowDisplayNameIfProvided

int dummyIntData = 2;
string dummyStringData = "DummyString";
UTF.DataRowAttribute dataRowAttribute = new UTF.DataRowAttribute(
dummyIntData,
dummyStringData);
dataRowAttribute.DisplayName = "DataRowTestDisplayName";
UTF.DataRowAttribute dataRowAttribute = new UTF.DataRowAttribute(dummyIntData, dummyStringData)
{
DisplayName = "DataRowTestDisplayName"
};

var attribs = new Attribute[] { dataRowAttribute };

Expand Down Expand Up @@ -634,8 +641,10 @@ public void RunTestMethodShouldFillInDisplayNameWithDataRowArgumentsIfNoDisplayN
[TestMethodV1]
public void RunTestMethodShouldSetResultFilesIfPresentForDataDrivenTests()
{
UTF.TestResult testResult = new UTF.TestResult();
testResult.ResultFiles = new List<string>() { "C:\\temp.txt" };
UTF.TestResult testResult = new UTF.TestResult
{
ResultFiles = new List<string>() { "C:\\temp.txt" }
};

var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);
Expand Down Expand Up @@ -704,8 +713,10 @@ public void RunTestMethodShouldReturnParentResultForDataSourceDataDrivenTestsCon
[TestMethodV1]
public void RunTestMethodShouldReturnParentResultForDataRowDataDrivenTests()
{
UTF.TestResult testResult = new UTF.TestResult();
testResult.ResultFiles = new List<string>() { "C:\\temp.txt" };
UTF.TestResult testResult = new UTF.TestResult
{
ResultFiles = new List<string>() { "C:\\temp.txt" }
};

var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);
Expand Down Expand Up @@ -736,8 +747,10 @@ public void RunTestMethodShouldReturnParentResultForDataRowDataDrivenTests()
[TestMethodV1]
public void RunTestMethodShouldReturnParentResultForDataRowDataDrivenTestsContainingSingleTest()
{
UTF.TestResult testResult = new UTF.TestResult();
testResult.ResultFiles = new List<string>() { "C:\\temp.txt" };
UTF.TestResult testResult = new UTF.TestResult
{
ResultFiles = new List<string>() { "C:\\temp.txt" }
};

var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);
Expand Down Expand Up @@ -871,7 +884,7 @@ private static void InitMethodThrowingException(UTFExtension.TestContext tc)

public class TestableTestmethodInfo : TestMethodInfo
{
private Func<UTF.TestResult> invokeTest;
private readonly Func<UTF.TestResult> invokeTest;

internal TestableTestmethodInfo(MethodInfo testMethod, TestClassInfo parent, TestMethodOptions testMethodOptions, Func<UTF.TestResult> invoke)
: base(testMethod, parent, testMethodOptions)
Expand Down

0 comments on commit 8b35d9a

Please sign in to comment.