Skip to content

Commit

Permalink
fixed a couple of ReSharper warnings, updated credits in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
csoltenborn committed Feb 13, 2016
1 parent a8c2777 commit 9e0bac8
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void UpdateTestDurations_SimpleTests_DurationsAreWrittenAndReadCorrectly(
ToTestResult("TestSuite1.SkippedTest", Model.TestOutcome.Skipped, 1, tempFile)
};

TestDurationSerializer serializer = new TestDurationSerializer(TestEnvironment);
var serializer = new TestDurationSerializer();
serializer.UpdateTestDurations(testResults);

string durationsFile = GetDurationsFile(serializer, tempFile);
Expand All @@ -47,7 +47,7 @@ public void UpdateTestDurations_SameTestsInDifferentExecutables_DurationsAreWrit
ToTestResult("TestSuite1.Test1", Model.TestOutcome.Failed, 4, tempFile2)
};

TestDurationSerializer serializer = new TestDurationSerializer(TestEnvironment);
var serializer = new TestDurationSerializer();
serializer.UpdateTestDurations(testResults);

string durationsFile1 = GetDurationsFile(serializer, tempFile);
Expand Down Expand Up @@ -75,7 +75,7 @@ public void UpdateTestDurations_SingleTest_DurationIsUpdatedCorrectly()
ToTestResult("TestSuite1.Test1", Model.TestOutcome.Passed, 3, tempFile)
};

TestDurationSerializer serializer = new TestDurationSerializer(TestEnvironment);
var serializer = new TestDurationSerializer();
serializer.UpdateTestDurations(testResults);
IDictionary<Model.TestCase, int> durations = serializer.ReadTestDurations(testResults.Select(tr => tr.TestCase));
Assert.AreEqual(3, durations[testResults[0].TestCase]);
Expand All @@ -95,7 +95,7 @@ public void ReadTestDurations_NoDurationFile_EmptyDictionary()
{
string tempFile = Path.GetTempFileName();

TestDurationSerializer serializer = new TestDurationSerializer(TestEnvironment);
var serializer = new TestDurationSerializer();
IDictionary<Model.TestCase, int> durations = serializer.ReadTestDurations(ToTestCase("TestSuite1.Test1", tempFile).Yield());

Assert.IsNotNull(durations);
Expand All @@ -111,7 +111,7 @@ public void ReadTestDurations_DurationFileWithoutCurrentTest_EmptyDictionary()
ToTestResult("TestSuite1.Test1", Model.TestOutcome.None, 3, tempFile)
};

TestDurationSerializer serializer = new TestDurationSerializer(TestEnvironment);
var serializer = new TestDurationSerializer();
serializer.UpdateTestDurations(testResults);

