diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs index aa8b803c..6a80e326 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs @@ -72,6 +72,37 @@ public static void LogDependency( LogDependency(logger, dependencyType, dependencyData, isSuccessful, measurement.StartTime, measurement.Elapsed, context); } + /// + /// Logs a dependency. + /// + /// The logger to track the telemetry. + /// The custom type of dependency. + /// The custom data of dependency. + /// The indication whether or not the operation was successful. + /// The measuring the latency to call the dependency. + /// The ID of the dependency to link as parent ID. + /// The context that provides more insights on the dependency that was measured. + /// + /// Thrown when the , , is null. + /// + /// Thrown when the is blank. + public static void LogDependency( + this ILogger logger, + string dependencyType, + object dependencyData, + bool isSuccessful, + DurationMeasurement measurement, + string dependencyId, + Dictionary context = null) + { + Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); + Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); + Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); + Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency"); + + LogDependency(logger, dependencyType, dependencyData, isSuccessful, measurement.StartTime, measurement.Elapsed, dependencyId, context); + } + /// /// Logs a dependency. /// @@ -139,12 +170,45 @@ public static void LogDependency( /// Logs a dependency. /// /// The logger to track the telemetry. - /// Custom type of dependency - /// Custom data of dependency - /// Indication whether or not the operation was successful - /// Point in time when the interaction with the dependency was started - /// Duration of the operation - /// Context that provides more insights on the dependency that was measured + /// The custom type of dependency. + /// The custom data of dependency. + /// The indication whether or not the operation was successful. + /// The name of the dependency. + /// The measuring the latency to call the dependency. + /// The ID of the dependency to link as parent ID. + /// The context that provides more insights on the dependency that was measured. + /// + /// Thrown when the , , is null. + /// + /// Thrown when the is blank. + public static void LogDependency( + this ILogger logger, + string dependencyType, + object dependencyData, + bool isSuccessful, + string dependencyName, + DurationMeasurement measurement, + string dependencyId, + Dictionary context = null) + { + Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); + Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); + Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); + Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency"); + + LogDependency(logger, dependencyType, dependencyData, isSuccessful, dependencyName, measurement.StartTime, measurement.Elapsed, dependencyId, context); + } + + /// + /// Logs a dependency. + /// + /// The logger to track the telemetry. + /// Custom type of dependency. + /// Custom data of dependency. + /// The indication whether or not the operation was successful. + /// The point in time when the interaction with the dependency was started. + /// The duration of the operation. + /// The context that provides more insights on the dependency that was measured. /// /// Thrown when the , is null. /// @@ -164,20 +228,54 @@ public static void LogDependency( Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the dependency operation"); - LogDependency(logger, dependencyType, dependencyData, targetName: null, isSuccessful: isSuccessful, startTime: startTime, duration: duration, context: context); + LogDependency(logger, dependencyType, dependencyData, targetName: null, isSuccessful, startTime, duration, context); } /// /// Logs a dependency. /// /// The logger to track the telemetry. - /// Custom type of dependency - /// Custom data of dependency - /// Indication whether or not the operation was successful - /// The name of the dependency - /// Point in time when the interaction with the dependency was started - /// Duration of the operation - /// Context that provides more insights on the dependency that was measured + /// The custom type of dependency. + /// The custom data of dependency. + /// The indication whether or not the operation was successful. + /// The point in time when the interaction with the dependency was started. + /// The duration of the operation. + /// The ID of the dependency to link as parent ID. + /// The context that provides more insights on the dependency that was measured. + /// + /// Thrown when the , is null. + /// + /// Thrown when the is blank. + /// Thrown when the is a negative time range. + public static void LogDependency( + this ILogger logger, + string dependencyType, + object dependencyData, + bool isSuccessful, + DateTimeOffset startTime, + TimeSpan duration, + string dependencyId, + Dictionary context = null) + { + Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); + Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); + Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); + Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the dependency operation"); + + LogDependency(logger, dependencyType, dependencyData, targetName: null, isSuccessful, startTime, duration, dependencyId, context); + } + + /// + /// Logs a dependency. + /// + /// The logger to track the telemetry. + /// The custom type of dependency. + /// The custom data of dependency. + /// The indication whether or not the operation was successful. + /// The name of the dependency. + /// The point in time when the interaction with the dependency was started. + /// The duration of the operation. + /// The context that provides more insights on the dependency that was measured. /// /// Thrown when the , is null. /// @@ -201,6 +299,42 @@ public static void LogDependency( LogDependency(logger, dependencyType, dependencyData, targetName: null, isSuccessful: isSuccessful, dependencyName, startTime: startTime, duration: duration, context: context); } + /// + /// Logs a dependency. + /// + /// The logger to track the telemetry. + /// The custom type of dependency. + /// The custom data of dependency. + /// The indication whether or not the operation was successful. + /// The name of the dependency. + /// The point in time when the interaction with the dependency was started. + /// The duration of the operation. + /// The ID of the dependency to link as parent ID. + /// The context that provides more insights on the dependency that was measured. + /// + /// Thrown when the , is null. + /// + /// Thrown when the is blank. + /// Thrown when the is a negative time range. + public static void LogDependency( + this ILogger logger, + string dependencyType, + object dependencyData, + bool isSuccessful, + string dependencyName, + DateTimeOffset startTime, + TimeSpan duration, + string dependencyId, + Dictionary context = null) + { + Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); + Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); + Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); + Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the dependency operation"); + + LogDependency(logger, dependencyType, dependencyData, targetName: null, isSuccessful, dependencyName, startTime, duration, dependencyId, context); + } + /// /// Logs a dependency. /// @@ -264,6 +398,39 @@ public static void LogDependency( LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, measurement.StartTime, measurement.Elapsed, context); } + /// + /// Logs a dependency. + /// + /// The logger to track the telemetry. + /// The custom type of dependency. + /// The custom data of dependency. + /// The name of the dependency target. + /// The indication whether or not the operation was successful. + /// The measuring the latency to call the dependency. + /// The ID of the dependency to link as parent ID. + /// The context that provides more insights on the dependency that was measured. + /// + /// Thrown when the , , is null. + /// + /// Thrown when the is blank. + public static void LogDependency( + this ILogger logger, + string dependencyType, + object dependencyData, + string targetName, + bool isSuccessful, + DurationMeasurement measurement, + string dependencyId, + Dictionary context = null) + { + Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); + Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); + Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); + Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency"); + + LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, measurement.StartTime, measurement.Elapsed, dependencyId, context); + } + /// /// Logs a dependency. /// @@ -335,13 +502,48 @@ public static void LogDependency( /// Logs a dependency. /// /// The logger to track the telemetry. - /// Custom type of dependency - /// Custom data of dependency - /// Name of dependency target - /// Indication whether or not the operation was successful - /// Point in time when the interaction with the dependency was started - /// Duration of the operation - /// Context that provides more insights on the dependency that was measured + /// The custom type of dependency. + /// The custom data of dependency. + /// The name of the dependency target. + /// The indication whether or not the operation was successful. + /// The name of the dependency. + /// The measuring the latency to call the dependency. + /// The ID of the dependency to link as parent ID. + /// The context that provides more insights on the dependency that was measured. + /// + /// Thrown when the , , is null. + /// + /// Thrown when the is blank. + public static void LogDependency( + this ILogger logger, + string dependencyType, + object dependencyData, + string targetName, + bool isSuccessful, + string dependencyName, + DurationMeasurement measurement, + string dependencyId, + Dictionary context = null) + { + Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); + Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); + Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); + Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency"); + + LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, dependencyName, measurement.StartTime, measurement.Elapsed, dependencyId, context); + } + + /// + /// Logs a dependency. + /// + /// The logger to track the telemetry. + /// The custom type of dependency. + /// The custom data of dependency. + /// The name of dependency target. + /// The indication whether or not the operation was successful. + /// The point in time when the interaction with the dependency was started. + /// The duration of the operation. + /// The context that provides more insights on the dependency that was measured. /// /// Thrown when the , is null. /// @@ -369,14 +571,89 @@ public static void LogDependency( /// Logs a dependency. /// /// The logger to track the telemetry. - /// Custom type of dependency - /// Custom data of dependency - /// Name of dependency target - /// Indication whether or not the operation was successful + /// The custom type of dependency. + /// The custom data of dependency. + /// The name of dependency target. + /// The indication whether or not the operation was successful. + /// The point in time when the interaction with the dependency was started. + /// The ID of the dependency to link as parent ID. + /// The duration of the operation. + /// The context that provides more insights on the dependency that was measured. + /// + /// Thrown when the , is null. + /// + /// Thrown when the is blank. + /// Thrown when the is a negative time range. + public static void LogDependency( + this ILogger logger, + string dependencyType, + object dependencyData, + string targetName, + bool isSuccessful, + DateTimeOffset startTime, + TimeSpan duration, + string dependencyId, + Dictionary context = null) + { + Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); + Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); + Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); + Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the dependency operation"); + + LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, targetName, startTime, duration, dependencyId, context); + } + + /// + /// Logs a dependency. + /// + /// The logger to track the telemetry. + /// The custom type of dependency. + /// The custom data of dependency. + /// The name of dependency target. + /// The indication whether or not the operation was successful. + /// The name of the dependency. + /// The point in time when the interaction with the dependency was started. + /// The duration of the operation. + /// The context that provides more insights on the dependency that was measured. + /// + /// Thrown when the , is null. + /// + /// Thrown when the is blank. + /// Thrown when the is a negative time range. + public static void LogDependency( + this ILogger logger, + string dependencyType, + object dependencyData, + string targetName, + bool isSuccessful, + string dependencyName, + DateTimeOffset startTime, + TimeSpan duration, + Dictionary context = null) + { + Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); + Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); + Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); + Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the dependency operation"); + + context = context ?? new Dictionary(); + + LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, dependencyName, startTime, duration, dependencyId: null, context); + } + + /// + /// Logs a dependency. + /// + /// The logger to track the telemetry. + /// The custom type of dependency. + /// The custom data of dependency. + /// The name of dependency target. + /// The indication whether or not the operation was successful. /// The name of the dependency - /// Point in time when the interaction with the dependency was started - /// Duration of the operation - /// Context that provides more insights on the dependency that was measured + /// The point in time when the interaction with the dependency was started. + /// The duration of the operation. + /// The ID of the dependency to link as parent ID. + /// The context that provides more insights on the dependency that was measured. /// /// Thrown when the , is null. /// @@ -391,6 +668,7 @@ public static void LogDependency( string dependencyName, DateTimeOffset startTime, TimeSpan duration, + string dependencyId, Dictionary context = null) { Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); @@ -407,6 +685,7 @@ public static void LogDependency( targetName: targetName, duration: duration, startTime: startTime, + dependencyId: dependencyId, resultCode: null, isSuccessful: isSuccessful, context: context)); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs index 8114abbf..e963508e 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs @@ -24,6 +24,7 @@ public async Task LogDependency_SinksToApplicationInsights_ResultsInDependencyTe // Arrange string dependencyType = "Arcus"; string dependencyData = BogusGenerator.Finance.Account(); + string dependencyId = Guid.NewGuid().ToString(); using (ILoggerFactory loggerFactory = CreateLoggerFactory()) { ILogger logger = loggerFactory.CreateLogger(); @@ -34,7 +35,7 @@ public async Task LogDependency_SinksToApplicationInsights_ResultsInDependencyTe Dictionary telemetryContext = CreateTestTelemetryContext(); // Act - logger.LogDependency(dependencyType, dependencyData, isSuccessful, startTime, duration, telemetryContext); + logger.LogDependency(dependencyType, dependencyData, isSuccessful, startTime, duration, dependencyId, telemetryContext); } // Assert @@ -44,19 +45,30 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async () => { EventsResults results = await client.Events.GetDependencyEventsAsync(ApplicationId, timespan: "PT30M"); Assert.NotEmpty(results.Value); - Assert.Contains(results.Value, result => result.Dependency.Type == dependencyType && result.Dependency.Data == dependencyData); + AssertX.Any(results.Value, result => + { + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Equal(dependencyData, result.Dependency.Data); + Assert.Equal(dependencyId, result.Dependency.Id); + }); }); } - AssertX.Any(GetLogEventsFromMemory(), logEvent => + AssertSerilogLogProperties(dependencyType, dependencyData); + } + + private void AssertSerilogLogProperties(string dependencyType, string dependencyData) + { + IEnumerable logEvents = GetLogEventsFromMemory(); + AssertX.Any(logEvents, logEvent => { StructureValue logEntry = logEvent.Properties.GetAsStructureValue(ContextProperties.DependencyTracking.DependencyLogEntry); Assert.NotNull(logEntry); - var actualDependencyType = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyType)); + LogEventProperty actualDependencyType = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyType)); Assert.Equal(dependencyType, actualDependencyType.Value.ToDecentString()); - var actualDependencyData = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyData)); + LogEventProperty actualDependencyData = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyData)); Assert.Equal(dependencyData, actualDependencyData.Value.ToDecentString()); Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.Context)); @@ -70,6 +82,7 @@ public async Task LogDependency_SinksToApplicationInsights_ResultsInDependencyTe string dependencyType = "Arcus"; string dependencyData = BogusGenerator.Finance.Account(); string dependencyName = BogusGenerator.Random.Word(); + string dependencyId = Guid.NewGuid().ToString(); using (ILoggerFactory loggerFactory = CreateLoggerFactory()) { ILogger logger = loggerFactory.CreateLogger(); @@ -80,7 +93,7 @@ public async Task LogDependency_SinksToApplicationInsights_ResultsInDependencyTe Dictionary telemetryContext = CreateTestTelemetryContext(); // Act - logger.LogDependency(dependencyType, dependencyData, isSuccessful, dependencyName, startTime, duration, telemetryContext); + logger.LogDependency(dependencyType, dependencyData, isSuccessful, dependencyName, startTime, duration, dependencyId, telemetryContext); } // Assert @@ -90,22 +103,34 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async () => { EventsResults results = await client.Events.GetDependencyEventsAsync(ApplicationId, timespan: "PT30M"); Assert.NotEmpty(results.Value); - Assert.Contains(results.Value, result => result.Dependency.Type == dependencyType && result.Dependency.Data == dependencyData && result.Dependency.Name == dependencyName); + AssertX.Any(results.Value, result => + { + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Equal(dependencyData, result.Dependency.Data); + Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); + }); }); } - AssertX.Any(GetLogEventsFromMemory(), logEvent => + AssertSerilogLogProperties(dependencyType, dependencyData, dependencyName); + } + + private void AssertSerilogLogProperties(string dependencyType, string dependencyData, string dependencyName) + { + IEnumerable logEvents = GetLogEventsFromMemory(); + AssertX.Any(logEvents, logEvent => { StructureValue logEntry = logEvent.Properties.GetAsStructureValue(ContextProperties.DependencyTracking.DependencyLogEntry); Assert.NotNull(logEntry); - var actualDependencyType = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyType)); + LogEventProperty actualDependencyType = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyType)); Assert.Equal(dependencyType, actualDependencyType.Value.ToDecentString()); - var actualDependencyData = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyData)); + LogEventProperty actualDependencyData = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyData)); Assert.Equal(dependencyData, actualDependencyData.Value.ToDecentString()); - var actualDependencyName = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyName)); + LogEventProperty actualDependencyName = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyName)); Assert.Equal(dependencyName, actualDependencyName.Value.ToDecentString()); Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.Context)); diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs index 88388676..3d977fc0 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs @@ -21,8 +21,8 @@ public void LogDependency_ValidArguments_Succeeds() { // Arrange var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Name.FullName(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); TimeSpan duration = _bogusGenerator.Date.Timespan(); @@ -40,15 +40,40 @@ public void LogDependency_ValidArguments_Succeeds() Assert.Contains(isSuccessful.ToString(), logMessage); } + [Fact] + public void LogDependency_ValidArgumentsWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = _bogusGenerator.Date.Timespan(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, isSuccessful, startTime, duration, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Fact] public void LogDependency_ValidArgumentsWithDependencyName_Succeeds() { // Arrange var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Name.FullName(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); TimeSpan duration = _bogusGenerator.Date.Timespan(); @@ -66,13 +91,40 @@ public void LogDependency_ValidArgumentsWithDependencyName_Succeeds() Assert.Contains(dependencyName, logMessage); } + [Fact] + public void LogDependency_ValidArgumentsWithDependencyNameWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyName = _bogusGenerator.Lorem.Word(); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = _bogusGenerator.Date.Timespan(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, isSuccessful, dependencyName, startTime, duration, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Equal(dependencyName, dependency.DependencyName); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Fact] public void LogDependency_WithoutDependencyType_Fails() { // Arrange var logger = new TestLogger(); string dependencyType = null; - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); TimeSpan duration = _bogusGenerator.Date.Timespan(); @@ -102,7 +154,7 @@ public void LogDependency_WithNegativeDuration_Fails() // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Name.FullName(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); TimeSpan duration = TimeSpanGenerator.GeneratePositiveDuration().Negate(); @@ -111,13 +163,61 @@ public void LogDependency_WithNegativeDuration_Fails() Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, startTime, duration)); } + [Fact] + public void LogDependency_WithoutDependencyTypeWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = null; + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = _bogusGenerator.Date.Timespan(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, startTime, duration, dependencyId)); + } + + [Fact] + public void LogDependency_WithoutDependencyDataWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Name.FullName(); + object dependencyData = null; + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = _bogusGenerator.Date.Timespan(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, startTime, duration, dependencyId)); + } + + [Fact] + public void LogDependency_WithNegativeDurationWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Name.FullName(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = TimeSpanGenerator.GeneratePositiveDuration().Negate(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, startTime, duration, dependencyId)); + } + [Fact] public void LogDependencyWithDependencyMeasurement_ValidArguments_Succeeds() { // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); var measurement = DependencyMeasurement.Start(); DateTimeOffset startTime = measurement.StartTime; @@ -137,13 +237,40 @@ public void LogDependencyWithDependencyMeasurement_ValidArguments_Succeeds() Assert.Contains(isSuccessful.ToString(), logMessage); } + [Fact] + public void LogDependencyWithDurationMeasurement_ValidArgumentsWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + var measurement = DurationMeasurement.Start(); + DateTimeOffset startTime = measurement.StartTime; + measurement.Dispose(); + TimeSpan duration = measurement.Elapsed; + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Fact] public void LogDependencyWithDependencyDurationMeasurement_ValidArguments_Succeeds() { // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); var measurement = DurationMeasurement.Start(); DateTimeOffset startTime = measurement.StartTime; @@ -163,15 +290,42 @@ public void LogDependencyWithDependencyDurationMeasurement_ValidArguments_Succee Assert.Contains(isSuccessful.ToString(), logMessage); } + [Fact] + public void LogDependencyWithDependencyDurationMeasurement_ValidArgumentsWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + var measurement = DurationMeasurement.Start(); + DateTimeOffset startTime = measurement.StartTime; + measurement.Dispose(); + TimeSpan duration = measurement.Elapsed; + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Fact] public void LogDependencyWithDependencyMeasurement_ValidArgumentsWithDependencyName_Succeeds() { // Arrange var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); var measurement = DependencyMeasurement.Start(); DateTimeOffset startTime = measurement.StartTime; measurement.Dispose(); @@ -191,15 +345,43 @@ public void LogDependencyWithDependencyMeasurement_ValidArgumentsWithDependencyN Assert.Contains(dependencyName, logMessage); } + [Fact] + public void LogDependencyWithDurationMeasurement_ValidArgumentsWithDependencyNameWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + DateTimeOffset startTime = measurement.StartTime; + measurement.Dispose(); + TimeSpan duration = measurement.Elapsed; + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, isSuccessful, dependencyName, measurement, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Fact] public void LogDependencyWithDurationMeasurement_ValidArgumentsWithDependencyName_Succeeds() { // Arrange var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); var measurement = DurationMeasurement.Start(); DateTimeOffset startTime = measurement.StartTime; measurement.Dispose(); @@ -225,9 +407,9 @@ public void LogDependencyWithDurationMeasurement_WithoutDependencyType_Fails(str { // Arrange var logger = new TestLogger(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); var measurement = DurationMeasurement.Start(); measurement.Dispose(); @@ -243,7 +425,7 @@ public void LogDependencyWithDurationMeasurement_WithoutDependencyData_Fails() var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); var measurement = DurationMeasurement.Start(); measurement.Dispose(); @@ -257,10 +439,10 @@ public void LogDependencyWithDurationMeasurement_WithoutMeasurement_Fails() { // Arrange var logger = new TestLogger(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string dependencyType = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); var measurement = DurationMeasurement.Start(); measurement.Dispose(); @@ -269,12 +451,65 @@ public void LogDependencyWithDurationMeasurement_WithoutMeasurement_Fails() () => logger.LogDependency(dependencyType, dependencyData, isSuccessful, dependencyName, measurement: (DurationMeasurement)null)); } + [Theory] + [ClassData(typeof(Blanks))] + public void LogDependencyWithDurationMeasurement_WithoutDependencyTypeWithDependencyId_Fails(string dependencyType) + { + // Arrange + var logger = new TestLogger(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny( + () => logger.LogDependency(dependencyType, dependencyData, isSuccessful, dependencyName, measurement, dependencyId)); + } + [Fact] - public void LogDependencyWithDurationMeasurement_ValidArgumentsWithTargetName_Succeeds() + public void LogDependencyWithDurationMeasurement_WithoutDependencyDataWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny( + () => logger.LogDependency(dependencyType, dependencyData: null, isSuccessful, dependencyName, measurement, dependencyId)); + } + + [Fact] + public void LogDependencyWithDurationMeasurement_WithoutMeasurementWithDependencyId_Fails() { // Arrange var logger = new TestLogger(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string dependencyType = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny( + () => logger.LogDependency(dependencyType, dependencyData, isSuccessful, dependencyName, measurement: null, dependencyId)); + } + + [Fact] + public void LogDependencyWithDurationMeasurement_ValidArgumentsWithTargetName_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Database.Type(); var dependencyData = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); string targetName = _bogusGenerator.Lorem.Word(); @@ -296,15 +531,44 @@ public void LogDependencyWithDurationMeasurement_ValidArgumentsWithTargetName_Su Assert.Equal(targetName, dependency.TargetName); } + [Fact] + public void LogDependencyWithDurationMeasurement_ValidArgumentsWithTargetNameWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string targetName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + DateTimeOffset startTime = measurement.StartTime; + measurement.Dispose(); + TimeSpan duration = measurement.Elapsed; + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Equal(targetName, dependency.TargetName); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Theory] [ClassData(typeof(Blanks))] public void LogDependencyWithDurationMeasurementWithTargetName_WithoutDependencyType_Fails(string dependencyType) { // Arrange var logger = new TestLogger(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string targetName = _bogusGenerator.Random.Word(); + string targetName = _bogusGenerator.Lorem.Word(); var measurement = DurationMeasurement.Start(); measurement.Dispose(); @@ -320,7 +584,7 @@ public void LogDependencyWithDurationMeasurementWithTargetName_WithoutDependency var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string targetName = _bogusGenerator.Random.Word(); + string targetName = _bogusGenerator.Lorem.Word(); var measurement = DurationMeasurement.Start(); measurement.Dispose(); @@ -335,9 +599,9 @@ public void LogDependencyWithDurationMeasurementWithTargetName_WithoutMeasuremen // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string targetName = _bogusGenerator.Random.Word(); + string targetName = _bogusGenerator.Lorem.Word(); var measurement = DurationMeasurement.Start(); measurement.Dispose(); @@ -346,13 +610,66 @@ public void LogDependencyWithDurationMeasurementWithTargetName_WithoutMeasuremen () => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement: (DurationMeasurement)null)); } + [Theory] + [ClassData(typeof(Blanks))] + public void LogDependencyWithDurationMeasurementWithTargetName_WithoutDependencyTypeWithDependencyId_Fails(string dependencyType) + { + // Arrange + var logger = new TestLogger(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string targetName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny( + () => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement, dependencyId)); + } + + [Fact] + public void LogDependencyWithDurationMeasurementWithTargetName_WithoutDependencyDataWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string targetName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny( + () => logger.LogDependency(dependencyType, dependencyData: null, targetName, isSuccessful, measurement, dependencyId)); + } + + [Fact] + public void LogDependencyWithDurationMeasurementWithTargetName_WithoutMeasurementWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string targetName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny( + () => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement: null, dependencyId)); + } + [Fact] public void LogDependencyWithDependencyMeasurement_WithoutDependencyMeasurement_Fails() { // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); // Act / Assert @@ -365,22 +682,51 @@ public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyMeas // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement: (DurationMeasurement)null)); + } + + [Fact] + public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyMeasurementWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement: null, dependencyId)); + } + + [Fact] + public void LogDependencyWithDependencyMeasurement_WithoutDependencyType_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = null; + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); + var measurement = DependencyMeasurement.Start(); + measurement.Dispose(); // Act / Assert - Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement: (DurationMeasurement)null)); + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement)); } [Fact] - public void LogDependencyWithDependencyMeasurement_WithoutDependencyType_Fails() + public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyType_Fails() { // Arrange var logger = new TestLogger(); string dependencyType = null; - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - var measurement = DependencyMeasurement.Start(); + var measurement = DurationMeasurement.Start(); measurement.Dispose(); // Act / Assert @@ -388,18 +734,19 @@ public void LogDependencyWithDependencyMeasurement_WithoutDependencyType_Fails() } [Fact] - public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyType_Fails() + public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyTypeWithDependencyId_Fails() { // Arrange var logger = new TestLogger(); string dependencyType = null; - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); var measurement = DurationMeasurement.Start(); measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); // Act / Assert - Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement)); + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement, dependencyId)); } [Fact] @@ -433,12 +780,28 @@ public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyData } [Fact] - public void LogDependencyTarget_ValidArguments_Succeeds() + public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyDataWithDependencyId_Fails() { // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Name.FullName(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + object dependencyData = null; + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + var measurement = DurationMeasurement.Start(); + measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement, dependencyId)); + } + + [Fact] + public void LogDependencyTarget_ValidArguments_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); @@ -457,16 +820,42 @@ public void LogDependencyTarget_ValidArguments_Succeeds() Assert.Contains(isSuccessful.ToString(), logMessage); } + [Fact] + public void LogDependencyTarget_ValidArgumentsWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = _bogusGenerator.Date.Timespan(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, startTime, duration, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Fact] public void LogDependencyTarget_ValidArgumentsWithDependencyName_Succeeds() { // Arrange var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Name.FullName(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); TimeSpan duration = _bogusGenerator.Date.Timespan(); @@ -484,13 +873,42 @@ public void LogDependencyTarget_ValidArgumentsWithDependencyName_Succeeds() Assert.Contains(dependencyName, logMessage); } + [Fact] + public void LogDependencyTarget_ValidArgumentsWithDependencyNameWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Database.Type(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyName = _bogusGenerator.Lorem.Word(); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = _bogusGenerator.Date.Timespan(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, dependencyName, startTime, duration, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(dependencyName, dependency.DependencyName); + Assert.Equal(targetName, dependency.TargetName); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Fact] public void LogDependencyTarget_WithoutDependencyType_Fails() { // Arrange var logger = new TestLogger(); string dependencyType = null; - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); @@ -522,7 +940,7 @@ public void LogDependencyTarget_WithoutTarget_Fails() // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Name.FullName(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = null; bool isSuccessful = _bogusGenerator.PickRandom(true, false); DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); @@ -538,7 +956,7 @@ public void LogDependencyTarget_WithNegativeDuration_Fails() // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Name.FullName(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); @@ -548,13 +966,81 @@ public void LogDependencyTarget_WithNegativeDuration_Fails() Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, startTime, duration)); } + [Fact] + public void LogDependencyTarget_WithoutDependencyTypeWithDependency_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = null; + var dependencyData = _bogusGenerator.Random.Int().ToString(); + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = _bogusGenerator.Date.Timespan(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, startTime, duration, dependencyId)); + } + + [Fact] + public void LogDependencyTarget_WithoutDependencyDataWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Name.FullName(); + object dependencyData = null; + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = _bogusGenerator.Date.Timespan(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, startTime, duration)); + } + + [Fact] + public void LogDependencyTarget_WithoutTargetWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Name.FullName(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + string targetName = null; + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = TimeSpanGenerator.GeneratePositiveDuration().Negate(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, startTime, duration, dependencyId)); + } + + [Fact] + public void LogDependencyTarget_WithNegativeDurationWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Name.FullName(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); + TimeSpan duration = TimeSpanGenerator.GeneratePositiveDuration().Negate(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, startTime, duration, dependencyId)); + } + [Fact] public void LogDependencyWithDependencyMeasurementTarget_ValidArguments_Succeeds() { // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); var measurement = DependencyMeasurement.Start(); @@ -581,10 +1067,10 @@ public void LogDependencyWithDependencyMeasurementTarget_ValidArgumentsWithDepen // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); var measurement = DependencyMeasurement.Start(); DateTimeOffset startTime = measurement.StartTime; measurement.Dispose(); @@ -610,10 +1096,10 @@ public void LogDependencyWithDurationMeasurementTarget_ValidArgumentsWithDepende // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); var measurement = DurationMeasurement.Start(); DateTimeOffset startTime = measurement.StartTime; measurement.Dispose(); @@ -633,15 +1119,46 @@ public void LogDependencyWithDurationMeasurementTarget_ValidArgumentsWithDepende Assert.Contains(dependencyName, logMessage); } + [Fact] + public void LogDependencyWithDurationMeasurementTarget_ValidArgumentsWithDependencyNameWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + DateTimeOffset startTime = measurement.StartTime; + measurement.Dispose(); + TimeSpan duration = measurement.Elapsed; + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, dependencyName, measurement, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(dependencyName, dependency.DependencyName); + Assert.Equal(targetName, dependency.TargetName); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Fact] public void LogDependencyWithDurationMeasurementTarget_WithoutDependencyType_Fails() { // Arrange var logger = new TestLogger(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); var measurement = DurationMeasurement.Start(); measurement.Dispose(); @@ -651,20 +1168,21 @@ public void LogDependencyWithDurationMeasurementTarget_WithoutDependencyType_Fai } [Fact] - public void LogDependencyWithDurationMeasurementTarget_WithoutDependencyData_Fails() + public void LogDependencyWithDurationMeasurementTarget_WithoutDependencyTypeWithDependencyId_Fails() { // Arrange var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Lorem.Word(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); var measurement = DurationMeasurement.Start(); measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); // Act / Assert Assert.ThrowsAny( - () => logger.LogDependency(dependencyType, dependencyData: null, targetName, isSuccessful, dependencyName, measurement)); + () => logger.LogDependency(dependencyType: null, dependencyData, targetName, isSuccessful, dependencyName, measurement, dependencyId)); } [Fact] @@ -695,6 +1213,36 @@ public void LogDependencyWithDurationMeasurementTarget_WithoutTargetName_Succeed Assert.Null(dependency.TargetName); } + [Fact] + public void LogDependencyWithDurationMeasurementTarget_WithoutTargetNameWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + var dependencyData = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + DateTimeOffset startTime = measurement.StartTime; + measurement.Dispose(); + TimeSpan duration = measurement.Elapsed; + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, targetName: null, isSuccessful, dependencyName, measurement, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Equal(dependencyName, dependency.DependencyName); + Assert.Null(dependency.TargetName); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Fact] public void LogDependencyWithDurationMeasurementTarget_WithoutDependencyName_Succeeds() { @@ -723,29 +1271,76 @@ public void LogDependencyWithDurationMeasurementTarget_WithoutDependencyName_Suc Assert.Equal(targetName, dependency.TargetName); } + [Fact] + public void LogDependencyWithDurationMeasurementTarget_WithoutDependencyNameWithDependencyId_Succeeds() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + var dependencyData = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string targetName = _bogusGenerator.Lorem.Word(); + var measurement = DurationMeasurement.Start(); + DateTimeOffset startTime = measurement.StartTime; + measurement.Dispose(); + TimeSpan duration = measurement.Elapsed; + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act + logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, dependencyName: null, measurement, dependencyId); + + // Assert + DependencyLogEntry dependency = logger.GetMessageAsDependency(); + Assert.Equal(dependencyType, dependency.DependencyType); + Assert.Equal(dependencyData, dependency.DependencyData); + Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime); + Assert.Equal(duration, dependency.Duration); + Assert.Equal(isSuccessful, dependency.IsSuccessful); + Assert.Null(dependency.DependencyName); + Assert.Equal(targetName, dependency.TargetName); + Assert.Equal(dependencyId, dependency.DependencyId); + } + [Fact] public void LogDependencyWithDurationMeasurementTarget_WithoutMeasurement_Fails() { // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); + string dependencyName = _bogusGenerator.Lorem.Word(); // Act / Assert Assert.ThrowsAny( () => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, dependencyName, measurement: (DurationMeasurement)null)); } + [Fact] + public void LogDependencyWithDurationMeasurementTarget_WithoutMeasurementWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyName = _bogusGenerator.Lorem.Word(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny( + () => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, dependencyName, measurement: null, dependencyId)); + } + [Fact] public void LogDependencyTargetWithDependencyMeasurement_WithoutDependencyType_Fails() { // Arrange var logger = new TestLogger(); string dependencyType = null; - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); var measurement = DependencyMeasurement.Start(); @@ -761,7 +1356,7 @@ public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependen // Arrange var logger = new TestLogger(); string dependencyType = null; - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); var measurement = DurationMeasurement.Start(); @@ -771,6 +1366,23 @@ public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependen Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement)); } + [Fact] + public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependencyTypeWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = null; + var dependencyData = _bogusGenerator.Random.Int().ToString(); + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + var measurement = DurationMeasurement.Start(); + measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement, dependencyId)); + } + [Fact] public void LogDependencyTargetWithDependencyMeasurement_WithoutDependencyData_Fails() { @@ -803,13 +1415,30 @@ public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependen Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement)); } + [Fact] + public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependencyDataWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Name.FullName(); + object dependencyData = null; + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + var measurement = DurationMeasurement.Start(); + measurement.Dispose(); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement, dependencyId)); + } + [Fact] public void LogDependencyTargetWithDependencyMeasurement_WithoutDependencyMeasurement_Fails() { // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); @@ -823,12 +1452,27 @@ public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependen // Arrange var logger = new TestLogger(); string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); + var dependencyData = _bogusGenerator.Random.Int().ToString(); string targetName = _bogusGenerator.Lorem.Word(); bool isSuccessful = _bogusGenerator.PickRandom(true, false); // Act / Assert Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement: (DurationMeasurement)null)); } + + [Fact] + public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependencyMeasurementWithDependencyId_Fails() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyId = _bogusGenerator.Lorem.Word(); + + // Act / Assert + Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement: null, dependencyId)); + } } }