Skip to content

Instantly share code, notes, and snippets.

View StephanyBatista's full-sized avatar

Stephany Henrique Batista StephanyBatista

View GitHub Profile
@StephanyBatista
StephanyBatista / Startup.cs
Created September 12, 2017 11:37
New Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
@StephanyBatista
StephanyBatista / Startup.cs
Created September 12, 2017 11:37
Old Startup.cs
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
[Route("api/[controller]")]
public class TokenController : Controller
{
[HttpPost]
public IActionResult Post([FromBody]LoginModel loginModel)
{
if (loginModel.Username != "stephany" && loginModel.Password != "batista")
return Unauthorized();
var token = new JwtTokenBuilder()
public string Build()
{
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Sub, this.subject),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim("NameId", this.nameId)
}
.Union(this.claims.Select(item => new Claim(item.Key, item.Value)));
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options => {
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
public class ProductController : Controller
{
public IActionResult Index()
{
var applicationDbContext = new ApplicationDbContext(null);
var repository = new ProductRepository(applicationDbContext);
return View(repository.GetAll());
}
}
public class ProductController : Controller
{
private ProductRepository _productRepository;
public ProductController()
{
}
}
public class ProductController : Controller
{
private readonly ProductRepository _productRepository;
public ProductController(ProductRepository productRepository)
{
_productRepository = productRepository;
}
public IActionResult Index()
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
[Fact]
public void DeveCriarCurso()
{
var cursoEsperado = new
{
Nome = _nome,
CargaHoraria = _cargaHoraria,
PublicoAlvo = _publicoAlvo,
Valor = _valor,
Descricao = _descricao