IDictionary<Model.TestCase, int> durations = serializer.ReadTestDurations(
Expand Down
3 changes: 1 addition & 2 deletions GoogleTestAdapter/Core/GoogleTestExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq;
using System.Collections.Generic;
using GoogleTestAdapter.Helpers;
using GoogleTestAdapter.Model;
Expand Down
4 changes: 2 additions & 2 deletions GoogleTestAdapter/Core/Helpers/TestCaseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ private IEnumerable<string> GetTypedTestMethodSignatures(TestCaseDescriptor desc
List<string> result = new List<string>();

// remove instance number
string suite = descriptor.Suite.Substring(0, descriptor.Suite.LastIndexOf("/"));
string suite = descriptor.Suite.Substring(0, descriptor.Suite.LastIndexOf("/", StringComparison.Ordinal));

// remove prefix
if (suite.Contains("/"))
{
int index = suite.IndexOf("/");
int index = suite.IndexOf("/", StringComparison.Ordinal);
suite = suite.Substring(index + 1, suite.Length - index - 1);
}

Expand Down
3 changes: 1 addition & 2 deletions GoogleTestAdapter/Core/Helpers/TestProcessLauncher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics;
using GoogleTestAdapter.Framework;

Expand Down
3 changes: 1 addition & 2 deletions GoogleTestAdapter/Core/Model/TestCase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;

namespace GoogleTestAdapter.Model
{
Expand Down
2 changes: 1 addition & 1 deletion GoogleTestAdapter/Core/Runners/ParallelTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase>

private ITestsSplitter GetTestsSplitter(TestCase[] testCasesToRun)
{
TestDurationSerializer serializer = new TestDurationSerializer(TestEnvironment);
var serializer = new TestDurationSerializer();
IDictionary<TestCase, int> durations = serializer.ReadTestDurations(testCasesToRun);

ITestsSplitter splitter;
Expand Down
8 changes: 4 additions & 4 deletions GoogleTestAdapter/Core/Runners/PreparingTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace GoogleTestAdapter.Runners
{
public class PreparingTestRunner : ITestRunner
{
public const string TEST_SETUP = "Test setup";
public const string TEST_TEARDOWN = "Test teardown";
public const string TestSetup = "Test setup";
public const string TestTeardown = "Test teardown";

private TestEnvironment TestEnvironment { get; }
private ITestRunner InnerTestRunner { get; }
Expand Down Expand Up @@ -42,13 +42,13 @@ public void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> t

string batch = TestEnvironment.Options.GetBatchForTestSetup(SolutionDirectory, testDirectory, ThreadId);
batch = batch == "" ? "" : SolutionDirectory + batch;
SafeRunBatch(TEST_SETUP, SolutionDirectory, batch, isBeingDebugged);
SafeRunBatch(TestSetup, SolutionDirectory, batch, isBeingDebugged);

InnerTestRunner.RunTests(allTestCases, testCasesToRun, userParameters, isBeingDebugged, debuggedLauncher);

batch = TestEnvironment.Options.GetBatchForTestTeardown(SolutionDirectory, testDirectory, ThreadId);
batch = batch == "" ? "" : SolutionDirectory + batch;
SafeRunBatch(TEST_TEARDOWN, SolutionDirectory, batch, isBeingDebugged);
SafeRunBatch(TestTeardown, SolutionDirectory, batch, isBeingDebugged);

stopwatch.Stop();
TestEnvironment.DebugInfo($"Thread {ThreadId} took {stopwatch.Elapsed}");
Expand Down
4 changes: 2 additions & 2 deletions GoogleTestAdapter/Core/Runners/SequentialTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ private void RunTestsFromExecutable(string executable,
{
string resultXmlFile = Path.GetTempFileName();
string workingDir = Path.GetDirectoryName(executable);
TestDurationSerializer serializer = new TestDurationSerializer(TestEnvironment);
var serializer = new TestDurationSerializer();

CommandLineGenerator generator = new CommandLineGenerator(allTestCases, testCasesToRun, executable.Length, userParameters, resultXmlFile, TestEnvironment);
var generator = new CommandLineGenerator(allTestCases, testCasesToRun, executable.Length, userParameters, resultXmlFile, TestEnvironment);
foreach (CommandLineGenerator.Args arguments in generator.GetCommandLines())
{
if (Canceled)
Expand Down
10 changes: 2 additions & 8 deletions GoogleTestAdapter/Core/Scheduling/TestDurationSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace GoogleTestAdapter.Scheduling
[XmlRoot]
public class GtaTestDurations
{
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public string Executable { get; set; }
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global
public List<TestDuration> TestDurations { get; set; } = new List<TestDuration>();
}

Expand Down Expand Up @@ -40,15 +42,7 @@ public class TestDurationSerializer
private static object Lock { get; } = new object();
private static readonly TestDuration Default = new TestDuration();


private XmlSerializer Serializer { get; } = new XmlSerializer(typeof(GtaTestDurations));
private TestEnvironment TestEnvironment { get; }


public TestDurationSerializer(TestEnvironment testEnvironment)
{
this.TestEnvironment = testEnvironment;
}


public IDictionary<TestCase, int> ReadTestDurations(IEnumerable<TestCase> testcases)
Expand Down
4 changes: 2 additions & 2 deletions GoogleTestAdapter/DiaResolver/DiaResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.IO;
using Dia;
using System.Runtime.InteropServices;
// ReSharper disable InconsistentNaming

namespace GoogleTestAdapter.DiaResolver
{
Expand Down Expand Up @@ -58,7 +58,7 @@ private bool TryCreateDiaInstance(Guid clsid)
try
{
Type comType = Type.GetTypeFromCLSID(clsid);
DiaDataSource = (IDiaDataSource)System.Activator.CreateInstance(comType);
DiaDataSource = (IDiaDataSource)Activator.CreateInstance(comType);
return true;
}
catch (Exception)
Expand Down
22 changes: 11 additions & 11 deletions GoogleTestAdapter/TestAdapter.Tests/AbstractTestExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ public virtual void RunTests_WithSetupAndTeardownBatchesWhereTeardownFails_LogsW
RunAndVerifyTests(X86ExternallyLinkedTests, 2, 0, 0);

MockLogger.Verify(l => l.LogWarning(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_SETUP))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestSetup))),
Times.Never);
MockLogger.Verify(l => l.LogWarning(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_TEARDOWN))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestTeardown))),
Times.AtLeastOnce());
}

Expand All @@ -146,10 +146,10 @@ public virtual void RunTests_WithSetupAndTeardownBatchesWhereSetupFails_LogsWarn
RunAndVerifyTests(X64ExternallyLinkedTests, 2, 0, 0);

MockLogger.Verify(l => l.LogWarning(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_SETUP))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestSetup))),
Times.AtLeastOnce());
MockLogger.Verify(l => l.LogWarning(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_TEARDOWN))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestTeardown))),
Times.Never);
}

