OnStarting throws when Response.HasStarted
This commit is contained in:
parent
37d41f36c7
commit
51b3e82701
|
|
@ -36,6 +36,11 @@ namespace Microsoft.AspNetCore.TestHost
|
||||||
|
|
||||||
public void OnStarting(Func<object, Task> callback, object state)
|
public void OnStarting(Func<object, Task> callback, object state)
|
||||||
{
|
{
|
||||||
|
if (HasStarted)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
var prior = _responseStartingAsync;
|
var prior = _responseStartingAsync;
|
||||||
_responseStartingAsync = async () =>
|
_responseStartingAsync = async () =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -22,5 +23,22 @@ namespace Microsoft.AspNetCore.TestHost
|
||||||
|
|
||||||
Assert.True(responseInformation.HasStarted);
|
Assert.True(responseInformation.HasStarted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void OnStarting_ThrowsWhenHasStarted()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var responseInformation = new ResponseFeature();
|
||||||
|
responseInformation.HasStarted = true;
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<InvalidOperationException>(() =>
|
||||||
|
{
|
||||||
|
responseInformation.OnStarting((status) =>
|
||||||
|
{
|
||||||
|
return Task.FromResult(string.Empty);
|
||||||
|
}, state: "string");
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue