Skip to content

Instantly share code, notes, and snippets.

@Ibro Ibro/UnitTestController.cs
Last active Feb 24, 2018

What would you like to do?
BuildAuthorizationService - ASP.NET Core - Unit Testing Authorization Service -
var mockMyRepository = new Mock<IMyRepository>();
mockMyRepository.Setup(repo => repo.GetData("john"))
mockMyRepository.Setup(repo => repo.GetData("codingblast"))
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
You can’t perform that action at this time.