Expand All @@ -159,22 +159,22 @@ public virtual void RunTests_WithoutBatches_NoLogging()
RunAndVerifyTests(X64ExternallyLinkedTests, 2, 0, 0);

MockLogger.Verify(l => l.LogInfo(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_SETUP))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestSetup))),
Times.Never);
MockLogger.Verify(l => l.LogWarning(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_SETUP))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestSetup))),
Times.Never);
MockLogger.Verify(l => l.LogError(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_SETUP))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestSetup))),
Times.Never);
MockLogger.Verify(l => l.LogInfo(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_TEARDOWN))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestTeardown))),
Times.Never);
MockLogger.Verify(l => l.LogWarning(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_TEARDOWN))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestTeardown))),
Times.Never);
MockLogger.Verify(l => l.LogError(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_TEARDOWN))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestTeardown))),
Times.Never);
}

Expand All @@ -186,7 +186,7 @@ public virtual void RunTests_WithNonexistingSetupBatch_LogsError()
RunAndVerifyTests(X64ExternallyLinkedTests, 2, 0, 0);

MockLogger.Verify(l => l.LogError(
It.Is<string>(s => s.Contains(PreparingTestRunner.TEST_SETUP.ToLower()))),
It.Is<string>(s => s.Contains(PreparingTestRunner.TestSetup.ToLower()))),
Times.AtLeastOnce());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using GoogleTestAdapter.Helpers;
using GoogleTestAdapter.Framework;
using System;
using GoogleTestAdapter.TestAdapter.Helpers;

