Skip to content

Commit 979f49a

Browse files
committed
refactor options - including enumeration for ms code coverage. Add Newtonsoft.Json as nuget package as advised
1 parent d0d81ee commit 979f49a

22 files changed

+771
-133
lines changed

FineCodeCoverage/FineCodeCoverage.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
153153
<PrivateAssets>all</PrivateAssets>
154154
</PackageReference>
155+
<PackageReference Include="Newtonsoft.Json">
156+
<Version>13.0.1</Version>
157+
</PackageReference>
155158
<PackageReference Include="ReflectObject">
156159
<Version>1.0.0</Version>
157160
</PackageReference>

FineCodeCoverage2022/FineCodeCoverage2022.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
146146
<PrivateAssets>all</PrivateAssets>
147147
</PackageReference>
148+
<PackageReference Include="Newtonsoft.Json">
149+
<Version>13.0.1</Version>
150+
</PackageReference>
148151
<PackageReference Include="ReflectObject">
149152
<Version>1.0.0</Version>
150153
</PackageReference>

FineCodeCoverageTests/AppOptionsProvider_Tests.cs

Lines changed: 405 additions & 0 deletions
Large diffs are not rendered by default.

FineCodeCoverageTests/FCCEngine_Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void SetUp()
112112
};
113113

114114
var mockedAppOptions = mocker.GetMock<IAppOptions>();
115-
mockedAppOptions.Setup(x => x.MsCodeCoverage).Returns(false);
115+
mockedAppOptions.Setup(x => x.RunMsCodeCoverage).Returns(RunMsCodeCoverage.No);
116116
var mockAppOptionsProvider = mocker.GetMock<IAppOptionsProvider>();
117117
mockAppOptionsProvider.Setup(x => x.Get()).Returns(mockedAppOptions.Object);
118118
}

FineCodeCoverageTests/FineCodeCoverageTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<Compile Include="CoverageToolOutput_Tests\CoverageToolOutput_Exports_Tests.cs" />
111111
<Compile Include="CoverageToolOutput_Tests\FccOutputExistenceCoverageToolOutputFolderSolutionProvider_Tests.cs" />
112112
<Compile Include="CoverageToolOutput_Tests\SolutionFolderProvider_Tests.cs" />
113+
<Compile Include="AppOptionsProvider_Tests.cs" />
113114
<Compile Include="CoverageUtilManager_Tests.cs" />
114115
<Compile Include="MsCodeCoverage\ShimCopier_Tests.cs" />
115116
<Compile Include="MsCodeCoverage\TemplatedRunSettingsService_Tests.cs" />

FineCodeCoverageTests/MsCodeCoverage/MsCodeCoverageRunSettingsService_IsCollecting_Tests.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,25 @@ public void SetupSut()
8383
autoMocker = new AutoMoqer();
8484
msCodeCoverageRunSettingsService = autoMocker.Create<MsCodeCoverageRunSettingsService>();
8585
msCodeCoverageRunSettingsService.threadHelper = new TestThreadHelper();
86-
SetupAppOptionsProvider();
86+
SetupAppOptionsProvider(RunMsCodeCoverage.Yes);
87+
}
88+
89+
[Test]
90+
public async Task Should_Not_Be_Collecting_If_RunMsCodeCoverage_No()
91+
{
92+
SetupAppOptionsProvider(RunMsCodeCoverage.No);
93+
var testOperation = SetUpTestOperation(new List<ICoverageProject> { });
94+
var collectionStatus = await msCodeCoverageRunSettingsService.IsCollectingAsync(testOperation);
95+
96+
Assert.AreEqual(MsCodeCoverageCollectionStatus.NotCollecting, collectionStatus);
8797
}
8898

