/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Hosting/TestHost/test/ResponseFeatureTests.cs
84 строки
3 KB
Shreyas Jejurkar
chore : Remove unwanted `using` statement (#39176)
02 янв 2022, 17:39
Не верифицирован
02 янв 2022, 17:39
c85baf8
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace Microsoft.AspNetCore.TestHost; public class ResponseFeatureTests { [Fact] public async Task StatusCode_DefaultsTo200() { // Arrange & Act var responseInformation = CreateResponseFeature(); // Assert Assert.Equal(200, responseInformation.StatusCode); Assert.False(responseInformation.HasStarted); await responseInformation.FireOnSendingHeadersAsync(); Assert.True(responseInformation.HasStarted); Assert.True(responseInformation.Headers.IsReadOnly); } [Fact] public async Task StartAsync_StartsResponse() { // Arrange & Act var responseInformation = CreateResponseFeature(); // Assert Assert.Equal(200, responseInformation.StatusCode); Assert.False(responseInformation.HasStarted); await responseInformation.StartAsync(); Assert.True(responseInformation.HasStarted); Assert.True(responseInformation.Headers.IsReadOnly); } [Fact] public void OnStarting_ThrowsWhenHasStarted() { // Arrange var responseInformation = CreateResponseFeature(); responseInformation.HasStarted = true; // Act & Assert Assert.Throws<InvalidOperationException>(() => { responseInformation.OnStarting((status) => { return Task.FromResult(string.Empty); }, state: "string"); }); } [Fact] public void StatusCode_ThrowsWhenHasStarted() { var responseInformation = CreateResponseFeature(); responseInformation.HasStarted = true; Assert.Throws<InvalidOperationException>(() => responseInformation.StatusCode = 400); Assert.Throws<InvalidOperationException>(() => responseInformation.ReasonPhrase = "Hello World"); } [Fact] public void StatusCode_MustBeGreaterThan99() { var responseInformation = CreateResponseFeature(); Assert.Throws<ArgumentOutOfRangeException>(() => responseInformation.StatusCode = 99); Assert.Throws<ArgumentOutOfRangeException>(() => responseInformation.StatusCode = 0); Assert.Throws<ArgumentOutOfRangeException>(() => responseInformation.StatusCode = -200); responseInformation.StatusCode = 100; responseInformation.StatusCode = 200; responseInformation.StatusCode = 1000; } private ResponseFeature CreateResponseFeature() { return new ResponseFeature(ex => { }); } }