Fix not setting HttpConnection.ConnectionId (#2154)
This commit is contained in:
parent
3e906fb64a
commit
41c8dcf449
|
|
@ -68,8 +68,19 @@ namespace Microsoft.AspNetCore.Http.Connections.Client
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override IFeatureCollection Features { get; } = new FeatureCollection();
|
public override IFeatureCollection Features { get; } = new FeatureCollection();
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <summary>
|
||||||
public override string ConnectionId { get; set; }
|
/// Gets or sets the connection ID.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The connection ID is set when the <see cref="HttpConnection"/> is started and should not be set by user code.
|
||||||
|
/// If the connection was created with <see cref="HttpConnectionOptions.SkipNegotiation"/> set to <c>true</c>
|
||||||
|
/// then the connection ID will be <c>null</c>.
|
||||||
|
/// </remarks>
|
||||||
|
public override string ConnectionId
|
||||||
|
{
|
||||||
|
get => _connectionId;
|
||||||
|
set => throw new InvalidOperationException("The ConnectionId is set internally and should not be set by user code.");
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override IDictionary<object, object> Items { get; set; } = new ConnectionItems();
|
public override IDictionary<object, object> Items { get; set; } = new ConnectionItems();
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,42 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
Assert.Equal(expectedNegotiate, await negotiateUrlTcs.Task.OrTimeout());
|
Assert.Equal(expectedNegotiate, await negotiateUrlTcs.Task.OrTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task NegotiateReturnedConenctionIdIsSetOnConnection()
|
||||||
|
{
|
||||||
|
string connectionId = null;
|
||||||
|
|
||||||
|
var testHttpHandler = new TestHttpMessageHandler(autoNegotiate: false);
|
||||||
|
testHttpHandler.OnNegotiate((request, cancellationToken) => ResponseUtils.CreateResponse(HttpStatusCode.OK,
|
||||||
|
JsonConvert.SerializeObject(new
|
||||||
|
{
|
||||||
|
connectionId = "0rge0d00-0040-0030-0r00-000q00r00e00",
|
||||||
|
availableTransports = new object[]
|
||||||
|
{
|
||||||
|
new
|
||||||
|
{
|
||||||
|
transport = "LongPolling",
|
||||||
|
transferFormats = new[] { "Text" }
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})));
|
||||||
|
testHttpHandler.OnLongPoll(cancellationToken => ResponseUtils.CreateResponse(HttpStatusCode.NoContent));
|
||||||
|
testHttpHandler.OnLongPollDelete((token) => ResponseUtils.CreateResponse(HttpStatusCode.Accepted));
|
||||||
|
|
||||||
|
using (var noErrorScope = new VerifyNoErrorsScope())
|
||||||
|
{
|
||||||
|
await WithConnectionAsync(
|
||||||
|
CreateConnection(testHttpHandler, loggerFactory: noErrorScope.LoggerFactory),
|
||||||
|
async (connection) =>
|
||||||
|
{
|
||||||
|
await connection.StartAsync(TransferFormat.Text).OrTimeout();
|
||||||
|
connectionId = connection.ConnectionId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal("0rge0d00-0040-0030-0r00-000q00r00e00", connectionId);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task NegotiateThatReturnsUrlGetFollowed()
|
public async Task NegotiateThatReturnsUrlGetFollowed()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,14 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
Assert.Equal("httpConnectionOptions", exception.ParamName);
|
Assert.Equal("httpConnectionOptions", exception.ParamName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CannotSetConnectionId()
|
||||||
|
{
|
||||||
|
var connection = new HttpConnection(new Uri("http://fakeuri.org/"));
|
||||||
|
var exception = Assert.Throws<InvalidOperationException>(() => connection.ConnectionId = "custom conneciton ID");
|
||||||
|
Assert.Equal("The ConnectionId is set internally and should not be set by user code.", exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task HttpOptionsSetOntoHttpClientHandler()
|
public async Task HttpOptionsSetOntoHttpClientHandler()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue