From 158bea8f7d8cd61c3a6365db54cfc400e2196ca3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Feb 2026 10:40:46 +0000 Subject: [PATCH 1/2] Initial plan From 5e8ec3a253bf25ba3fbbb521b73ce308fdca7519 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Feb 2026 10:48:17 +0000 Subject: [PATCH 2/2] Fix FakeHttpMessageHandler disposal to use using statements Co-authored-by: gwharris7 <96964444+gwharris7@users.noreply.github.com> --- .../Services/AgentBlueprintServiceTests.cs | 100 +++++++++--------- 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Services/AgentBlueprintServiceTests.cs b/src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Services/AgentBlueprintServiceTests.cs index ebe65957..09496587 100644 --- a/src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Services/AgentBlueprintServiceTests.cs +++ b/src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Services/AgentBlueprintServiceTests.cs @@ -329,42 +329,42 @@ public async Task GetAgentInstancesForBlueprintAsync_ReturnsFilteredInstances() { // Arrange var (service, handler) = CreateServiceWithFakeHandler(); - - const string blueprintId = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"; - - // Response 1: GET /beta/servicePrincipals/microsoft.graph.agentIdentity?$filter=agentIdentityBlueprintId eq '...' - // Server-side filtered response returns only matching SPs - handler.QueueResponse(new HttpResponseMessage(HttpStatusCode.OK) + using (handler) { - Content = new StringContent(JsonSerializer.Serialize(new + const string blueprintId = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"; + + // Response 1: GET /beta/servicePrincipals/microsoft.graph.agentIdentity?$filter=agentIdentityBlueprintId eq '...' + // Server-side filtered response returns only matching SPs + handler.QueueResponse(new HttpResponseMessage(HttpStatusCode.OK) { - value = new[] + Content = new StringContent(JsonSerializer.Serialize(new { - new { id = "sp-obj-1", displayName = "Instance A", agentIdentityBlueprintId = blueprintId } - } - })) - }); + value = new[] + { + new { id = "sp-obj-1", displayName = "Instance A", agentIdentityBlueprintId = blueprintId } + } + })) + }); - // Response 2: GET /beta/users?$filter=identityParentId eq 'sp-obj-1' - // Secondary call to resolve the agentic user for the matching SP - handler.QueueResponse(new HttpResponseMessage(HttpStatusCode.OK) - { - Content = new StringContent(JsonSerializer.Serialize(new + // Response 2: GET /beta/users?$filter=identityParentId eq 'sp-obj-1' + // Secondary call to resolve the agentic user for the matching SP + handler.QueueResponse(new HttpResponseMessage(HttpStatusCode.OK) { - value = new[] { new { id = "user-obj-1" } } - })) - }); - - // Act - var instances = await service.GetAgentInstancesForBlueprintAsync("tenant-id", blueprintId); + Content = new StringContent(JsonSerializer.Serialize(new + { + value = new[] { new { id = "user-obj-1" } } + })) + }); - // Assert - instances.Should().HaveCount(1); - instances[0].IdentitySpId.Should().Be("sp-obj-1"); - instances[0].DisplayName.Should().Be("Instance A"); - instances[0].AgentUserId.Should().Be("user-obj-1"); + // Act + var instances = await service.GetAgentInstancesForBlueprintAsync("tenant-id", blueprintId); - handler.Dispose(); + // Assert + instances.Should().HaveCount(1); + instances[0].IdentitySpId.Should().Be("sp-obj-1"); + instances[0].DisplayName.Should().Be("Instance A"); + instances[0].AgentUserId.Should().Be("user-obj-1"); + } } [Fact] @@ -372,19 +372,19 @@ public async Task GetAgentInstancesForBlueprintAsync_ReturnsEmpty_WhenNoneFound( { // Arrange var (service, handler) = CreateServiceWithFakeHandler(); - - handler.QueueResponse(new HttpResponseMessage(HttpStatusCode.OK) + using (handler) { - Content = new StringContent(JsonSerializer.Serialize(new { value = Array.Empty() })) - }); + handler.QueueResponse(new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(JsonSerializer.Serialize(new { value = Array.Empty() })) + }); - // Act - var instances = await service.GetAgentInstancesForBlueprintAsync("tenant-id", "b2c3d4e5-f6a7-8901-bcde-f12345678901"); + // Act + var instances = await service.GetAgentInstancesForBlueprintAsync("tenant-id", "b2c3d4e5-f6a7-8901-bcde-f12345678901"); - // Assert - instances.Should().BeEmpty(); - - handler.Dispose(); + // Assert + instances.Should().BeEmpty(); + } } [Fact] @@ -392,24 +392,24 @@ public async Task DeleteAgentUserAsync_ReturnsTrue_OnSuccess() { // Arrange var (service, handler) = CreateServiceWithFakeHandler(); + using (handler) + { + // Queue HTTP response for DELETE /beta/agentUsers/{userId} + handler.QueueResponse(new HttpResponseMessage(HttpStatusCode.NoContent)); - // Queue HTTP response for DELETE /beta/agentUsers/{userId} - handler.QueueResponse(new HttpResponseMessage(HttpStatusCode.NoContent)); - - // Act - var result = await service.DeleteAgentUserAsync("tenant-id", "user-obj-1"); + // Act + var result = await service.DeleteAgentUserAsync("tenant-id", "user-obj-1"); - // Assert - result.Should().BeTrue(); - - handler.Dispose(); + // Assert + result.Should().BeTrue(); + } } [Fact] public async Task DeleteAgentUserAsync_ReturnsFalse_OnGraphError() { // Arrange - var handler = new FakeHttpMessageHandler(); + using var handler = new FakeHttpMessageHandler(); _mockTokenProvider.GetMgGraphAccessTokenAsync( Arg.Any(), Arg.Any>(), Arg.Any(), Arg.Any(), Arg.Any()) @@ -429,8 +429,6 @@ public async Task DeleteAgentUserAsync_ReturnsFalse_OnGraphError() // Assert result.Should().BeFalse(); - - handler.Dispose(); } private (AgentBlueprintService service, FakeHttpMessageHandler handler) CreateServiceWithFakeHandler()