-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generation of CodeCoverage.deps.json file #2627
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ namespace Microsoft.VisualStudio.TraceDataCollector.UnitTests | |
using Coverage.Interfaces; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using TestPlatform.ObjectModel.DataCollection; | ||
using TraceCollector; | ||
using TraceCollector.Interfaces; | ||
|
@@ -36,6 +38,7 @@ public class DynamicCoverageDataCollectorImplTests | |
private Mock<IDataCollectionLogger> dataCollectionLoggerMock; | ||
private Mock<IDirectoryHelper> directoryHelperMock; | ||
private Mock<IFileHelper> fileHelperMock; | ||
private Mock<IProfilersLocationProvider> profilersLocationProviderMock; | ||
|
||
private string aConfigFileName; | ||
private string atempDirectory; | ||
|
@@ -48,8 +51,9 @@ public DynamicCoverageDataCollectorImplTests() | |
this.dataCollectionLoggerMock = new Mock<IDataCollectionLogger>(); | ||
this.directoryHelperMock = new Mock<IDirectoryHelper>(); | ||
this.fileHelperMock = new Mock<IFileHelper>(); | ||
this.profilersLocationProviderMock = new Mock<IProfilersLocationProvider>(); | ||
this.tempSessionDir = null; | ||
this.collectorImpl = new DynamicCoverageDataCollectorImpl(this.vanguardMock.Object, this.directoryHelperMock.Object, this.fileHelperMock.Object); | ||
this.collectorImpl = new DynamicCoverageDataCollectorImpl(this.vanguardMock.Object, this.directoryHelperMock.Object, this.fileHelperMock.Object, this.profilersLocationProviderMock.Object); | ||
this.SetupForInitialize(); | ||
this.collectorImpl.Initialize(DynamicCoverageDataCollectorImplTests.sampleConfigurationElement, this.dataCollectionSinkMock.Object, this.dataCollectionLoggerMock.Object); | ||
} | ||
|
@@ -83,6 +87,48 @@ public void InitializeShouldCreateDefaultCodeCoverageSettingsIfConfigElementIsNu | |
this.CompareWithDefaultConfig(); | ||
} | ||
|
||
[TestMethod] | ||
public void InitializeShouldGenerateCodeCoverageDepsJsonFile() | ||
{ | ||
this.directoryHelperMock.Setup(d => d.CreateDirectory(It.IsAny<string>())) | ||
.Callback<string>((path) => Directory.CreateDirectory(path)); | ||
|
||
this.fileHelperMock.Setup(f => f.WriteAllText(It.IsAny<string>(), It.IsAny<string>())) | ||
.Callback<string, string>((path, content) => { File.WriteAllText(path, content); }); | ||
|
||
this.profilersLocationProviderMock.Setup(lp => lp.GetCodeCoverageShimPath()).Returns(@"C:\aaa\bbb\Microsoft.VisualStudio.CodeCoverage.Shim.dll"); | ||
|
||
this.collectorImpl.Initialize(null, this.dataCollectionSinkMock.Object, this.dataCollectionLoggerMock.Object); | ||
|
||
var obj = JObject.Parse(File.ReadAllText(this.collectorImpl.CodeCoverageDepsJsonFilePath)); | ||
|
||
var expected = @" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it's a json file, a new line shouldn't affect anything other than formatting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also this stuff is working only on Windows now |
||
{ | ||
""runtimeTarget"": { | ||
""name"": ""codecoverage"", | ||
""signature"": """" | ||
}, | ||
""targets"": { | ||
""codecoverage"": { | ||
""Microsoft.VisualStudio.CodeCoverage.Shim/15.0.0.0"": { | ||
""runtime"": { | ||
""C:/aaa/bbb/Microsoft.VisualStudio.CodeCoverage.Shim.dll"": { } | ||
} | ||
} | ||
} | ||
}, | ||
""libraries"": { | ||
""Microsoft.VisualStudio.CodeCoverage.Shim/15.0.0.0"": { | ||
""type"": ""reference"", | ||
""serviceable"": false, | ||
""sha512"": """" | ||
} | ||
} | ||
}"; | ||
|
||
Assert.AreEqual(expected.Trim(), File.ReadAllText(this.collectorImpl.CodeCoverageDepsJsonFilePath).Trim()); | ||
} | ||
|
||
[TestMethod] | ||
public void InitializeShouldInitializeVanguardWithRightCoverageSettings() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work in different platforms? Is it better to concatenate strings with
Environment.NewLine
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic is invoked only on windows now, new lines doesn't matter for JSON files