namespace GoogleTestAdapter.TestAdapter.Helpers
namespace GoogleTestAdapter.TestAdapter.Framework
{
class VsTestFrameworkReporter : ITestFrameworkReporter
{
Expand All @@ -14,16 +14,13 @@ class VsTestFrameworkReporter : ITestFrameworkReporter
private IFrameworkHandle FrameworkHandle { get; }
private ITestCaseDiscoverySink Sink { get; }

private TestEnvironment TestEnvironment { get; }

private Throttle Throttle { get; }


public VsTestFrameworkReporter(ITestCaseDiscoverySink sink, IFrameworkHandle frameworkHandle, TestEnvironment testEnvironment)
public VsTestFrameworkReporter(ITestCaseDiscoverySink sink, IFrameworkHandle frameworkHandle)
{
Sink = sink;
FrameworkHandle = frameworkHandle;
TestEnvironment = testEnvironment;

// This is part of a workaround for a Visual Studio bug (see issue #15).
// If test results are reported too quickly (100 or more in 500ms), the
Expand Down
42 changes: 21 additions & 21 deletions GoogleTestAdapter/TestAdapter/Helpers/TestCaseFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ namespace GoogleTestAdapter.TestAdapter.Helpers

public class TestCaseFilter
{
private readonly IRunContext runContext;
private readonly TestEnvironment testEnvironment;
private IRunContext RunContext { get; }
private TestEnvironment TestEnvironment { get; }

private readonly IDictionary<string, TestProperty> testProperties = new Dictionary<string, TestProperty>(StringComparer.OrdinalIgnoreCase);
private readonly IDictionary<string, TestProperty> traitProperties = new Dictionary<string, TestProperty>(StringComparer.OrdinalIgnoreCase);
private IDictionary<string, TestProperty> TestPropertiesMap { get; } = new Dictionary<string, TestProperty>(StringComparer.OrdinalIgnoreCase);
private IDictionary<string, TestProperty> TraitPropertiesMap { get; } = new Dictionary<string, TestProperty>(StringComparer.OrdinalIgnoreCase);

private IEnumerable<string> TestProperties => testProperties.Keys;
private IEnumerable<string> TraitProperties => traitProperties.Keys;
private IEnumerable<string> TestProperties => TestPropertiesMap.Keys;
private IEnumerable<string> TraitProperties => TraitPropertiesMap.Keys;
private IEnumerable<string> AllProperties => TestProperties.Union(TraitProperties);

public TestCaseFilter(IRunContext runContext, ISet<string> traitNames, TestEnvironment testEnvironment)
{
this.runContext = runContext;
this.testEnvironment = testEnvironment;
this.RunContext = runContext;
this.TestEnvironment = testEnvironment;

InitProperties(traitNames);
}
Expand All @@ -43,30 +43,30 @@ public bool Matches(TestCase testCase)

private void InitProperties(ISet<string> traitNames)
{
testProperties[nameof(TestCaseProperties.FullyQualifiedName)] = TestCaseProperties.FullyQualifiedName;
testProperties[nameof(TestCaseProperties.DisplayName)] = TestCaseProperties.DisplayName;
testProperties[nameof(TestCaseProperties.LineNumber)] = TestCaseProperties.LineNumber;
testProperties[nameof(TestCaseProperties.CodeFilePath)] = TestCaseProperties.CodeFilePath;
testProperties[nameof(TestCaseProperties.ExecutorUri)] = TestCaseProperties.ExecutorUri;
testProperties[nameof(TestCaseProperties.Id)] = TestCaseProperties.Id;
testProperties[nameof(TestCaseProperties.Source)] = TestCaseProperties.Source;
TestPropertiesMap[nameof(TestCaseProperties.FullyQualifiedName)] = TestCaseProperties.FullyQualifiedName;
TestPropertiesMap[nameof(TestCaseProperties.DisplayName)] = TestCaseProperties.DisplayName;
TestPropertiesMap[nameof(TestCaseProperties.LineNumber)] = TestCaseProperties.LineNumber;
TestPropertiesMap[nameof(TestCaseProperties.CodeFilePath)] = TestCaseProperties.CodeFilePath;
TestPropertiesMap[nameof(TestCaseProperties.ExecutorUri)] = TestCaseProperties.ExecutorUri;
TestPropertiesMap[nameof(TestCaseProperties.Id)] = TestCaseProperties.Id;
TestPropertiesMap[nameof(TestCaseProperties.Source)] = TestCaseProperties.Source;

foreach (string traitName in traitNames)
{
var traitTestProperty = TestProperty.Find(traitName) ??
TestProperty.Register(traitName, traitName, typeof(string), typeof(TestCase));
traitProperties[traitName] = traitTestProperty;
TraitPropertiesMap[traitName] = traitTestProperty;
}
}

private TestProperty PropertyProvider(string propertyName)
{
TestProperty testProperty;

testProperties.TryGetValue(propertyName, out testProperty);
TestPropertiesMap.TryGetValue(propertyName, out testProperty);

if (testProperty == null)
traitProperties.TryGetValue(propertyName, out testProperty);
TraitPropertiesMap.TryGetValue(propertyName, out testProperty);

return testProperty;
}
Expand All @@ -88,12 +88,12 @@ private object PropertyValueProvider(TestCase currentTest, string propertyName)

private ITestCaseFilterExpression GetFilterExpression()
{
ITestCaseFilterExpression filterExpression = runContext.GetTestCaseFilter(AllProperties, PropertyProvider);
ITestCaseFilterExpression filterExpression = RunContext.GetTestCaseFilter(AllProperties, PropertyProvider);

string message = filterExpression == null
? "No test case filter provided"
: $"Test case filter: {filterExpression.TestCaseFilterValue}";
testEnvironment.DebugInfo(message);
TestEnvironment.DebugInfo(message);

return filterExpression;
}
Expand All @@ -117,7 +117,7 @@ private bool Matches(TestCase testCase, ITestCaseFilterExpression filterExpressi
string message = matches
? $"{testCase.DisplayName} matches {filterExpression.TestCaseFilterValue}"
: $"{testCase.DisplayName} does not match {filterExpression.TestCaseFilterValue}";
testEnvironment.DebugInfo(message);
TestEnvironment.DebugInfo(message);

return matches;
}
Expand Down
3 changes: 0 additions & 3 deletions GoogleTestAdapter/TestAdapter/Helpers/Throttle.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace GoogleTestAdapter.TestAdapter.Helpers
{
Expand Down
3 changes: 0 additions & 3 deletions GoogleTestAdapter/TestAdapter/Settings/RunSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ public RunSettings()
public int? ReportWaitPeriod { get; set; }
public bool ShouldSerializeReportWaitPeriod() { return ReportWaitPeriod != null; }

public bool? DevelopmentMode { get; set; }
public bool ShouldSerializeDevelopmentMode() { return DevelopmentMode != null; }


public override XmlElement ToXml()
{
Expand Down
Loading

0 comments on commit 9e0bac8

Please sign in to comment.