Skip to content

Commit e89dbe4

Browse files
committed
add CoverletInProcDataCollectorTests
1 parent c5f17c7 commit e89dbe4

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

src/coverlet.collector/InProcDataCollection/CoverletInProcDataCollector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void TestSessionStart(TestSessionStartArgs testSessionStartArgs)
8585
{
8686
}
8787

88-
private Type GetInstrumentationClass(Assembly assembly)
88+
internal Type GetInstrumentationClass(Assembly assembly)
8989
{
9090
try
9191
{
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) Toni Solarin-Sodara
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Reflection;
6+
using Coverlet.Collector.DataCollection;
7+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
8+
using Moq;
9+
using Xunit;
10+
11+
namespace Coverlet.Collector.Tests.DataCollection
12+
{
13+
public class CoverletInProcDataCollectorTests
14+
{
15+
private readonly CoverletInProcDataCollector _dataCollector;
16+
17+
public CoverletInProcDataCollectorTests()
18+
{
19+
_dataCollector = new CoverletInProcDataCollector();
20+
}
21+
22+
[Fact]
23+
public void GetInstrumentationClass_ShouldReturnNullForNonMatchingType_EnabledLogging()
24+
{
25+
// Arrange
26+
var dataCollectionSink = new Mock<IDataCollectionSink>();
27+
var mockAssembly = new Mock<Assembly>();
28+
var mockType = new Mock<Type>();
29+
mockType.Setup(t => t.Namespace).Returns("Coverlet.Core.Instrumentation.Tracker");
30+
mockType.Setup(t => t.Name).Returns("MockAssembly_Tracker");
31+
mockAssembly.Setup(a => a.GetTypes()).Returns(new[] { mockType.Object });
32+
Environment.SetEnvironmentVariable("COVERLET_DATACOLLECTOR_INPROC_EXCEPTIONLOG_ENABLED", "1");
33+
_dataCollector.Initialize(dataCollectionSink.Object);
34+
35+
// Act & Assert
36+
var results = _dataCollector.GetInstrumentationClass(mockAssembly.Object);
37+
38+
// Assert
39+
Assert.Null(results);
40+
}
41+
42+
[Fact]
43+
public void GetInstrumentationClass_ShouldReturnNullForNonMatchingType()
44+
{
45+
// Arrange
46+
var mockAssembly = new Mock<Assembly>();
47+
var mockType = new Mock<Type>();
48+
mockType.Setup(t => t.Namespace).Returns("NonMatchingNamespace");
49+
mockType.Setup(t => t.Name).Returns("NonMatchingName");
50+
mockAssembly.Setup(a => a.GetTypes()).Returns(new[] { mockType.Object });
51+
52+
// Act
53+
var result = _dataCollector.GetInstrumentationClass(mockAssembly.Object);
54+
55+
// Assert
56+
Assert.Null(result);
57+
}
58+
}
59+
}

test/coverlet.collector.tests/CoverletSettingsTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ public void ToString_ReturnsCorrectFormat()
1515
var settings = new CoverletSettings
1616
{
1717
TestModule = "TestModule.dll",
18-
ReportFormats = new[] { "json", "lcov" },
19-
IncludeFilters = new[] { "[*]*" },
20-
IncludeDirectories = new[] { "dir1", "dir2" },
21-
ExcludeFilters = new[] { "[*]ExcludeNamespace.*" },
22-
ExcludeSourceFiles = new[] { "file1.cs", "file2.cs" },
23-
ExcludeAttributes = new[] { "ExcludeAttribute" },
18+
ReportFormats = ["json", "lcov"],
19+
IncludeFilters = ["[*]*"],
20+
IncludeDirectories = ["dir1", "dir2"],
21+
ExcludeFilters = ["[*]ExcludeNamespace.*"],
22+
ExcludeSourceFiles = ["file1.cs", "file2.cs"],
23+
ExcludeAttributes = ["ExcludeAttribute"],
2424
MergeWith = "coverage.json",
2525
UseSourceLink = true,
2626
SingleHit = false,
2727
IncludeTestAssembly = true,
2828
SkipAutoProps = false,
29-
DoesNotReturnAttributes = new[] { "DoesNotReturn" },
29+
DoesNotReturnAttributes = ["DoesNotReturn"],
3030
DeterministicReport = true,
3131
ExcludeAssembliesWithoutSources = "true"
3232
};

0 commit comments

Comments
 (0)