/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Http/Http.Results/test/EmptyResultTests.cs
50 строк
2 KB
Alexander Köplinger
Upgrade xunit version to 2.9.0 (#57303)
23 авг 2024, 20:27
Не верифицирован
23 авг 2024, 20:27
9209724
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Http.HttpResults; public class EmptyResultTests { [Fact] public async Task EmptyResult_DoesNothing() { // Arrange var emptyResult = EmptyHttpResult.Instance; // Act var httpContext = GetHttpContext(); var memoryStream = httpContext.Response.Body as MemoryStream; await emptyResult.ExecuteAsync(httpContext); // Assert Assert.Equal(StatusCodes.Status200OK, httpContext.Response.StatusCode); Assert.Equal(0, memoryStream.Length); } [Fact] public async Task ExecuteAsync_ThrowsArgumentNullException_WhenHttpContextIsNull() { // Arrange var result = EmptyHttpResult.Instance; HttpContext httpContext = null; // Act & Assert await Assert.ThrowsAsync<ArgumentNullException>("httpContext", () => result.ExecuteAsync(httpContext)); } private static HttpContext GetHttpContext() { var httpContext = new DefaultHttpContext(); httpContext.Request.PathBase = new PathString(""); httpContext.Response.Body = new MemoryStream(); httpContext.RequestServices = CreateServices(); return httpContext; } private static IServiceProvider CreateServices() { return new ServiceCollection().BuildServiceProvider(); } }