diff --git a/DevProxy.Tests/ProxyControllerTests.cs b/DevProxy.Tests/ProxyControllerTests.cs new file mode 100644 index 000000000..c9158900c --- /dev/null +++ b/DevProxy.Tests/ProxyControllerTests.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Security.Cryptography; +using System.Security.Cryptography.X509Certificates; +using DevProxy.ApiControllers; +using Microsoft.AspNetCore.Mvc; +using Xunit; + +namespace DevProxy.Tests; + +public sealed class ProxyControllerTests +{ + [Fact] + public async Task RaiseMockRequestAsync_ReturnsNoContentAfterMockRequestCompletes() + { + var stateController = new FakeProxyStateController(); + using var rsa = RSA.Create(2048); + var request = new CertificateRequest("CN=test", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); + using var cert = request.CreateSelfSigned(DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddDays(1)); + var controller = new ProxyController(stateController, new FakeProxyConfiguration(), cert); + + var result = await controller.RaiseMockRequestAsync(CancellationToken.None); + + _ = Assert.IsType(result); + Assert.Equal(1, stateController.MockRequestCalls); + } +} diff --git a/DevProxy/ApiControllers/ProxyController.cs b/DevProxy/ApiControllers/ProxyController.cs index 31b55b0c9..3332dab6c 100644 --- a/DevProxy/ApiControllers/ProxyController.cs +++ b/DevProxy/ApiControllers/ProxyController.cs @@ -57,11 +57,11 @@ public async Task SetAsync([FromBody] ProxyInfo proxyInfo, Cancel [HttpPost("mockRequest")] #pragma warning disable CA1030 - public async Task RaiseMockRequestAsync(CancellationToken cancellationToken) + public async Task RaiseMockRequestAsync(CancellationToken cancellationToken) #pragma warning restore CA1030 { await _proxyStateController.MockRequestAsync(cancellationToken); - Response.StatusCode = 202; + return NoContent(); } [HttpPost("stopProxy")]