Last active
February 24, 2018 09:42
-
-
Save Ibro/1eed7d987f66b8974d17da10fa1333f0 to your computer and use it in GitHub Desktop.
BuildAuthorizationService - ASP.NET Core - Unit Testing Authorization Service - https://codingblast.com/asp-net-core-unit-testing-authorizationservice-inside-controller/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mockMyRepository = new Mock<IMyRepository>(); | |
mockMyRepository.Setup(repo => repo.GetData("john")) | |
.Returns(Task.FromResult("Corrrect")); | |
mockMyRepository.Setup(repo => repo.GetData("codingblast")) | |
.Returns(Task.FromResult("Yeah!")); | |
var authService = BuildAuthorizationService(services => | |
{ | |
services.AddScoped<IMyRepository>(sp => mockMyRepository.Object); | |
services.AddScoped<IAuthorizationHandler, MyCustomHandler>(); | |
services.AddAuthorization(options => | |
{ | |
options.AddPolicy("PolicyName", policy => policy.Requirements.Add(new MyCustomRequirement())); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment