Example #1
0
    public async Task DoesNotSupportNonUriEndPoints()
    {
        var factory = new HttpConnectionFactory(
            Options.Create(new HttpConnectionOptions {
            DefaultTransferFormat = TransferFormat.Text
        }),
            NullLoggerFactory.Instance);

        var ex = await Assert.ThrowsAsync <NotSupportedException>(async() => await factory.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 0)));

        Assert.Equal("The provided EndPoint must be of type UriEndPoint.", ex.Message);
    }
        public async Task ConnectionIsDisposedIfItFailsToStartAsync()
        {
            var testHandler = new TestHttpMessageHandler(autoNegotiate: false, handleFirstPoll: false);

            testHandler.OnRequest((req, next, ct) => Task.FromException <HttpResponseMessage>(new Exception("BOOM")));

            var factory = new HttpConnectionFactory(Options.Create(new HttpConnectionOptions()
            {
                Url = new Uri("http://example.com"),
                HttpMessageHandlerFactory = _ => testHandler
            }), NullLoggerFactory.Instance);

            // We don't care about the specific exception
            await Assert.ThrowsAnyAsync <Exception>(() => factory.ConnectAsync(TransferFormat.Text));

            // We care that the handler (and by extension the client) was disposed
            Assert.True(testHandler.Disposed);
        }
Example #3
0
        public async Task OptionsUrlMustMatchEndPointIfSet()
        {
            var url1 = new Uri("http://example.com/1");
            var url2 = new Uri("http://example.com/2");

            var factory = new HttpConnectionFactory(
                Options.Create(new HttpConnectionOptions
            {
                Url = url1,
                DefaultTransferFormat = TransferFormat.Text
            }),
                NullLoggerFactory.Instance);

            var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await factory.ConnectAsync(new UriEndPoint(url2)));

            Assert.Equal("If HttpConnectionOptions.Url was set, it must match the UriEndPoint.Uri passed to ConnectAsync.", ex.Message);
        }