Skip to content

Commit cebecd3

Browse files
authored
Drop FluentAssertions (#587)
1 parent c3e3493 commit cebecd3

17 files changed

+89
-139
lines changed

test/Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="FluentAssertions" Version="6.12.0" />
1615
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
1716
<PackageReference Include="NSubstitute" Version="5.1.0" />
1817
<PackageReference Include="xunit" Version="2.8.1" />

test/Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests/ContinuousProfilerTests.cs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#if NET
2020

2121
using System.IO.Compression;
22-
using FluentAssertions;
23-
using FluentAssertions.Execution;
2422
using Google.Protobuf.Collections;
2523
using OpenTelemetry.Proto.Collector.Logs.V1;
2624
using OpenTelemetry.Proto.Common.V1;
@@ -49,7 +47,7 @@ public async Task SubmitAllocationSamples()
4947
RunTestApplication();
5048
var logsData = logsCollector.GetAllLogs();
5149

52-
logsData.Length.Should().BeGreaterOrEqualTo(expected: 1);
50+
Assert.True(logsData.Length > 0);
5351

5452
await DumpLogRecords(logsData);
5553

@@ -68,14 +66,11 @@ public async Task SubmitAllocationSamples()
6866
profiles.Add(profile);
6967
}
7068

71-
using (new AssertionScope())
72-
{
73-
AllShouldHaveBasicAttributes(logRecords, ConstantValuedAttributes("allocation"));
74-
ProfilesContainAllocationValue(profiles);
75-
RecordsContainFrameCountAttribute(logRecords);
76-
ResourceContainsExpectedAttributes(dataResourceLog.Resource);
77-
HasNameAndVersionSet(instrumentationLibraryLogs.Scope);
78-
}
69+
AllShouldHaveBasicAttributes(logRecords, ConstantValuedAttributes("allocation"));
70+
ProfilesContainAllocationValue(profiles);
71+
RecordsContainFrameCountAttribute(logRecords);
72+
ResourceContainsExpectedAttributes(dataResourceLog.Resource);
73+
HasNameAndVersionSet(instrumentationLibraryLogs.Scope);
7974

8075
logRecords.Clear();
8176
}
@@ -94,7 +89,7 @@ public async Task SubmitThreadSamples()
9489
var logsData = logsCollector.GetAllLogs();
9590
// The application works for 6 seconds with debug logging enabled we expect at least 2 attempts of thread sampling in CI.
9691
// On a dev box it is typical to get at least 4 but the CI machines seem slower, using 2
97-
logsData.Length.Should().BeGreaterOrEqualTo(expected: 2);
92+
Assert.True(logsData.Length > 2);
9893

9994
await DumpLogRecords(logsData);
10095

@@ -118,14 +113,11 @@ public async Task SubmitThreadSamples()
118113

119114
containStackTraceForClassHierarchy |= profiles.Any(profile => ContainsStackTrace(profile, expectedStackTrace));
120115

121-
using (new AssertionScope())
122-
{
123-
AllShouldHaveBasicAttributes(logRecords, ConstantValuedAttributes("cpu"));
124-
ProfilesDoNotContainAnyValue(profiles);
125-
RecordsContainFrameCountAttribute(logRecords);
126-
ResourceContainsExpectedAttributes(dataResourceLog.Resource);
127-
HasNameAndVersionSet(instrumentationLibraryLogs.Scope);
128-
}
116+
AllShouldHaveBasicAttributes(logRecords, ConstantValuedAttributes("cpu"));
117+
ProfilesDoNotContainAnyValue(profiles);
118+
RecordsContainFrameCountAttribute(logRecords);
119+
ResourceContainsExpectedAttributes(dataResourceLog.Resource);
120+
HasNameAndVersionSet(instrumentationLibraryLogs.Scope);
129121

130122
logRecords.Clear();
131123
}
@@ -137,23 +129,23 @@ private static void ProfilesContainAllocationValue(List<Profile> profiles)
137129
{
138130
foreach (var profile in profiles)
139131
{
140-
profile.Samples.All(x => x.Values.Length == 1).Should().BeTrue();
132+
Assert.All(profile.Samples, x => Assert.Single(x.Values));
141133
}
142134
}
143135

144136
private static void ProfilesDoNotContainAnyValue(List<Profile> profiles)
145137
{
146138
foreach (var profile in profiles)
147139
{
148-
profile.Samples.All(x => x.Values.Length == 0).Should().BeTrue();
140+
Assert.All(profile.Samples, x => Assert.Empty(x.Values));
149141
}
150142
}
151143

152144
private static void RecordsContainFrameCountAttribute(RepeatedField<LogRecord> logRecords)
153145
{
154146
foreach (var logRecord in logRecords)
155147
{
156-
logRecord.Attributes.Should().Contain(attr => attr.Key == "profiling.data.total.frame.count");
148+
Assert.Single(logRecord.Attributes, attr => attr.Key == "profiling.data.total.frame.count");
157149
}
158150
}
159151

