From 752d5d33e3598e046e361eb5e38c364550125716 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Feb 2026 20:24:29 +0000 Subject: [PATCH 1/3] Initial plan From 44b4fa3281dcbaee252ba31cdbf605bfdc4ead6d Mon Sep 17 00:00:00 2001 From: "Scott Beddall (from Dev Box)" Date: Mon, 2 Feb 2026 15:53:57 -0800 Subject: [PATCH 2/3] empty-commit From c9e29a0d38e7c9c4f95e9fb5a8370ef2b8f64b4d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 00:02:28 +0000 Subject: [PATCH 3/3] Add improved error message for invalid TestMode values Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com> --- .../Helpers/LiveTestSettingsTests.cs | 66 +++++++++++++++++++ .../Client/Helpers/LiveTestSettings.cs | 24 +++++-- 2 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Helpers/LiveTestSettingsTests.cs diff --git a/core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Helpers/LiveTestSettingsTests.cs b/core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Helpers/LiveTestSettingsTests.cs new file mode 100644 index 0000000000..7ef3202ab7 --- /dev/null +++ b/core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Helpers/LiveTestSettingsTests.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Text.Json; +using System.Text.Json.Serialization; +using Azure.Mcp.Tests.Helpers; +using Xunit; + +namespace Azure.Mcp.Core.UnitTests.Helpers; + +public class LiveTestSettingsTests +{ + [Fact] + public void JsonDeserialization_WithInvalidTestMode_ThrowsJsonException() + { + // Arrange - Create JSON with an invalid TestMode value + var json = """{"TestMode": "InvalidMode", "TenantId": "test-tenant"}"""; + + // Act & Assert - Verify JsonException is thrown + var exception = Assert.Throws(() => + JsonSerializer.Deserialize(json, new JsonSerializerOptions() + { + PropertyNameCaseInsensitive = true, + Converters = { new JsonStringEnumConverter() } + })); + + // Verify the error message mentions TestMode + Assert.Contains("TestMode", exception.Message); + } + + [Theory] + [InlineData("Live", TestMode.Live)] + [InlineData("Record", TestMode.Record)] + [InlineData("Playback", TestMode.Playback)] + [InlineData("live", TestMode.Live)] // Test case-insensitive + [InlineData("record", TestMode.Record)] + [InlineData("playback", TestMode.Playback)] + public void JsonDeserialization_WithValidTestMode_LoadsSuccessfully(string testModeValue, TestMode expectedMode) + { + // Arrange - Create JSON with valid TestMode value + var json = $$$"""{"TestMode": "{{{testModeValue}}}", "TenantId": "test-tenant", "SubscriptionId": "test-subscription"}"""; + + // Act - Deserialize the JSON + var settings = JsonSerializer.Deserialize(json, new JsonSerializerOptions() + { + PropertyNameCaseInsensitive = true, + Converters = { new JsonStringEnumConverter() } + }); + + // Assert - Verify the settings were loaded correctly + Assert.NotNull(settings); + Assert.Equal(expectedMode, settings.TestMode); + Assert.Equal("test-tenant", settings.TenantId); + Assert.Equal("test-subscription", settings.SubscriptionId); + } + + /// + /// Proxy class for testing LiveTestSettings JSON deserialization without file I/O + /// + private class LiveTestSettingsProxy + { + public TestMode TestMode { get; set; } = TestMode.Live; + public string TenantId { get; set; } = string.Empty; + public string SubscriptionId { get; set; } = string.Empty; + } +} diff --git a/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/Helpers/LiveTestSettings.cs b/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/Helpers/LiveTestSettings.cs index ef350bae80..842f5bc20d 100644 --- a/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/Helpers/LiveTestSettings.cs +++ b/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/Helpers/LiveTestSettings.cs @@ -53,16 +53,26 @@ public static bool TryLoadTestSettings([NotNullWhen(true)] out LiveTestSettings? { var json = File.ReadAllText(path); - settings = JsonSerializer.Deserialize(json, new JsonSerializerOptions() + try { - PropertyNameCaseInsensitive = true, - Converters = { new JsonStringEnumConverter() } - }); + settings = JsonSerializer.Deserialize(json, new JsonSerializerOptions() + { + PropertyNameCaseInsensitive = true, + Converters = { new JsonStringEnumConverter() } + }); - if (settings != null) + if (settings != null) + { + settings.SettingsDirectory = Path.GetDirectoryName(path) ?? string.Empty; + return true; + } + } + catch (JsonException ex) when (ex.Message.Contains("TestMode")) { - settings.SettingsDirectory = Path.GetDirectoryName(path) ?? string.Empty; - return true; + var validValues = string.Join(", ", Enum.GetNames()); + throw new InvalidOperationException( + $"Invalid TestMode value in {TestSettingsFileName}. Valid values are: {validValues}. " + + $"Error details: {ex.Message}", ex); } }