Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions DevProxy.Tests/ProxyControllerTests.cs
Original file line number Diff line number Diff line change
@@ -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<NoContentResult>(result);
Assert.Equal(1, stateController.MockRequestCalls);
}
}
4 changes: 2 additions & 2 deletions DevProxy/ApiControllers/ProxyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public async Task<IActionResult> SetAsync([FromBody] ProxyInfo proxyInfo, Cancel

[HttpPost("mockRequest")]
#pragma warning disable CA1030
public async Task RaiseMockRequestAsync(CancellationToken cancellationToken)
public async Task<IActionResult> RaiseMockRequestAsync(CancellationToken cancellationToken)
#pragma warning restore CA1030
{
await _proxyStateController.MockRequestAsync(cancellationToken);
Response.StatusCode = 202;
return NoContent();
}

[HttpPost("stopProxy")]
Expand Down
Loading