Skip to content

Instantly share code, notes, and snippets.

using System.Collections.Generic;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Mvc.Razor;
// These annotations make Resharper not complain about not finding the Views.
// ASP.NET Core support coming to R# for Feature Folders soon - https://youtrack.jetbrains.com/issue/RSRP-461882
[assembly: AspMvcViewLocationFormat("/Features/{1}/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/Shared/{0}.cshtml")]
[assembly: AspMvcPartialViewLocationFormat("~/Features/{1}/{0}.cshtml")]
[assembly: AspMvcPartialViewLocationFormat("~/Features/Shared/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("~/Features/{1}/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("~/Features/Shared/{0}.cshtml")]
[assembly: AspMvcPartialViewLocationFormat("~/Features/{1}/{0}.cshtml")]
[assembly: AspMvcPartialViewLocationFormat("~/Features/Shared/{0}.cshtml")]
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" />
@scottsauber
scottsauber / ApplicationDbContext.cs
Created September 11, 2017 20:46
EF Core 1.x Customizations
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<OrderItem> Orders { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
@scottsauber
scottsauber / ApplicationDbContext.cs
Last active October 17, 2017 11:27
Customizing EF Core tables using EF Core 2.0+
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<OrderItem> OrderItems { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;netstandard20</TargetFrameworks>
<PackageVersion>1.0.0</PackageVersion>
<PackageId>Package Name</PackageId>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
</PropertyGroup>
<ItemGroup>
@scottsauber
scottsauber / Startup.cs
Created October 13, 2017 19:32
InMemory DB Startup
public class Startup
{
public IConfiguration Configuration { get; }
public IHostingEnvironment CurrentEnvironment { get; }
public Startup(IConfiguration configuration, IHostingEnvironment currentEnvironment)
{
Configuration = configuration;
CurrentEnvironment = currentEnvironment;
}
[Produces("application/json")]
[Route("api/ApplicationUsers")]
public class ApplicationUsersController : Controller
{
private readonly ApplicationDbContext _context;
public ApplicationUsersController(ApplicationDbContext context)
{
_context = context;
}
public class ApplicationUsersControllerGetApplicationUser
{
private readonly ApplicationDbContext _context;
private readonly HttpClient _client;
public ApplicationUsersControllerGetApplicationUser()
{
var builder = new WebHostBuilder()
.UseEnvironment("Testing")
.UseStartup<Startup>();
[Fact]
public async Task DoesReturnOk_GivenUserExists()
{
// Arrange
var user = new ApplicationUser
{
Id = "123",
Email = "test@test.com"
};