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
public async Task<IActionResult> AddEmployeeClaim() | |
{ | |
var user = await _userManager.GetUserAsync(User); | |
var claim = new Claim("Employee", "Mosalla"); | |
var addClaimResult = await _userManager.AddClaimAsync(user, claim); | |
return View(addClaimResult); | |
} |
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
public class Startup | |
{ | |
public Startup(IConfiguration configuration, IHostingEnvironment env) | |
{ | |
var builder = new ConfigurationBuilder() | |
.SetBasePath(env.ContentRootPath) | |
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); | |
Configuration = builder.Build(); | |
} |
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
[HttpGet] | |
public async Task<IActionResult> Detail(int id) | |
{ | |
if (id == default(int)) return BadRequest(); | |
var model = await _mediator.Send(new PortfolioByIdQuery { PortfolioId = id }); | |
if (model == null) return NotFound(); | |
var viewModel = _mapper.Map<Portfolio, PortfolioViewModel>(model); |
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
public class PortfolioControllerTests | |
{ | |
private readonly IMediator _mediatorFake; | |
private readonly IMapper _mapperFake; | |
private readonly PortfolioController _sut; | |
public PortfolioControllerTests() | |
{ | |
_mediatorFake = A.Fake<IMediator>(); | |
_mapperFake = A.Fake<IMapper>(); |
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
Fact] | |
public async Task Detail_PassesTheCorrectIdIntoPortfolioByIdQuery() | |
{ | |
var mapperFake = A.Fake<IMapper>(); | |
var mediatorMock = A.Fake<IMediator>(); | |
var sut = new PortfolioController(mapperFake, mediatorMock); | |
var portfolioId = 2; | |
await sut.Detail(portfolioId); |
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
namespace ApiResource.Controllers | |
{ | |
[Produces("application/json")] | |
[Authorize] | |
[Route("api/ApiResourceWithoutPolicy")] | |
public class ApiResourceWithoutPolicyController : Controller | |
{ | |
[HttpGet] | |
public IActionResult Get() | |
{ |
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
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvcCore() | |
.AddAuthorization() | |
.AddJsonFormatters(); | |
services.AddAuthentication("Bearer") | |
.AddIdentityServerAuthentication(options => | |
{ | |
options.Authority = "http://localhost:5000"; |
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
public class Config | |
{ | |
public static IEnumerable<ApiResource> GetApiResources() | |
{ | |
return new List<ApiResource> | |
{ | |
new ApiResource("Api1", "Warehouse Api") | |
}; | |
} | |
} |
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
public static List<TestUser> GetUsers() | |
{ | |
return new List<TestUser> | |
{ | |
new TestUser | |
{ | |
SubjectId = "1", | |
Username = "mosalla", | |
Password = "password", | |
Claims = new[] |
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
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddIdentityServer() | |
.AddDeveloperSigningCredential() | |
.AddInMemoryApiResources(Config.GetApiResources()) | |
.AddInMemoryClients(Config.GetClients()) | |
.AddTestUsers(Config.GetUsers()) | |
.AddProfileService<ProfileService>(); | |
} |