@@ -185,7 +177,7 @@ private static void AllShouldHaveBasicAttributes(RepeatedField<LogRecord> logRec
185177
{
186178
foreach (var attribute in attributes)
187179
{
188-
logRecord.Attributes.Should().ContainEquivalentOf(attribute);
180+
Assert.Contains(attribute, logRecord.Attributes);
189181
}
190182
}
191183
}
@@ -208,8 +200,8 @@ private static void ResourceContainsExpectedAttributes(global::OpenTelemetry.Pro
208200

209201
private static void HasNameAndVersionSet(InstrumentationScope instrumentationScope)
210202
{
211-
instrumentationScope.Name.Should().Be("otel.profiling");
212-
instrumentationScope.Version.Should().Be("0.1.0");
203+
Assert.Equal("otel.profiling", instrumentationScope.Name);
204+
Assert.Equal("0.1.0", instrumentationScope.Version);
213205
}
214206

215207
private static bool ContainsStackTrace(Profile profile, string expectedStackTrace)

test/Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests/Helpers/ResourceExpectorExtensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// </copyright>
1616

1717
using System.Reflection;
18-
using FluentAssertions;
1918
using OpenTelemetry.Proto.Common.V1;
2019
using OpenTelemetry.Proto.Resource.V1;
2120

@@ -52,11 +51,11 @@ internal static void AssertProfileResources(Resource resource)
5251

5352
foreach (var constantAttribute in constantAttributes)
5453
{
55-
resource.Attributes.Should().ContainEquivalentOf(constantAttribute);
54+
Assert.Contains(constantAttribute, resource.Attributes);
5655
}
5756

5857
// asserting resource attribute without values
59-
resource.Attributes.Should().Contain(value => value.Key == "host.name");
60-
resource.Attributes.Should().Contain(value => value.Key == "process.pid");
58+
Assert.Single(resource.Attributes, value => value.Key == "host.name");
59+
Assert.Single(resource.Attributes, value => value.Key == "process.pid");
6160
}
6261
}

test/Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests/Helpers/TestHelper.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
using System.Diagnostics;
3636
using System.Reflection;
37-
using FluentAssertions;
3837
using Xunit.Abstractions;
3938

4039
namespace Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests.Helpers;
@@ -147,8 +146,8 @@ public void RunTestApplication(TestSettings testSettings = null)
147146
Output.WriteLine("Exit Code: " + process.ExitCode);
148147
Output.WriteResult(helper);
149148

150-
processTimeout.Should().BeFalse("Test application timed out");
151-
process.ExitCode.Should().Be(0, "Test application exited with non-zero exit code");
149+
Assert.False(processTimeout, "Test application timed out");
150+
Assert.Equal(0, process.ExitCode);
152151
}
153152

154153
/// <summary>

test/Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests/SelfContainedTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
// limitations under the License.
3131
// </copyright>
3232

33-
using FluentAssertions;
3433
using Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests.Helpers;
3534
using Xunit.Abstractions;
3635

@@ -50,7 +49,7 @@ public SelfContainedTests(ITestOutputHelper output)
5049
// The self-contained app is going to have an extra folder before it: the one
5150
// with a RID like "win-x64", "linux-x64", etc.
5251
var childrenDirs = Directory.GetDirectories(nonSelfContainedOutputDir);
53-
childrenDirs.Should().ContainSingle();
52+
Assert.Single(childrenDirs);
5453

5554
_selfContainedAppDir = childrenDirs[0];
5655
}
@@ -92,7 +91,7 @@ private void RunInstrumentationTarget(string instrumentationTarget)
9291
using var process = InstrumentedProcessHelper.Start(instrumentationScriptPath, instrumentationTarget, EnvironmentHelper);
9392
using var helper = new ProcessHelper(process);
9493

95-
process.Should().NotBeNull();
94+
Assert.NotNull(process);
9695

9796
bool processTimeout = !process!.WaitForExit((int)Helpers.Timeout.ProcessExit.TotalMilliseconds);
9897
if (processTimeout)
@@ -104,8 +103,8 @@ private void RunInstrumentationTarget(string instrumentationTarget)
104103
Output.WriteLine("Exit Code: " + process.ExitCode);
105104
Output.WriteResult(helper);
106105

107-
processTimeout.Should().BeFalse("test application should NOT have timed out");
108-
process.ExitCode.Should().Be(0, "test application should NOT have non-zero exit code");
106+
Assert.False(processTimeout, "test application should NOT have timed out");
107+
Assert.Equal(0, process.ExitCode);
109108
}
110109

111110
private void RunAndAssertHttpSpans(Action appLauncherAction)

test/Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests/ServerTimingHeaderTests.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
#if NET
1818

19-
using FluentAssertions;
20-
using FluentAssertions.Execution;
2119
using Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests.Helpers;
2220
using Xunit.Abstractions;
2321

