blob: 998d0a34a43a64b452dbdea2d78401d4d02e6759 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
{
public class ListenOptionsTests
{
[Fact]
public void ProtocolsDefault()
{
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0));
Assert.Equal(HttpProtocols.Http1AndHttp2, listenOptions.Protocols);
}
[Fact]
public void LocalHostListenOptionsClonesConnectionMiddleware()
{
var localhostListenOptions = new LocalhostListenOptions(1004);
localhostListenOptions.ConnectionAdapters.Add(new PassThroughConnectionAdapter());
var serviceProvider = new ServiceCollection().BuildServiceProvider();
localhostListenOptions.KestrelServerOptions = new KestrelServerOptions
{
ApplicationServices = serviceProvider
};
var middlewareRan = false;
localhostListenOptions.Use(next =>
{
middlewareRan = true;
return context => Task.CompletedTask;
});
var clone = localhostListenOptions.Clone(IPAddress.IPv6Loopback);
var app = clone.Build();
// Execute the delegate
app(null);
Assert.True(middlewareRan);
Assert.NotNull(clone.KestrelServerOptions);
Assert.NotNull(serviceProvider);
Assert.Same(serviceProvider, clone.ApplicationServices);
Assert.Single(clone.ConnectionAdapters);
}
}
}
|