Skip to content

Commit

Permalink
Tests for new factory methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch committed Jan 28, 2023
1 parent e6e51d9 commit 3132e3b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,28 @@ public void MeterProviderNestedResolutionUsingConfigureTest()
Assert.True(innerTestExecuted);
}

[Fact]
public void MeterProviderAddReaderFactoryTest()
{
bool factoryInvoked = false;

using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddReader(sp =>
{
factoryInvoked = true;

Assert.NotNull(sp);

return new MyReader();
})
.Build() as MeterProviderSdk;

Assert.True(factoryInvoked);

Assert.NotNull(meterProvider);
Assert.True(meterProvider.Reader is MyReader);
}

private static void RunBuilderServiceLifecycleTest(
MeterProviderBuilder builder,
Func<MeterProviderSdk> buildFunc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,50 @@ public void TracerProviderNestedResolutionUsingConfigureTest()
Assert.True(innerTestExecuted);
}

[Fact]
public void TracerProviderSetSamplerFactoryTest()
{
bool factoryInvoked = false;

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(sp =>
{
factoryInvoked = true;

Assert.NotNull(sp);

return new MySampler();
})
.Build() as TracerProviderSdk;

Assert.True(factoryInvoked);

Assert.NotNull(tracerProvider);
Assert.True(tracerProvider.Sampler is MySampler);
}

[Fact]
public void TracerProviderAddProcessorFactoryTest()
{
bool factoryInvoked = false;

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddProcessor(sp =>
{
factoryInvoked = true;

Assert.NotNull(sp);

return new MyProcessor();
})
.Build() as TracerProviderSdk;

Assert.True(factoryInvoked);

Assert.NotNull(tracerProvider);
Assert.True(tracerProvider.Processor is MyProcessor);
}

private static void RunBuilderServiceLifecycleTest(
TracerProviderBuilder builder,
Func<TracerProviderSdk> buildFunc,
Expand Down

0 comments on commit 3132e3b

Please sign in to comment.