OnStarting throws when Response.HasStarted

This commit is contained in:
Ryan Brandenburg 2017-01-25 17:01:14 -08:00
parent 37d41f36c7
commit 51b3e82701
2 changed files with 23 additions and 0 deletions

View File

@ -36,6 +36,11 @@ namespace Microsoft.AspNetCore.TestHost
public void OnStarting(Func<object, Task> callback, object state)
{
if (HasStarted)
{
throw new InvalidOperationException();
}
var prior = _responseStartingAsync;
_responseStartingAsync = async () =>
{

View File

@ -1,6 +1,7 @@
// 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;
using System.Threading.Tasks;
using Xunit;
@ -22,5 +23,22 @@ namespace Microsoft.AspNetCore.TestHost
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");
});
}
}
}