@@ -50,7 +48,8 @@ public async Task SubmitRequest(bool isEnabled, bool captureHeaders)
5048
{
5149
if (captureHeaders)
5250
{
53-
return span.Attributes.FirstOrDefault(x => x.Key == "http.request.header.custom-request-test-header")?.Value.StringValue == "Test-Value";
51+
return span.Attributes.FirstOrDefault(x => x.Key == "http.request.header.custom-request-test-header")
52+
?.Value.StringValue == "Test-Value";
5453
}
5554

5655
return true;
@@ -79,18 +78,15 @@ public async Task SubmitRequest(bool isEnabled, bool captureHeaders)
7978

8079
Output.WriteResult(helper);
8180

82-
using (new AssertionScope())
81+
if (isEnabled)
8382
{
84-
if (isEnabled)
85-
{
86-
response.Headers.Should().Contain(x => x.Key == "Server-Timing");
87-
response.Headers.Should().Contain(x => x.Key == "Access-Control-Expose-Headers");
88-
}
89-
else
90-
{
91-
response.Headers.Should().NotContain(x => x.Key == "Server-Timing");
92-
response.Headers.Should().NotContain(x => x.Key == "Access-Control-Expose-Headers");
93-
}
83+
Assert.Single(response.Headers, x => x.Key == "Server-Timing");
84+
Assert.Single(response.Headers, x => x.Key == "Access-Control-Expose-Headers");
85+
}
86+
else
87+
{
88+
Assert.DoesNotContain(response.Headers, x => x.Key == "Server-Timing");
89+
Assert.DoesNotContain(response.Headers, x => x.Key == "Access-Control-Expose-Headers");
9490
}
9591

9692
collector.AssertExpectations();

test/Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests/SmokeTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
// limitations under the License.
3131
// </copyright>
3232

33-
using FluentAssertions;
3433
using Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests.Helpers;
3534
using Xunit.Abstractions;
3635

@@ -181,7 +180,7 @@ public void ManagedLogsHaveNoSensitiveData()
181180

182181
var managedLog = tempLogsDirectory.GetFiles("otel-dotnet-auto-*-Splunk-*.log").Single();
183182
var managedLogContent = File.ReadAllText(managedLog.FullName);
184-
managedLogContent.Should().NotBeNullOrWhiteSpace();
183+
Assert.False(string.IsNullOrWhiteSpace(managedLogContent));
185184

186185
var environmentVariables = ParseSettingsLog(managedLogContent, "Environment Variables:");
187186
VerifyVariables(environmentVariables);
@@ -198,14 +197,14 @@ public void ManagedLogsHaveNoSensitiveData()
198197

199198
void VerifyVariables(ICollection<KeyValuePair<string, string>> options)
200199
{
201-
options.Should().NotBeEmpty();
200+
Assert.NotEmpty(options);
202201

203202
var secretVariables = options
204203
.Where(item => secretIdentificators.Any(i => item.Key.Contains(i)))
205204
.ToList();
206205

207-
secretVariables.Should().NotBeEmpty();
208-
secretVariables.Should().AllSatisfy(secret => secret.Value.Should().Be("<hidden>"));
206+
Assert.NotEmpty(secretVariables);
207+
Assert.All(secretVariables, secret => Assert.Equal("<hidden>", secret.Value));
209208
}
210209
}
211210

test/Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests/Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<!-- Suppress warnings about lowercase variable names in generated code -->
@@ -36,7 +36,6 @@
3636
</ItemGroup>
3737

3838
<ItemGroup>
39-
<PackageReference Update="FluentAssertions" Version="7.0.0" />
4039
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.12.0" />
4140
<PackageReference Update="NSubstitute" Version="5.3.0" />
4241
<PackageReference Update="xunit" Version="2.9.2" />

test/Splunk.OpenTelemetry.AutoInstrumentation.Tests/ExporterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void ConfigureOtlpOptions_EndpointSpecified()
3333
var options = new OtlpExporterOptions();
3434
new Metrics(settings).ConfigureMetricsOptions(options);
3535

36-
options.Endpoint.Should().Be(endpoint);
36+
Assert.StartsWith(endpoint, options.Endpoint.ToString());
3737

3838
Environment.SetEnvironmentVariable("SPLUNK_REALM", null);
3939
Environment.SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", null);

test/Splunk.OpenTelemetry.AutoInstrumentation.Tests/LoggerTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ public class LoggerTests
2323
[Fact]
2424
public void ConstructorDoesNotThrowExceptionWhenReflectionFails()
2525
{
26-
var action = () => new Logger();
27-
action.Should().NotThrow();
26+
_ = new Logger();
2827
}
2928

3029
[Fact]
3130
public void ImplementationDoesNotThrowExceptionWhenReflectionFails()
3231
{
33-
ILogger logger = new Logger();
34-
var action = () => logger.Warning("message");
35-
action.Should().NotThrow();
32+
var logger = new Logger();
33+
logger.Warning("message");
3634
}
3735
}

0 commit comments

Comments
 (0)