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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
namespace ArgusTransfer.Tests.Extensions
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using ArgusTransfer.Client;
using ArgusTransfer.Extensions;
Expand All @@ -30,6 +32,7 @@ namespace ArgusTransfer.Tests.Extensions
using ArgusTransfer.Serialization;
using ArgusTransfer.Server;

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -335,6 +338,51 @@ public void Verify_that_AddArgusPipeHost_resolves_without_ambiguity()
Assert.That(hostedServices.OfType<ArgusPipeHostBackgroundService>().Count(), Is.EqualTo(1));
}

[Test]
public void Verify_that_AddArgusPipeHost_with_an_invalid_option_fails_when_the_host_is_created()
{
var services = new ServiceCollection();

services.AddLogging();
services.AddSingleton<ArgusRouter>();
services.AddArgusPipeHost(options => options.RequestReadTimeout = TimeSpan.FromSeconds(-30));

var provider = services.BuildServiceProvider();

// The generic host resolves its hosted services when it starts, so the invalid option stops the startup with
// an exception that names it, instead of failing every request later
Assert.That(
() => provider.GetServices<IHostedService>().ToList(),
Throws.TypeOf<ArgumentOutOfRangeException>().With.Message.Contains(nameof(ArgusPipeHostOptions.RequestReadTimeout)));
Assert.That(
() => provider.GetRequiredService<IOptions<ArgusPipeHostOptions>>().Value,
Throws.TypeOf<ArgumentOutOfRangeException>());
}

[Test]
public void Verify_that_an_invalid_option_bound_from_configuration_fails_with_an_exception_that_names_the_option()
{
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string> { ["Argus:RequestReadTimeout"] = "-00:00:30" })
.Build();

var services = new ServiceCollection();

services.AddLogging();
services.AddSingleton<ArgusRouter>();
services.Configure<ArgusPipeHostOptions>(configuration.GetSection("Argus"));
services.AddArgusPipeHost();

var provider = services.BuildServiceProvider();

// The configuration binder sets the option through reflection, which wraps the exception of the setter
Assert.That(
() => provider.GetServices<IHostedService>().ToList(),
Throws.TypeOf<TargetInvocationException>()
.With.InnerException.TypeOf<ArgumentOutOfRangeException>()
.And.InnerException.Message.Contains(nameof(ArgusPipeHostOptions.RequestReadTimeout)));
}

[Test]
public void Verify_that_AddArgusBodySerializer_does_not_duplicate()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,26 @@ public async Task Verify_that_large_body_over_the_limit_gets_BadRequest_promptly
cts.Dispose();
}

[Test]
public async Task Verify_that_a_MaxRequestBodySize_of_zero_accepts_a_body_larger_than_the_default_limit()
{
var pipeName = $"argus-no-body-limit-test-{Guid.NewGuid():N}";
var (hostService, cts) = await this.StartHostAsync(CreateEchoRouter(), new ArgusPipeHostOptions { PipeName = pipeName, MaxRequestBodySize = 0 });

using var client = new ArgusClient(pipeName);

// A 2 MB body: twice the default limit of 1 MB
var body = new string('x', 2_000_000);
var response = await client.PostAsync("/echo", body, timeout: TimeSpan.FromSeconds(10));

Assert.That(response.StatusCode, Is.EqualTo(ArgusStatusCode.Ok));
Assert.That(response.Body, Has.Length.EqualTo(body.Length));

await cts.CancelAsync();
await hostService.StopAsync(CancellationToken.None);
cts.Dispose();
}

[Test]
public async Task Verify_that_oversized_headers_sent_by_ArgusClient_get_BadRequest_promptly()
{
Expand Down
Loading
Loading