Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/Http/Http.Results/test/ForbidResultTest.cs')
-rw-r--r--src/Http/Http.Results/test/ForbidResultTest.cs215
1 files changed, 107 insertions, 108 deletions
diff --git a/src/Http/Http.Results/test/ForbidResultTest.cs b/src/Http/Http.Results/test/ForbidResultTest.cs
index f123d38469..42236c0066 100644
--- a/src/Http/Http.Results/test/ForbidResultTest.cs
+++ b/src/Http/Http.Results/test/ForbidResultTest.cs
@@ -10,120 +10,119 @@ using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
-namespace Microsoft.AspNetCore.Http.Result
+namespace Microsoft.AspNetCore.Http.Result;
+
+public class ForbidResultTest
{
- public class ForbidResultTest
+ [Fact]
+ public async Task ExecuteResultAsync_InvokesForbidAsyncOnAuthenticationService()
{
- [Fact]
- public async Task ExecuteResultAsync_InvokesForbidAsyncOnAuthenticationService()
- {
- // Arrange
- var auth = new Mock<IAuthenticationService>();
- auth
- .Setup(c => c.ForbidAsync(It.IsAny<HttpContext>(), "", null))
- .Returns(Task.CompletedTask)
- .Verifiable();
- var httpContext = GetHttpContext(auth.Object);
- var result = new ForbidResult("", null);
-
- // Act
- await result.ExecuteAsync(httpContext);
-
- // Assert
- auth.Verify();
- }
-
- [Fact]
- public async Task ExecuteResultAsync_InvokesForbidAsyncOnAllConfiguredSchemes()
+ // Arrange
+ var auth = new Mock<IAuthenticationService>();
+ auth
+ .Setup(c => c.ForbidAsync(It.IsAny<HttpContext>(), "", null))
+ .Returns(Task.CompletedTask)
+ .Verifiable();
+ var httpContext = GetHttpContext(auth.Object);
+ var result = new ForbidResult("", null);
+
+ // Act
+ await result.ExecuteAsync(httpContext);
+
+ // Assert
+ auth.Verify();
+ }
+
+ [Fact]
+ public async Task ExecuteResultAsync_InvokesForbidAsyncOnAllConfiguredSchemes()
+ {
+ // Arrange
+ var authProperties = new AuthenticationProperties();
+ var auth = new Mock<IAuthenticationService>();
+ auth
+ .Setup(c => c.ForbidAsync(It.IsAny<HttpContext>(), "Scheme1", authProperties))
+ .Returns(Task.CompletedTask)
+ .Verifiable();
+ auth
+ .Setup(c => c.ForbidAsync(It.IsAny<HttpContext>(), "Scheme2", authProperties))
+ .Returns(Task.CompletedTask)
+ .Verifiable();
+ var httpContext = GetHttpContext(auth.Object);
+ var result = new ForbidResult(new[] { "Scheme1", "Scheme2" }, authProperties);
+ var routeData = new RouteData();
+
+ // Act
+ await result.ExecuteAsync(httpContext);
+
+ // Assert
+ auth.Verify();
+ }
+
+ public static TheoryData ExecuteResultAsync_InvokesForbidAsyncWithAuthPropertiesData =>
+ new TheoryData<AuthenticationProperties>
{
- // Arrange
- var authProperties = new AuthenticationProperties();
- var auth = new Mock<IAuthenticationService>();
- auth
- .Setup(c => c.ForbidAsync(It.IsAny<HttpContext>(), "Scheme1", authProperties))
- .Returns(Task.CompletedTask)
- .Verifiable();
- auth
- .Setup(c => c.ForbidAsync(It.IsAny<HttpContext>(), "Scheme2", authProperties))
- .Returns(Task.CompletedTask)
- .Verifiable();
- var httpContext = GetHttpContext(auth.Object);
- var result = new ForbidResult(new[] { "Scheme1", "Scheme2" }, authProperties);
- var routeData = new RouteData();
-
- // Act
- await result.ExecuteAsync(httpContext);
-
- // Assert
- auth.Verify();
- }
-
- public static TheoryData ExecuteResultAsync_InvokesForbidAsyncWithAuthPropertiesData =>
- new TheoryData<AuthenticationProperties>
- {
null,
new AuthenticationProperties()
- };
+ };
- [Theory]
- [MemberData(nameof(ExecuteResultAsync_InvokesForbidAsyncWithAuthPropertiesData))]
- public async Task ExecuteResultAsync_InvokesForbidAsyncWithAuthProperties(AuthenticationProperties expected)
- {
- // Arrange
- var auth = new Mock<IAuthenticationService>();
- auth
- .Setup(c => c.ForbidAsync(It.IsAny<HttpContext>(), null, expected))
- .Returns(Task.CompletedTask)
- .Verifiable();
- var result = new ForbidResult(expected);
- var httpContext = GetHttpContext(auth.Object);
-
- // Act
- await result.ExecuteAsync(httpContext);
-
- // Assert
- auth.Verify();
- }
-
- [Theory]
- [MemberData(nameof(ExecuteResultAsync_InvokesForbidAsyncWithAuthPropertiesData))]
- public async Task ExecuteResultAsync_InvokesForbidAsyncWithAuthProperties_WhenAuthenticationSchemesIsEmpty(
- AuthenticationProperties expected)
- {
- // Arrange
- var auth = new Mock<IAuthenticationService>();
- auth
- .Setup(c => c.ForbidAsync(It.IsAny<HttpContext>(), null, expected))
- .Returns(Task.CompletedTask)
- .Verifiable();
- var httpContext = GetHttpContext(auth.Object);
- var result = new ForbidResult(expected)
- {
- AuthenticationSchemes = new string[0]
- };
- var routeData = new RouteData();
-
- // Act
- await result.ExecuteAsync(httpContext);
-
- // Assert
- auth.Verify();
- }
-
- private static DefaultHttpContext GetHttpContext(IAuthenticationService auth)
- {
- var httpContext = new DefaultHttpContext();
- httpContext.RequestServices = CreateServices()
- .AddSingleton(auth)
- .BuildServiceProvider();
- return httpContext;
- }
-
- private static IServiceCollection CreateServices()
+ [Theory]
+ [MemberData(nameof(ExecuteResultAsync_InvokesForbidAsyncWithAuthPropertiesData))]
+ public async Task ExecuteResultAsync_InvokesForbidAsyncWithAuthProperties(AuthenticationProperties expected)
+ {
+ // Arrange
+ var auth = new Mock<IAuthenticationService>();
+ auth
+ .Setup(c => c.ForbidAsync(It.IsAny<HttpContext>(), null, expected))
+ .Returns(Task.CompletedTask)
+ .Verifiable();
+ var result = new ForbidResult(expected);
+ var httpContext = GetHttpContext(auth.Object);
+
+ // Act
+ await result.ExecuteAsync(httpContext);
+
+ // Assert
+ auth.Verify();
+ }
+
+ [Theory]
+ [MemberData(nameof(ExecuteResultAsync_InvokesForbidAsyncWithAuthPropertiesData))]
+ public async Task ExecuteResultAsync_InvokesForbidAsyncWithAuthProperties_WhenAuthenticationSchemesIsEmpty(
+ AuthenticationProperties expected)
+ {
+ // Arrange
+ var auth = new Mock<IAuthenticationService>();
+ auth
+ .Setup(c => c.ForbidAsync(It.IsAny<HttpContext>(), null, expected))
+ .Returns(Task.CompletedTask)
+ .Verifiable();
+ var httpContext = GetHttpContext(auth.Object);
+ var result = new ForbidResult(expected)
{
- var services = new ServiceCollection();
- services.AddSingleton(typeof(ILogger<>), typeof(NullLogger<>));
- return services;
- }
+ AuthenticationSchemes = new string[0]
+ };
+ var routeData = new RouteData();
+
+ // Act
+ await result.ExecuteAsync(httpContext);
+
+ // Assert
+ auth.Verify();
+ }
+
+ private static DefaultHttpContext GetHttpContext(IAuthenticationService auth)
+ {
+ var httpContext = new DefaultHttpContext();
+ httpContext.RequestServices = CreateServices()
+ .AddSingleton(auth)
+ .BuildServiceProvider();
+ return httpContext;
+ }
+
+ private static IServiceCollection CreateServices()
+ {
+ var services = new ServiceCollection();
+ services.AddSingleton(typeof(ILogger<>), typeof(NullLogger<>));
+ return services;
}
}