8999
[TestCase(true)]
90100
[TestCase(false)]
91101
public async Task Should_Try_Analyse_Projects_With_Runsettings(bool useMsCodeCoverageOption)
92102
{
93-
SetupAppOptionsProvider(useMsCodeCoverageOption);
103+
var runMsCodeCoverage = useMsCodeCoverageOption ? RunMsCodeCoverage.Yes : RunMsCodeCoverage.IfInRunSettings;
104+
SetupAppOptionsProvider(runMsCodeCoverage);
94105

95106
var fccMsTestAdapterPath = InitializeFCCMsTestAdapterPath();
96107

@@ -176,7 +187,7 @@ private Task<MsCodeCoverageCollectionStatus> Throw_Exception_From_UserRunSetting
176187
[Test]
177188
public async Task Should_Prepare_Coverage_Projects_When_Suitable()
178189
{
179-
SetupAppOptionsProvider(false);
190+
SetupAppOptionsProvider(RunMsCodeCoverage.IfInRunSettings);
180191

181192
var mockTemplatedCoverageProject = new Mock<ICoverageProject>();
182193
var mockCoverageProjects = new List<Mock<ICoverageProject>>
@@ -201,7 +212,7 @@ public async Task Should_Prepare_Coverage_Projects_When_Suitable()
201212
[Test]
202213
public async Task Should_Set_UserRunSettingsProjectDetailsLookup_For_IRunSettingsService_When_Suitable()
203214
{
204-
SetupAppOptionsProvider(false);
215+
SetupAppOptionsProvider(RunMsCodeCoverage.IfInRunSettings);
205216

206217
var projectSettings = new Mock<IAppOptions>().Object;
207218
var excludedReferencedProjects = new List<string>();
@@ -279,7 +290,8 @@ public Task Should_Generate_RunSettings_From_Templates_When_RunSettings_Specifie
279290

280291
public async Task GenerateRunSettingsFromTemplate(bool msCodeCoverageOptions, bool runSettingsSpecifiedMsCodeCoverage)
281292
{
282-
SetupAppOptionsProvider(msCodeCoverageOptions);
293+
var runMsCodeCoverage = msCodeCoverageOptions ? RunMsCodeCoverage.Yes : RunMsCodeCoverage.IfInRunSettings;
294+
SetupAppOptionsProvider(runMsCodeCoverage);
283295
SetupIUserRunSettingsServiceAnalyseAny().Returns(new UserRunSettingsAnalysisResult(true, runSettingsSpecifiedMsCodeCoverage));
284296

285297
var fccMsTestAdapterPath = InitializeFCCMsTestAdapterPath();
@@ -390,7 +402,7 @@ private Task<MsCodeCoverageCollectionStatus> ExceptionWhenGenerateRunSettingsFro
390402
[Test]
391403
public async Task Should_Not_Be_Collecting_When_Template_Projects_And_Do_Not_Ms_Collect()
392404
{
393-
SetupAppOptionsProvider(false);
405+
SetupAppOptionsProvider(RunMsCodeCoverage.IfInRunSettings);
394406
SetupIUserRunSettingsServiceAnalyseAny().Returns(new UserRunSettingsAnalysisResult(true, false));
395407

396408
var coverageProjects = new List<ICoverageProject>
@@ -475,11 +487,11 @@ private ITestOperation SetUpTestOperation(List<ICoverageProject> coverageProject
475487
return mockTestOperation.Object;
476488
}
477489

478-
private void SetupAppOptionsProvider(bool useMsCodeCoverage = true)
490+
private void SetupAppOptionsProvider(RunMsCodeCoverage runMsCodeCoverage)
479491
{
480492
var mockAppOptionsProvider = autoMocker.GetMock<IAppOptionsProvider>();
481493
var mockOptions = new Mock<IAppOptions>();
482-
mockOptions.Setup(options => options.MsCodeCoverage).Returns(useMsCodeCoverage);
494+
mockOptions.Setup(options => options.RunMsCodeCoverage).Returns(runMsCodeCoverage);
483495
mockAppOptionsProvider.Setup(appOptionsProvider => appOptionsProvider.Get()).Returns(mockOptions.Object);
484496
}
485497

FineCodeCoverageTests/MsCodeCoverage/RunSettingsTemplateReplacementsFactory_Tests.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -580,51 +580,51 @@ private static string ModulePathElement(string value)
580580
[ExcludeFromCodeCoverage]
581581
internal class TestCoverageProjectOptions : IAppOptions
582582
{
583-
public string[] Exclude => throw new NotImplementedException();
583+
public string[] Exclude { get; set; }
584584

585-
public string[] ExcludeByAttribute => throw new NotImplementedException();
585+
public string[] ExcludeByAttribute { get; set; }
586586

587-
public string[] ExcludeByFile => throw new NotImplementedException();
587+
public string[] ExcludeByFile { get; set; }
588588

589-
public string[] Include => throw new NotImplementedException();
589+
public string[] Include { get; set; }
590590

591-
public bool RunInParallel => throw new NotImplementedException();
591+
public bool RunInParallel { get; set; }
592592

593-
public int RunWhenTestsExceed => throw new NotImplementedException();
593+
public int RunWhenTestsExceed { get; set; }
594594

595-
public bool RunWhenTestsFail => throw new NotImplementedException();
595+
public bool RunWhenTestsFail { get; set; }
596596

597-
public bool RunSettingsOnly => throw new NotImplementedException();
597+
public bool RunSettingsOnly { get; set; }
598598

599-
public bool CoverletConsoleGlobal => throw new NotImplementedException();
599+
public bool CoverletConsoleGlobal { get; set; }
600600

601-
public string CoverletConsoleCustomPath => throw new NotImplementedException();
601+
public string CoverletConsoleCustomPath { get; set; }
602602

603-
public bool CoverletConsoleLocal => throw new NotImplementedException();
603+
public bool CoverletConsoleLocal { get; set; }
604604

605-
public string CoverletCollectorDirectoryPath => throw new NotImplementedException();
605+
public string CoverletCollectorDirectoryPath { get; set; }
606606

607-
public string OpenCoverCustomPath => throw new NotImplementedException();
607+
public string OpenCoverCustomPath { get; set; }
608608

609-
public string FCCSolutionOutputDirectoryName => throw new NotImplementedException();
609+
public string FCCSolutionOutputDirectoryName { get; set; }
610610

611-
public int ThresholdForCyclomaticComplexity => throw new NotImplementedException();
611+
public int ThresholdForCyclomaticComplexity { get; set; }
612612

613-
public int ThresholdForNPathComplexity => throw new NotImplementedException();
613+
public int ThresholdForNPathComplexity { get; set; }
614614

615-
public int ThresholdForCrapScore => throw new NotImplementedException();
615+
public int ThresholdForCrapScore { get; set; }
616616

617-
public bool CoverageColoursFromFontsAndColours => throw new NotImplementedException();
617+
public bool CoverageColoursFromFontsAndColours { get; set; }
618618

619-
public bool StickyCoverageTable => throw new NotImplementedException();
619+
public bool StickyCoverageTable { get; set; }
620620

621-
public bool NamespacedClasses => throw new NotImplementedException();
621+
public bool NamespacedClasses { get; set; }
622622

623-
public bool HideFullyCovered => throw new NotImplementedException();
623+
public bool HideFullyCovered { get; set; }
624624

625-
public bool AdjacentBuildOutput => throw new NotImplementedException();
625+
public bool AdjacentBuildOutput { get; set; }
626626

627-
public bool MsCodeCoverage { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
627+
public FineCodeCoverage.Options.RunMsCodeCoverage RunMsCodeCoverage { get; set; }
628628
public string[] ModulePathsExclude { get; set; }
629629
public string[] ModulePathsInclude { get; set; }
630630
public string[] CompanyNamesExclude { get; set; }
@@ -644,6 +644,6 @@ internal class TestCoverageProjectOptions : IAppOptions
644644

645645
public bool IncludeReferencedProjects { get; set; }
646646

647-
public string ToolsDirectory => throw new NotImplementedException();
647+
public string ToolsDirectory { get; set; }
648648
}
649649
}

FineCodeCoverageTests/TestContainerDiscovery_Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public void Should_ReloadCoverage_When_TestExecutionFinished_If_RunInParallel_An
208208
{
209209
mockAppOptions.Setup(o => o.Enabled).Returns(true);
210210
mockAppOptions.Setup(o => o.RunInParallel).Returns(true);
211-
mockAppOptions.Setup(o => o.MsCodeCoverage).Returns(true);
211+
mockAppOptions.Setup(o => o.RunMsCodeCoverage).Returns(RunMsCodeCoverage.Yes);
212212
});
213213
RaiseTestExecutionFinished(operation);
214214

SharedProject/Core/MsTestPlatform/CodeCoverage/MsCodeCoverageRunSettingsService.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public static async Task<CoverageProjectsByType> CreateAsync(ITestOperation test
8080
private bool useMsCodeCoverage;
8181

8282
internal MsCodeCoverageCollectionStatus collectionStatus; // for tests
83+
private RunMsCodeCoverage runMsCodeCoverage;
84+
8385
private bool IsCollecting => collectionStatus == MsCodeCoverageCollectionStatus.Collecting;
8486

8587
internal IThreadHelper threadHelper = new VsThreadHelper();
@@ -121,7 +123,12 @@ public void Initialize(string appDataFolder, IFCCEngine fccEngine, CancellationT
121123
public async Task<MsCodeCoverageCollectionStatus> IsCollectingAsync(ITestOperation testOperation)
122124
{
123125
await InitializeIsCollectingAsync(testOperation);
124-
await TrySetUpForCollectionAsync(testOperation.SolutionDirectory);
126+
127+
if (runMsCodeCoverage != RunMsCodeCoverage.No)
128+
{
129+
await TrySetUpForCollectionAsync(testOperation.SolutionDirectory);
130+
}
131+
125132
ReportEndOfCoverageRunIfError();
126133
return collectionStatus;
127134
}
@@ -167,7 +174,8 @@ private void ReportEndOfCoverageRunIfError()
167174
private Task InitializeIsCollectingAsync(ITestOperation testOperation)
168175
{
169176
collectionStatus = MsCodeCoverageCollectionStatus.NotCollecting;
170-
useMsCodeCoverage = appOptionsProvider.Get().MsCodeCoverage;
177+
runMsCodeCoverage = appOptionsProvider.Get().RunMsCodeCoverage;
178+
useMsCodeCoverage = runMsCodeCoverage == RunMsCodeCoverage.Yes;
171179
userRunSettingsProjectDetailsLookup = null;
172180
return CleanUpAsync(testOperation);
173181
}

SharedProject/Core/Utilities/ReflectionExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@ public static TCustomAttribute[] GetTypedCustomAttributes<TCustomAttribute>(this
1414
var attributes = customAttributeProvider.GetCustomAttributes(typeof(TCustomAttribute), inherit);
1515
return attributes as TCustomAttribute[];
1616
}
17+
18+
public static PropertyInfo[] GetInterfacePropertyInfos(this Type type)
19+
{
20+
return (new Type[] { type })
21+
.Concat(type.GetInterfaces())
22+
.SelectMany(i => i.GetProperties()).ToArray();
23+
}
1724
}
1825
}

0 commit comments

Comments
 (0)