From dc4081868ce2e644000c044af74f9c200678f9a5 Mon Sep 17 00:00:00 2001 From: Madalyn Redding Date: Fri, 15 Aug 2025 14:26:34 -0700 Subject: [PATCH] move to nunit 4 patterns --- .../Assistants.VectorStoresTests.cs | 22 ++++++------- tests/Assistants/AssistantsSmokeTests.cs | 2 +- tests/Assistants/AssistantsTests.cs | 8 ++--- tests/Audio/TranscriptionTests.cs | 1 - tests/Batch/BatchTests.cs | 8 ++--- tests/Chat/ChatStoreTests.cs | 2 +- tests/Chat/ChatTests.cs | 10 +++--- tests/FineTuning/FineTuningClientTests.cs | 22 ++++++------- .../FineTuning/HyperparameterOptionsTests.cs | 24 +++++++------- tests/Telemetry/ChatTelemetryTests.cs | 32 +++++++++---------- tests/Telemetry/TestActivityListener.cs | 28 ++++++++-------- tests/Telemetry/TestMeterListener.cs | 14 ++++---- 12 files changed, 86 insertions(+), 87 deletions(-) diff --git a/tests/Assistants/Assistants.VectorStoresTests.cs b/tests/Assistants/Assistants.VectorStoresTests.cs index 4011e7854..d92fd193e 100644 --- a/tests/Assistants/Assistants.VectorStoresTests.cs +++ b/tests/Assistants/Assistants.VectorStoresTests.cs @@ -328,14 +328,14 @@ public async Task Pagination_CanRehydrateFileAssociationCollectionAsync() List itemsInPage = GetFileAssociationsFromPage(page).ToList(); List itemsInRehydratedPage = GetFileAssociationsFromPage(rehydratedPage).ToList(); - Assert.AreEqual(itemsInPage.Count, itemsInRehydratedPage.Count); + Assert.That(itemsInRehydratedPage.Count, Is.EqualTo(itemsInPage.Count)); for (int i = 0; i < itemsInPage.Count; i++) { - Assert.AreEqual(itemsInPage[0].FileId, itemsInRehydratedPage[0].FileId); - Assert.AreEqual(itemsInPage[0].VectorStoreId, itemsInRehydratedPage[0].VectorStoreId); - Assert.AreEqual(itemsInPage[0].CreatedAt, itemsInRehydratedPage[0].CreatedAt); - Assert.AreEqual(itemsInPage[0].Size, itemsInRehydratedPage[0].Size); + Assert.That(itemsInRehydratedPage[0].FileId, Is.EqualTo(itemsInPage[0].FileId)); + Assert.That(itemsInRehydratedPage[0].VectorStoreId, Is.EqualTo(itemsInPage[0].VectorStoreId)); + Assert.That(itemsInRehydratedPage[0].CreatedAt, Is.EqualTo(itemsInPage[0].CreatedAt)); + Assert.That(itemsInRehydratedPage[0].Size, Is.EqualTo(itemsInPage[0].Size)); } pageCount++; @@ -406,14 +406,14 @@ public void Pagination_CanRehydrateFileAssociationCollection() List itemsInPage = GetFileAssociationsFromPage(page).ToList(); List itemsInRehydratedPage = GetFileAssociationsFromPage(rehydratedPage).ToList(); - Assert.AreEqual(itemsInPage.Count, itemsInRehydratedPage.Count); + Assert.That(itemsInRehydratedPage.Count, Is.EqualTo(itemsInPage.Count)); for (int i = 0; i < itemsInPage.Count; i++) { - Assert.AreEqual(itemsInPage[0].FileId, itemsInRehydratedPage[0].FileId); - Assert.AreEqual(itemsInPage[0].VectorStoreId, itemsInRehydratedPage[0].VectorStoreId); - Assert.AreEqual(itemsInPage[0].CreatedAt, itemsInRehydratedPage[0].CreatedAt); - Assert.AreEqual(itemsInPage[0].Size, itemsInRehydratedPage[0].Size); + Assert.That(itemsInRehydratedPage[0].FileId, Is.EqualTo(itemsInPage[0].FileId)); + Assert.That(itemsInRehydratedPage[0].VectorStoreId, Is.EqualTo(itemsInPage[0].VectorStoreId)); + Assert.That(itemsInRehydratedPage[0].CreatedAt, Is.EqualTo(itemsInPage[0].CreatedAt)); + Assert.That(itemsInRehydratedPage[0].Size, Is.EqualTo(itemsInPage[0].Size)); } pageCount++; @@ -523,7 +523,7 @@ public void CanRehydrateBatchFileJob() Assert.IsTrue(batchOperation.HasCompleted); Assert.IsTrue(rehydratedOperation.HasCompleted); - Assert.AreEqual(batchOperation.Status, rehydratedOperation.Status); + Assert.That(rehydratedOperation.Status, Is.EqualTo(batchOperation.Status)); } public enum ChunkingStrategyKind { Auto, Static } diff --git a/tests/Assistants/AssistantsSmokeTests.cs b/tests/Assistants/AssistantsSmokeTests.cs index c6afdf970..19d684d53 100644 --- a/tests/Assistants/AssistantsSmokeTests.cs +++ b/tests/Assistants/AssistantsSmokeTests.cs @@ -79,7 +79,7 @@ public void ResponseFormatEquality() Assert.That((AssistantResponseFormat)null != AssistantResponseFormat.CreateTextFormat()); Assert.That(AssistantResponseFormat.CreateTextFormat() != null); Assert.That(AssistantResponseFormat.CreateTextFormat(), Is.Not.EqualTo(null)); - Assert.That(null, Is.Not.EqualTo(AssistantResponseFormat.CreateTextFormat())); + Assert.That(AssistantResponseFormat.CreateTextFormat(), Is.Not.Null); AssistantResponseFormat jsonSchemaFormat = AssistantResponseFormat.CreateJsonSchemaFormat( name: "test_schema", diff --git a/tests/Assistants/AssistantsTests.cs b/tests/Assistants/AssistantsTests.cs index 02cccae22..daabcce8f 100644 --- a/tests/Assistants/AssistantsTests.cs +++ b/tests/Assistants/AssistantsTests.cs @@ -1760,7 +1760,7 @@ public async Task Pagination_CanCastAssistantPageCollectionToConvenienceFromProt // functions correctly as the convenience return type. await foreach (Assistant assistant in assistants) { - Assert.AreEqual(createdAssistants[count++].Id, assistant.Id); + Assert.That(assistant.Id, Is.EqualTo(createdAssistants[count++].Id)); if (count >= createdAssistants.Count) { @@ -1810,7 +1810,7 @@ public void Pagination_CanCastAssistantPageCollectionToConvenienceFromProtocol() // functions correctly as the convenience return type. foreach (Assistant assistant in assistants) { - Assert.AreEqual(createdAssistants[count++].Id, assistant.Id); + Assert.That(assistant.Id, Is.EqualTo(createdAssistants[count++].Id)); if (count >= createdAssistants.Count) { @@ -1893,7 +1893,7 @@ public async Task Pagination_CanRehydrateRunStepPageCollectionFromBytesAsync() .ToListAsync(); } - CollectionAssert.AreEqual(runSteps, rehydratedRunSteps); + Assert.That(rehydratedRunSteps, Is.EqualTo(runSteps).AsCollection); } [Test] @@ -1967,7 +1967,7 @@ public void Pagination_CanRehydrateRunStepPageCollectionFromBytes() .ToList(); } - CollectionAssert.AreEqual(runSteps, rehydratedRunSteps); + Assert.That(rehydratedRunSteps, Is.EqualTo(runSteps).AsCollection); } [Test] diff --git a/tests/Audio/TranscriptionTests.cs b/tests/Audio/TranscriptionTests.cs index 65f8b0988..c9a5af4e8 100644 --- a/tests/Audio/TranscriptionTests.cs +++ b/tests/Audio/TranscriptionTests.cs @@ -180,7 +180,6 @@ public async Task TranscriptionFormatsWork(string responseFormat) Assert.That(segment.Id, Is.EqualTo(i)); Assert.That(segment.EndTime, Is.GreaterThanOrEqualTo(segment.StartTime)); - Assert.That(segment.TokenIds, Is.Not.Null); Assert.That(segment.TokenIds.Length, Is.GreaterThan(0)); Assert.That(segment.AverageLogProbability, Is.LessThan(-0.001f).Or.GreaterThan(0.001f)); diff --git a/tests/Batch/BatchTests.cs b/tests/Batch/BatchTests.cs index ea31f05f9..0eecbdc02 100644 --- a/tests/Batch/BatchTests.cs +++ b/tests/Batch/BatchTests.cs @@ -233,13 +233,13 @@ static bool Validate(CreateBatchOperation operation) // We don't test wait for completion live because this is documented to // sometimes take 24 hours. - Assert.AreEqual(batchOperation.HasCompleted, rehydratedOperation.HasCompleted); + Assert.That(rehydratedOperation.HasCompleted, Is.EqualTo(batchOperation.HasCompleted)); using JsonDocument originalOperationJson = JsonDocument.Parse(batchOperation.GetRawResponse().Content); using JsonDocument rehydratedOperationJson = JsonDocument.Parse(rehydratedOperation.GetRawResponse().Content); - Assert.AreEqual(originalOperationJson.RootElement.GetProperty("id").GetString(), rehydratedOperationJson.RootElement.GetProperty("id").GetString()); - Assert.AreEqual(originalOperationJson.RootElement.GetProperty("created_at").GetInt64(), rehydratedOperationJson.RootElement.GetProperty("created_at").GetInt64()); - Assert.AreEqual(originalOperationJson.RootElement.GetProperty("status").GetString(), rehydratedOperationJson.RootElement.GetProperty("status").GetString()); + Assert.That(rehydratedOperationJson.RootElement.GetProperty("id").GetString(), Is.EqualTo(originalOperationJson.RootElement.GetProperty("id").GetString())); + Assert.That(rehydratedOperationJson.RootElement.GetProperty("created_at").GetInt64(), Is.EqualTo(originalOperationJson.RootElement.GetProperty("created_at").GetInt64())); + Assert.That(rehydratedOperationJson.RootElement.GetProperty("status").GetString(), Is.EqualTo(originalOperationJson.RootElement.GetProperty("status").GetString())); } } \ No newline at end of file diff --git a/tests/Chat/ChatStoreTests.cs b/tests/Chat/ChatStoreTests.cs index a57df2aa9..b122037bd 100644 --- a/tests/Chat/ChatStoreTests.cs +++ b/tests/Chat/ChatStoreTests.cs @@ -672,7 +672,7 @@ await RetryWithExponentialBackoffAsync(async () => { messageCount++; Assert.That(message.Id, Is.Not.Null.And.Not.Empty); - Assert.AreEqual("Basic messages test: Say 'Hello, this is a test message.'", message.Content); + Assert.That(message.Content, Is.EqualTo("Basic messages test: Say 'Hello, this is a test message.'")); if (messageCount >= 5) break; // Prevent infinite loop } diff --git a/tests/Chat/ChatTests.cs b/tests/Chat/ChatTests.cs index 8ee9a616a..3186de27a 100644 --- a/tests/Chat/ChatTests.cs +++ b/tests/Chat/ChatTests.cs @@ -903,15 +903,15 @@ public async Task HelloWorldChatWithTracingAndMetrics() ? await client.CompleteChatAsync(messages) : client.CompleteChat(messages); - Assert.AreEqual(1, activityListener.Activities.Count); + Assert.That(activityListener.Activities.Count, Is.EqualTo(1)); TestActivityListener.ValidateChatActivity(activityListener.Activities.Single(), result.Value); List durations = meterListener.GetMeasurements("gen_ai.client.operation.duration"); - Assert.AreEqual(1, durations.Count); + Assert.That(durations.Count, Is.EqualTo(1)); ValidateChatMetricTags(durations.Single(), result.Value); List usages = meterListener.GetMeasurements("gen_ai.client.token.usage"); - Assert.AreEqual(2, usages.Count); + Assert.That(usages.Count, Is.EqualTo(2)); Assert.True(usages[0].tags.TryGetValue("gen_ai.token.type", out var type)); Assert.IsInstanceOf(type); @@ -919,8 +919,8 @@ public async Task HelloWorldChatWithTracingAndMetrics() TestMeasurement input = (type is "input") ? usages[0] : usages[1]; TestMeasurement output = (type is "input") ? usages[1] : usages[0]; - Assert.AreEqual(result.Value.Usage.InputTokenCount, input.value); - Assert.AreEqual(result.Value.Usage.OutputTokenCount, output.value); + Assert.That(input.value, Is.EqualTo(result.Value.Usage.InputTokenCount)); + Assert.That(output.value, Is.EqualTo(result.Value.Usage.OutputTokenCount)); } [Test] diff --git a/tests/FineTuning/FineTuningClientTests.cs b/tests/FineTuning/FineTuningClientTests.cs index e5fe5e293..c67598673 100644 --- a/tests/FineTuning/FineTuningClientTests.cs +++ b/tests/FineTuning/FineTuningClientTests.cs @@ -78,7 +78,7 @@ public async Task MinimalRequiredParams([Values(Method.Sync, Method.Async)] Meth ? await ft.CancelAndUpdateAsync() : ft.CancelAndUpdate(); - Assert.AreEqual(FineTuningStatus.Cancelled, ft.Status); + Assert.That(ft.Status, Is.EqualTo(FineTuningStatus.Cancelled)); Assert.False(ft.Status.InProgress); Assert.True(ft.HasCompleted); } @@ -110,25 +110,25 @@ public async Task AllParameters([Values(Method.Sync, Method.Async)] Method metho ft.CancelAndUpdate(); #pragma warning disable CS0618 - Assert.AreEqual(1, ft.Hyperparameters.EpochCount); - Assert.AreEqual(2, ft.Hyperparameters.BatchSize); - Assert.AreEqual(3, ft.Hyperparameters.LearningRateMultiplier); + Assert.That(ft.Hyperparameters.EpochCount, Is.EqualTo(1)); + Assert.That(ft.Hyperparameters.BatchSize, Is.EqualTo(2)); + Assert.That(ft.Hyperparameters.LearningRateMultiplier, Is.EqualTo(3)); #pragma warning restore if (ft.MethodHyperparameters is HyperparametersForSupervised hp) { - Assert.AreEqual(1, hp.EpochCount); - Assert.AreEqual(2, hp.BatchSize); - Assert.AreEqual(3, hp.LearningRateMultiplier); + Assert.That(hp.EpochCount, Is.EqualTo(1)); + Assert.That(hp.BatchSize, Is.EqualTo(2)); + Assert.That(hp.LearningRateMultiplier, Is.EqualTo(3)); } else { Assert.Fail($"Expected HyperparametersForSupervised, got {ft.MethodHyperparameters?.GetType().ToString() ?? "null"}"); } - Assert.AreEqual(ft.UserProvidedSuffix, "TestFTJob"); - Assert.AreEqual(1234567, ft.Seed); - Assert.AreEqual(validationFile.Id, ft.ValidationFileId); + Assert.That(ft.UserProvidedSuffix, Is.EqualTo("TestFTJob")); + Assert.That(ft.Seed, Is.EqualTo(1234567)); + Assert.That(ft.ValidationFileId, Is.EqualTo(validationFile.Id)); } [Test] @@ -233,7 +233,7 @@ public void GetJobsWithAfter() } var secondJob = client.GetJobs(new() { AfterJobId = firstJob.JobId }).First(); - Assert.AreNotEqual(firstJob.JobId, secondJob.JobId); + Assert.That(secondJob.JobId, Is.Not.EqualTo(firstJob.JobId)); // Can't assert that one was created after the next because they might be created at the same second. // Assert.Greater(secondJob.CreatedAt, firstJob.CreatedAt, $"{firstJob}, {secondJob}"); } diff --git a/tests/FineTuning/HyperparameterOptionsTests.cs b/tests/FineTuning/HyperparameterOptionsTests.cs index 111860470..cdd269b81 100644 --- a/tests/FineTuning/HyperparameterOptionsTests.cs +++ b/tests/FineTuning/HyperparameterOptionsTests.cs @@ -13,20 +13,20 @@ class HyperparameterOptionsTests [Parallelizable] public void OptionsCanEasilyCompare() { - Assert.AreEqual(HyperparameterEpochCount.CreateAuto(), "auto"); - Assert.AreEqual(HyperparameterBatchSize.CreateAuto(), "auto"); - Assert.AreEqual(HyperparameterLearningRate.CreateAuto(), "auto"); - Assert.AreEqual(HyperparameterBetaFactor.CreateAuto(), "auto"); + Assert.That(HyperparameterEpochCount.CreateAuto(), Is.EqualTo("auto")); + Assert.That(HyperparameterBatchSize.CreateAuto(), Is.EqualTo("auto")); + Assert.That(HyperparameterLearningRate.CreateAuto(), Is.EqualTo("auto")); + Assert.That(HyperparameterBetaFactor.CreateAuto(), Is.EqualTo("auto")); - Assert.AreEqual(new HyperparameterEpochCount(1), 1); - Assert.AreEqual(new HyperparameterBatchSize(1), 1); - Assert.AreEqual(new HyperparameterLearningRate(1), 1); - Assert.AreEqual(new HyperparameterBetaFactor(1), 1); + Assert.That(new HyperparameterEpochCount(1), Is.EqualTo(1)); + Assert.That(new HyperparameterBatchSize(1), Is.EqualTo(1)); + Assert.That(new HyperparameterLearningRate(1), Is.EqualTo(1)); + Assert.That(new HyperparameterBetaFactor(1), Is.EqualTo(1)); - Assert.AreEqual(1, new HyperparameterEpochCount(1)); - Assert.AreEqual(1, new HyperparameterBatchSize(1)); - Assert.AreEqual(1.0, new HyperparameterLearningRate(1)); - Assert.AreEqual(1, new HyperparameterBetaFactor(1)); + Assert.That(new HyperparameterEpochCount(1), Is.EqualTo(1)); + Assert.That(new HyperparameterBatchSize(1), Is.EqualTo(1)); + Assert.That(new HyperparameterLearningRate(1), Is.EqualTo(1.0)); + Assert.That(new HyperparameterBetaFactor(1), Is.EqualTo(1)); Assert.That(1 == new HyperparameterEpochCount(1)); Assert.That(1 == new HyperparameterBatchSize(1)); diff --git a/tests/Telemetry/ChatTelemetryTests.cs b/tests/Telemetry/ChatTelemetryTests.cs index f54ed41db..79bb981cc 100644 --- a/tests/Telemetry/ChatTelemetryTests.cs +++ b/tests/Telemetry/ChatTelemetryTests.cs @@ -121,7 +121,7 @@ public void TracingOnMetricsOff() } Assert.Null(Activity.Current); - Assert.AreEqual(1, listener.Activities.Count); + Assert.That(listener.Activities.Count, Is.EqualTo(1)); ValidateChatActivity(listener.Activities.Single(), chatCompletion, RequestModel, Host, Port); } @@ -144,9 +144,9 @@ public void ChatTracingAllAttributes() using (var scope = telemetry.StartChatScope(options)) { - Assert.AreEqual(options.Temperature.Value, (float)Activity.Current.GetTagItem("gen_ai.request.temperature"), 0.01); - Assert.AreEqual(options.TopP.Value, (float)Activity.Current.GetTagItem("gen_ai.request.top_p"), 0.01); - Assert.AreEqual(options.MaxOutputTokenCount.Value, Activity.Current.GetTagItem("gen_ai.request.max_tokens")); + Assert.That((float)Activity.Current.GetTagItem("gen_ai.request.temperature"), Is.EqualTo(options.Temperature.Value).Within(0.01)); + Assert.That((float)Activity.Current.GetTagItem("gen_ai.request.top_p"), Is.EqualTo(options.TopP.Value).Within(0.01)); + Assert.That(Activity.Current.GetTagItem("gen_ai.request.max_tokens"), Is.EqualTo(options.MaxOutputTokenCount.Value)); scope.RecordChatCompletion(chatCompletion); } Assert.Null(Activity.Current); @@ -215,23 +215,23 @@ public async Task ChatTracingAndMetricsMultiple() await Task.WhenAll(tasks); - Assert.AreEqual(tasks.Length, activityListener.Activities.Count); + Assert.That(activityListener.Activities.Count, Is.EqualTo(tasks.Length)); var durations = meterListener.GetMeasurements("gen_ai.client.operation.duration"); - Assert.AreEqual(tasks.Length, durations.Count); - Assert.AreEqual(numberOfSuccessfulResponses, durations.Count(d => !d.tags.ContainsKey("error.type"))); + Assert.That(durations.Count, Is.EqualTo(tasks.Length)); + Assert.That(durations.Count(d => !d.tags.ContainsKey("error.type")), Is.EqualTo(numberOfSuccessfulResponses)); var usages = meterListener.GetMeasurements("gen_ai.client.token.usage"); // we don't report usage if there was no response - Assert.AreEqual(numberOfSuccessfulResponses * 2, usages.Count); + Assert.That(usages.Count, Is.EqualTo(numberOfSuccessfulResponses * 2)); Assert.IsEmpty(usages.Where(u => u.tags.ContainsKey("error.type"))); - Assert.AreEqual(totalPromptTokens, usages + Assert.That(usages .Where(u => u.tags.Contains(new KeyValuePair("gen_ai.token.type", "input"))) - .Sum(u => (long)u.value)); - Assert.AreEqual(totalCompletionTokens, usages + .Sum(u => (long)u.value), Is.EqualTo(totalPromptTokens)); + Assert.That(usages .Where(u => u.tags.Contains(new KeyValuePair("gen_ai.token.type", "output"))) - .Sum(u => (long)u.value)); + .Sum(u => (long)u.value), Is.EqualTo(totalCompletionTokens)); } private void SetMessages(ChatCompletionOptions options, params ChatMessage[] messages) @@ -248,7 +248,7 @@ private void ValidateDuration(TestMeterListener listener, ChatCompletion respons var measurements = listener.GetMeasurements("gen_ai.client.operation.duration"); Assert.IsNotNull(measurements); - Assert.AreEqual(1, measurements.Count); + Assert.That(measurements.Count, Is.EqualTo(1)); var measurement = measurements[0]; Assert.IsInstanceOf(measurement.value); @@ -266,7 +266,7 @@ private void ValidateUsage(TestMeterListener listener, ChatCompletion response, var measurements = listener.GetMeasurements("gen_ai.client.token.usage"); Assert.IsNotNull(measurements); - Assert.AreEqual(2, measurements.Count); + Assert.That(measurements.Count, Is.EqualTo(2)); foreach (var measurement in measurements) { @@ -280,8 +280,8 @@ private void ValidateUsage(TestMeterListener listener, ChatCompletion response, TestMeasurement input = (type is "input") ? measurements[0] : measurements[1]; TestMeasurement output = (type is "input") ? measurements[1] : measurements[0]; - Assert.AreEqual(inputTokens, input.value); - Assert.AreEqual(outputTokens, output.value); + Assert.That(input.value, Is.EqualTo(inputTokens)); + Assert.That(output.value, Is.EqualTo(outputTokens)); } private static ChatCompletion CreateChatCompletion(int promptTokens = PromptTokens, int completionTokens = CompletionTokens) diff --git a/tests/Telemetry/TestActivityListener.cs b/tests/Telemetry/TestActivityListener.cs index ae53c2fe7..fb591e7d2 100644 --- a/tests/Telemetry/TestActivityListener.cs +++ b/tests/Telemetry/TestActivityListener.cs @@ -38,28 +38,28 @@ public void Dispose() public static void ValidateChatActivity(Activity activity, ChatCompletion response, string requestModel = "gpt-4o-mini", string host = "api.openai.com", int port = 443) { Assert.NotNull(activity); - Assert.AreEqual($"chat {requestModel}", activity.DisplayName); - Assert.AreEqual("chat", activity.GetTagItem("gen_ai.operation.name")); - Assert.AreEqual("openai", activity.GetTagItem("gen_ai.system")); - Assert.AreEqual(requestModel, activity.GetTagItem("gen_ai.request.model")); + Assert.That(activity.DisplayName, Is.EqualTo($"chat {requestModel}")); + Assert.That(activity.GetTagItem("gen_ai.operation.name"), Is.EqualTo("chat")); + Assert.That(activity.GetTagItem("gen_ai.system"), Is.EqualTo("openai")); + Assert.That(activity.GetTagItem("gen_ai.request.model"), Is.EqualTo(requestModel)); - Assert.AreEqual(host, activity.GetTagItem("server.address")); - Assert.AreEqual(port, activity.GetTagItem("server.port")); + Assert.That(activity.GetTagItem("server.address"), Is.EqualTo(host)); + Assert.That(activity.GetTagItem("server.port"), Is.EqualTo(port)); if (response != null) { - Assert.AreEqual(response.Model, activity.GetTagItem("gen_ai.response.model")); - Assert.AreEqual(response.Id, activity.GetTagItem("gen_ai.response.id")); - Assert.AreEqual(new[] { response.FinishReason.ToString().ToLower() }, activity.GetTagItem("gen_ai.response.finish_reasons")); - Assert.AreEqual(response.Usage.OutputTokenCount, activity.GetTagItem("gen_ai.usage.output_tokens")); - Assert.AreEqual(response.Usage.InputTokenCount, activity.GetTagItem("gen_ai.usage.input_tokens")); - Assert.AreEqual(ActivityStatusCode.Unset, activity.Status); + Assert.That(activity.GetTagItem("gen_ai.response.model"), Is.EqualTo(response.Model)); + Assert.That(activity.GetTagItem("gen_ai.response.id"), Is.EqualTo(response.Id)); + Assert.That(activity.GetTagItem("gen_ai.response.finish_reasons"), Is.EqualTo(new[] { response.FinishReason.ToString().ToLower() })); + Assert.That(activity.GetTagItem("gen_ai.usage.output_tokens"), Is.EqualTo(response.Usage.OutputTokenCount)); + Assert.That(activity.GetTagItem("gen_ai.usage.input_tokens"), Is.EqualTo(response.Usage.InputTokenCount)); + Assert.That(activity.Status, Is.EqualTo(ActivityStatusCode.Unset)); Assert.Null(activity.StatusDescription); Assert.Null(activity.GetTagItem("error.type")); } else { - Assert.AreEqual(ActivityStatusCode.Error, activity.Status); + Assert.That(activity.Status, Is.EqualTo(ActivityStatusCode.Error)); Assert.NotNull(activity.GetTagItem("error.type")); } } @@ -67,6 +67,6 @@ public static void ValidateChatActivity(Activity activity, ChatCompletion respon public static void ValidateChatActivity(Activity activity, Exception ex, string requestModel = "gpt-4o-mini", string host = "api.openai.com", int port = 443) { ValidateChatActivity(activity, (ChatCompletion)null, requestModel, host, port); - Assert.AreEqual(ex.GetType().FullName, activity.GetTagItem("error.type")); + Assert.That(activity.GetTagItem("error.type"), Is.EqualTo(ex.GetType().FullName)); } } diff --git a/tests/Telemetry/TestMeterListener.cs b/tests/Telemetry/TestMeterListener.cs index a8a5cdc01..4312cdd45 100644 --- a/tests/Telemetry/TestMeterListener.cs +++ b/tests/Telemetry/TestMeterListener.cs @@ -62,15 +62,15 @@ public void Dispose() public static void ValidateChatMetricTags(TestMeasurement measurement, ChatCompletion response, string requestModel = "gpt-4o-mini", string host = "api.openai.com", int port = 443) { - Assert.AreEqual("openai", measurement.tags["gen_ai.system"]); - Assert.AreEqual("chat", measurement.tags["gen_ai.operation.name"]); - Assert.AreEqual(host, measurement.tags["server.address"]); - Assert.AreEqual(requestModel, measurement.tags["gen_ai.request.model"]); - Assert.AreEqual(port, measurement.tags["server.port"]); + Assert.That(measurement.tags["gen_ai.system"], Is.EqualTo("openai")); + Assert.That(measurement.tags["gen_ai.operation.name"], Is.EqualTo("chat")); + Assert.That(measurement.tags["server.address"], Is.EqualTo(host)); + Assert.That(measurement.tags["gen_ai.request.model"], Is.EqualTo(requestModel)); + Assert.That(measurement.tags["server.port"], Is.EqualTo(port)); if (response != null) { - Assert.AreEqual(response.Model, measurement.tags["gen_ai.response.model"]); + Assert.That(measurement.tags["gen_ai.response.model"], Is.EqualTo(response.Model)); Assert.False(measurement.tags.ContainsKey("error.type")); } } @@ -79,6 +79,6 @@ public static void ValidateChatMetricTags(TestMeasurement measurement, Exception { ValidateChatMetricTags(measurement, (ChatCompletion)null, requestModel, host, port); Assert.True(measurement.tags.ContainsKey("error.type")); - Assert.AreEqual(ex.GetType().FullName, measurement.tags["error.type"]); + Assert.That(measurement.tags["error.type"], Is.EqualTo(ex.GetType().FullName)); } }