Table of Contents

Class OpenTelemetryServiceExtensionsCoverageTests

Namespace
ProjectTemplate.Web.Tests
Assembly
ProjectTemplate.Web.Tests.dll
public sealed class OpenTelemetryServiceExtensionsCoverageTests
Inheritance
OpenTelemetryServiceExtensionsCoverageTests
Inherited Members

Methods

AddApplicationOpenTelemetry_BlankServiceName_FailsOptionsValidation()

Verifies that when OpenTelemetry is enabled but the service name is blank, an OptionsValidationException is thrown indicating that the service name must not be empty.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/OpenTelemetryServiceExtensionsCoverageTests.cs", 99)]
public void AddApplicationOpenTelemetry_BlankServiceName_FailsOptionsValidation()

AddApplicationOpenTelemetry_Disabled_ReturnsSameServiceCollection()

Verifies that when OpenTelemetry is disabled, the service collection is returned without modification and no exceptions are thrown.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/OpenTelemetryServiceExtensionsCoverageTests.cs", 18)]
public void AddApplicationOpenTelemetry_Disabled_ReturnsSameServiceCollection()

AddApplicationOpenTelemetry_EnabledWithoutTracingOrMetrics_ReturnsSameServiceCollection()

Verifies that when OpenTelemetry is enabled but both tracing and metrics are disabled, the service collection is returned without modification and no exceptions are thrown.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/OpenTelemetryServiceExtensionsCoverageTests.cs", 39)]
public void AddApplicationOpenTelemetry_EnabledWithoutTracingOrMetrics_ReturnsSameServiceCollection()

AddApplicationOpenTelemetry_InvalidOtlpEndpoint_FailsOptionsValidation()

Verifies that when OpenTelemetry is enabled and OTLP export is enabled but the endpoint is not a valid absolute URI, an OptionsValidationException is thrown indicating that the endpoint must be a valid absolute URI when OTLP export is enabled.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/OpenTelemetryServiceExtensionsCoverageTests.cs", 126)]
public void AddApplicationOpenTelemetry_InvalidOtlpEndpoint_FailsOptionsValidation()

AddApplicationOpenTelemetry_TracingMetricsAndOtlpEnabled_ReturnsSameServiceCollection()

Verifies that when OpenTelemetry is enabled with both tracing and metrics enabled, and OTLP export is configured, the service collection is returned without modification and no exceptions are thrown.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/OpenTelemetryServiceExtensionsCoverageTests.cs", 68)]
public void AddApplicationOpenTelemetry_TracingMetricsAndOtlpEnabled_ReturnsSameServiceCollection()

ConfigureOtlpExporter_ConfiguresEndpointAndProtocol(string, OtlpExportProtocol)

Verifies that the ConfigureOtlpExporter method correctly configures the OtlpExporterOptions based on the provided ApplicationOtlpExporterOptions, including parsing the protocol string and setting the endpoint URI. The test covers various protocol string cases (e.g., "HttpProtobuf", "httpprotobuf", "Grpc", and an unknown value) to ensure that the correct OtlpExportProtocol enum value is set in the exporter options. Additionally, it verifies that the endpoint is correctly parsed into a Uri object.

[Theory("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/OpenTelemetryServiceExtensionsCoverageTests.cs", 199)]
[InlineData(new object?[] { "HttpProtobuf", OtlpExportProtocol.HttpProtobuf })]
[InlineData(new object?[] { "httpprotobuf", OtlpExportProtocol.HttpProtobuf })]
[InlineData(new object?[] { "Grpc", OtlpExportProtocol.Grpc })]
[InlineData(new object?[] { "unknown", OtlpExportProtocol.Grpc })]
public void ConfigureOtlpExporter_ConfiguresEndpointAndProtocol(string protocol, OtlpExportProtocol expectedProtocol)

Parameters

protocol string

The protocol string to test, which will be parsed by the ConfigureOtlpExporter method to determine the OtlpExportProtocol to use. The test includes valid protocol strings in different cases (e.g., "HttpProtobuf" and "httpprotobuf") as well as an unknown value to verify that the default protocol is used when an unrecognized string is provided.

expectedProtocol OtlpExportProtocol

The expected OtlpExportProtocol enum value that should be set in the OtlpExporterOptions based on the provided protocol string. This parameter allows the test to verify that the ConfigureOtlpExporter method correctly maps the input protocol string to the corresponding OtlpExportProtocol value, ensuring that the exporter is configured with the intended protocol for OTLP export.

ResolveServiceVersion_ExplicitVersion_ReturnsTrimmedVersion()

Verifies that when an explicit service version is provided with leading and trailing whitespace, the resolved service version is trimmed of whitespace.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/OpenTelemetryServiceExtensionsCoverageTests.cs", 155)]
public void ResolveServiceVersion_ExplicitVersion_ReturnsTrimmedVersion()

ResolveServiceVersion_MissingVersion_ReturnsAssemblyFallback(string?)

Verifies that when the service version is missing (null, empty, or whitespace), the resolved service version falls back to the assembly version of the OpenTelemetryServiceExtensions class.

[Theory("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/OpenTelemetryServiceExtensionsCoverageTests.cs", 174)]
[InlineData(null)]
[InlineData(new object?[] { "" })]
[InlineData(new object?[] { " " })]
public void ResolveServiceVersion_MissingVersion_ReturnsAssemblyFallback(string? serviceVersion)

Parameters

serviceVersion string

Null, empty, or whitespace string representing the service version to test. The test will be run for each of these cases to ensure that the fallback logic is correctly applied when the service version is not provided.