Skip to content

Instantly share code, notes, and snippets.

View evan-boissonnot's full-sized avatar
🏠
Working from home

Evan BOISSONNOT evan-boissonnot

🏠
Working from home
View GitHub Profile
@evan-boissonnot
evan-boissonnot / app.component.test.ts
Created February 6, 2019 09:50
Mock component inside AppComponent
import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { MockComponent } from 'ng2-mock-component';
import { AppComponent } from './app.component';
import { GlobalMenuComponent } from './global-menu/global-menu.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
@evan-boissonnot
evan-boissonnot / karma.config.js
Created February 6, 2019 10:08
Karma config with global variables
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
@evan-boissonnot
evan-boissonnot / Startup.cs
Created February 16, 2019 11:25
Use Cors, asp.net api, asp.net core
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
@evan-boissonnot
evan-boissonnot / Startup.cs
Created February 16, 2019 11:36
AllowSpecificOrigin Cors asp.net core
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
@evan-boissonnot
evan-boissonnot / Startup.cs
Created February 16, 2019 11:38
AddCors, AddPolicy, AllowSpecificOrigin asp.net core api
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigin",
builder => builder.WithOrigins("http://example.com"));
});
}
@evan-boissonnot
evan-boissonnot / Livre.cs
Created February 20, 2019 16:05
Remote attribute in model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace TestAspNetMvcNet.Models
{
public class Livre
{
@evan-boissonnot
evan-boissonnot / LaserController
Created February 20, 2019 16:08
Remote calling this controller with JsonResult result
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
namespace TestAspNetMvcNet.Controllers
{
public class LaserController : Controller
@evan-boissonnot
evan-boissonnot / Create.cshtml
Created February 20, 2019 16:10
Remote jqueryval
@model TestAspNetMvcNet.Models.Livre
@{
ViewBag.Title = "Create";
List<SelectListItem> list = new List<SelectListItem>()
{
new SelectListItem() { Text = "Pisto 1", Value = "1" },
new SelectListItem() { Text = "Pisto 2", Value = "2" }
};
@evan-boissonnot
evan-boissonnot / HomeController.cs
Created February 21, 2019 15:04
generic db set, generic add
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace TestAspNetMvcNet.Models
{
public class BaseDataLayer<T>
{
public void Add(T item)
@evan-boissonnot
evan-boissonnot / Startup.cs
Created March 22, 2019 09:13
JwtBearer configuration, with issuer and audience validation
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.SaveToken = true;
options.TokenValidationParameters = new TokenValidationParameters()
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,