Removed Moq dependency from Instrumentation.SqlClient.Tests (#5125)
This commit is contained in:
parent
fba99e1254
commit
a3d2fec0f2
|
|
@ -17,7 +17,6 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="Moq" />
|
||||
<PackageReference Include="Testcontainers.MsSql" />
|
||||
<PackageReference Include="Testcontainers.SqlEdge" />
|
||||
<PackageReference Include="xunit" />
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ using System.Data;
|
|||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Tracing;
|
||||
using Moq;
|
||||
using OpenTelemetry.Instrumentation.SqlClient.Implementation;
|
||||
using OpenTelemetry.Tests;
|
||||
using OpenTelemetry.Trace;
|
||||
|
|
@ -48,9 +47,9 @@ public class SqlEventSourceTests
|
|||
[InlineData(CommandType.StoredProcedure, "sp_who", true)]
|
||||
public async Task SuccessfulCommandTest(CommandType commandType, string commandText, bool captureText, bool isFailure = false)
|
||||
{
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
var exportedItems = new List<Activity>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddInMemoryExporter(exportedItems)
|
||||
.AddSqlClientInstrumentation(options =>
|
||||
{
|
||||
options.SetDbStatementForText = captureText;
|
||||
|
|
@ -78,9 +77,8 @@ public class SqlEventSourceTests
|
|||
{
|
||||
}
|
||||
|
||||
Assert.Equal(3, activityProcessor.Invocations.Count);
|
||||
|
||||
var activity = (Activity)activityProcessor.Invocations[1].Arguments[0];
|
||||
Assert.Single(exportedItems);
|
||||
var activity = exportedItems[0];
|
||||
|
||||
VerifyActivityData(commandText, captureText, isFailure, dataSource, activity);
|
||||
}
|
||||
|
|
@ -105,9 +103,9 @@ public class SqlEventSourceTests
|
|||
{
|
||||
using IFakeBehavingSqlEventSource fakeSqlEventSource = (IFakeBehavingSqlEventSource)Activator.CreateInstance(eventSourceType);
|
||||
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
var exportedItems = new List<Activity>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddInMemoryExporter(exportedItems)
|
||||
.AddSqlClientInstrumentation(options =>
|
||||
{
|
||||
options.SetDbStatementForText = captureText;
|
||||
|
|
@ -132,9 +130,9 @@ public class SqlEventSourceTests
|
|||
|
||||
fakeSqlEventSource.WriteEndExecuteEvent(objectId, compositeState, sqlExceptionNumber);
|
||||
shutdownSignal.Dispose();
|
||||
Assert.Equal(5, activityProcessor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called.
|
||||
Assert.Single(exportedItems);
|
||||
|
||||
var activity = (Activity)activityProcessor.Invocations[2].Arguments[0];
|
||||
var activity = exportedItems[0];
|
||||
|
||||
VerifyActivityData(commandText, captureText, isFailure, "127.0.0.1", activity, enableConnectionLevelAttributes);
|
||||
}
|
||||
|
|
@ -146,9 +144,9 @@ public class SqlEventSourceTests
|
|||
{
|
||||
using IFakeMisbehavingSqlEventSource fakeSqlEventSource = (IFakeMisbehavingSqlEventSource)Activator.CreateInstance(eventSourceType);
|
||||
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
var exportedItems = new List<Activity>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddInMemoryExporter(exportedItems)
|
||||
.AddSqlClientInstrumentation()
|
||||
.Build();
|
||||
|
||||
|
|
@ -156,7 +154,7 @@ public class SqlEventSourceTests
|
|||
|
||||
shutdownSignal.Dispose();
|
||||
|
||||
Assert.Equal(3, activityProcessor.Invocations.Count); // SetTracerProvider/OnShutdown/Dispose called.
|
||||
Assert.Empty(exportedItems);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -166,9 +164,9 @@ public class SqlEventSourceTests
|
|||
{
|
||||
using IFakeMisbehavingSqlEventSource fakeSqlEventSource = (IFakeMisbehavingSqlEventSource)Activator.CreateInstance(eventSourceType);
|
||||
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
var exportedItems = new List<Activity>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddInMemoryExporter(exportedItems)
|
||||
.AddSqlClientInstrumentation()
|
||||
.Build();
|
||||
|
||||
|
|
@ -177,7 +175,7 @@ public class SqlEventSourceTests
|
|||
fakeSqlEventSource.WriteEndExecuteEvent("arg1", "arg2", "arg3", "arg4");
|
||||
shutdownSignal.Dispose();
|
||||
|
||||
Assert.Equal(3, activityProcessor.Invocations.Count); // SetTracerProvider/OnShutdown/Dispose called.
|
||||
Assert.Empty(exportedItems);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -187,9 +185,9 @@ public class SqlEventSourceTests
|
|||
{
|
||||
using IFakeBehavingSqlEventSource fakeSqlEventSource = (IFakeBehavingSqlEventSource)Activator.CreateInstance(eventSourceType);
|
||||
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
var exportedItems = new List<Activity>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddInMemoryExporter(exportedItems)
|
||||
.AddSqlClientInstrumentation()
|
||||
.Build();
|
||||
|
||||
|
|
@ -211,9 +209,9 @@ public class SqlEventSourceTests
|
|||
|
||||
fakeSqlEventSource.WriteEndExecuteEvent(objectId, compositeState, 0);
|
||||
shutdownSignal.Dispose();
|
||||
Assert.Equal(5, activityProcessor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called.
|
||||
Assert.Single(exportedItems);
|
||||
|
||||
var activity = (Activity)activityProcessor.Invocations[2].Arguments[0];
|
||||
var activity = exportedItems[0];
|
||||
|
||||
const bool captureText = false;
|
||||
VerifyActivityData(commandText, captureText, false, "127.0.0.1", activity, false);
|
||||
|
|
|
|||
Loading…
Reference in New Issue