Unverified Commit 88e46889 authored by Steve Smith's avatar Steve Smith Committed by GitHub

Merge pull request #14 from sdepouw/upgrade-to-.NETCore-2.1

Upgrade to .net core 2.1
parents 66342963 b7220af0
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Update="NETStandard.Library" Version="2.0.1" /> <PackageReference Update="NETStandard.Library" Version="2.0.3" />
</ItemGroup> </ItemGroup>
</Project> </Project>
using CleanArchitecture.Core.Entities;
using CleanArchitecture.Core.Interfaces;
using System.Linq;
namespace CleanArchitecture.Core
{
public static class DatabasePopulator
{
public static int PopulateDatabase(IRepository<ToDoItem> todoRepository)
{
if (todoRepository.List().Any()) return 0;
todoRepository.Add(new ToDoItem()
{
Title = "Get Sample Working",
Description = "Try to get the sample to build."
});
todoRepository.Add(new ToDoItem()
{
Title = "Review Solution",
Description = "Review the different projects in the solution and how they relate to one another."
});
todoRepository.Add(new ToDoItem()
{
Title = "Run and Review Tests",
Description = "Make sure all the tests run and review what they are doing."
});
return todoRepository.List().Count;
}
}
}
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion> <TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>CleanArchitecture.Infrastructure</AssemblyName> <AssemblyName>CleanArchitecture.Infrastructure</AssemblyName>
<PackageId>CleanArchitecture.Infrastructure</PackageId> <PackageId>CleanArchitecture.Infrastructure</PackageId>
</PropertyGroup> </PropertyGroup>
...@@ -11,15 +10,9 @@ ...@@ -11,15 +10,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" /> <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" PrivateAssets="All" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" PrivateAssets="All" />
<PackageReference Include="StructureMap.Microsoft.DependencyInjection" Version="1.4.0" /> <PackageReference Include="StructureMap.Microsoft.DependencyInjection" Version="1.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext> <PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>CleanArchitecture.Web</AssemblyName> <AssemblyName>CleanArchitecture.Web</AssemblyName>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<PackageId>CleanArchitecture.Web</PackageId> <PackageId>CleanArchitecture.Web</PackageId>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Content Update="wwwroot\**\*;Views\**\*;Areas\**\Views;appsettings.json;web.config"> <Content Update="wwwroot\**\*;Views\**\*;Areas\**\Views;appsettings.json;web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
...@@ -23,18 +19,15 @@ ...@@ -23,18 +19,15 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Dapper" Version="1.50.4" /> <PackageReference Include="Dapper" Version="1.50.5" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" /> <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" PrivateAssets="All" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" PrivateAssets="All" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" PrivateAssets="All" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="2.2.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="2.4.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup> </ItemGroup>
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish"> <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
...@@ -46,4 +39,13 @@ ...@@ -46,4 +39,13 @@
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.301" /> <DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.301" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Update="Pages\_ViewImports.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Pages\_ViewStart.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
</ItemGroup>
</Project> </Project>
using CleanArchitecture.Core.Entities; using CleanArchitecture.Core;
using CleanArchitecture.Core.Entities;
using CleanArchitecture.Core.Interfaces; using CleanArchitecture.Core.Interfaces;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Linq;
namespace CleanArchitecture.Web.Controllers namespace CleanArchitecture.Web.Controllers
{ {
...@@ -22,29 +22,8 @@ namespace CleanArchitecture.Web.Controllers ...@@ -22,29 +22,8 @@ namespace CleanArchitecture.Web.Controllers
public IActionResult Populate() public IActionResult Populate()
{ {
int recordsAdded = PopulateDatabase(); int recordsAdded = DatabasePopulator.PopulateDatabase(_todoRepository);
return Ok(recordsAdded); return Ok(recordsAdded);
} }
public int PopulateDatabase()
{
if (_todoRepository.List().Any()) return 0;
_todoRepository.Add(new ToDoItem()
{
Title = "Get Sample Working",
Description = "Try to get the sample to build."
});
_todoRepository.Add(new ToDoItem()
{
Title = "Review Solution",
Description = "Review the different projects in the solution and how they relate to one another."
});
_todoRepository.Add(new ToDoItem()
{
Title = "Run and Review Tests",
Description = "Make sure all the tests run and review what they are doing."
});
return _todoRepository.List().Count;
}
} }
} }
@page
@model CleanArchitecture.Web.Pages.ToDoRazorPage.IndexModel
<h2>To Do Items (Razor Page)</h2>
<ul>
@foreach (var item in Model.ToDoItems)
{
<li>@item.Title<br />@item.Description</li>
}
</ul>
using CleanArchitecture.Core.Entities;
using CleanArchitecture.Core.Interfaces;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.Generic;
namespace CleanArchitecture.Web.Pages.ToDoRazorPage
{
public class IndexModel : PageModel
{
private readonly IRepository<ToDoItem> _todoRepository;
public List<ToDoItem> ToDoItems { get; set; }
public IndexModel(IRepository<ToDoItem> todoRepository)
{
_todoRepository = todoRepository;
}
public void OnGet()
{
ToDoItems = _todoRepository.List();
}
}
}
@page
@model CleanArchitecture.Web.Pages.ToDoRazorPage.PopulateModel
<h3>Records Added: @Model.RecordsAdded</h3>
<p>
<a asp-page="Index">Check them out!</a>
</p>
using CleanArchitecture.Core;
using CleanArchitecture.Core.Entities;
using CleanArchitecture.Core.Interfaces;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace CleanArchitecture.Web.Pages.ToDoRazorPage
{
public class PopulateModel : PageModel
{
private readonly IRepository<ToDoItem> _todoRepository;
public PopulateModel(IRepository<ToDoItem> todoRepository)
{
_todoRepository = todoRepository;
}
public int RecordsAdded { get; set; }
public void OnGet()
{
RecordsAdded = DatabasePopulator.PopulateDatabase(_todoRepository);
}
}
}
@using CleanArchitecture.Web
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore;
using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting;
namespace CleanArchitecture.Web namespace CleanArchitecture.Web
{ {
...@@ -7,12 +7,11 @@ namespace CleanArchitecture.Web ...@@ -7,12 +7,11 @@ namespace CleanArchitecture.Web
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
BuildWebHost(args).Run(); CreateWebHostBuilder(args).Build().Run();
} }
public static IWebHost BuildWebHost(string[] args) => public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args) WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>() .UseStartup<Startup>();
.Build();
} }
} }
using System; using CleanArchitecture.Core.Interfaces;
using CleanArchitecture.Core.Interfaces;
using CleanArchitecture.Core.SharedKernel; using CleanArchitecture.Core.SharedKernel;
using CleanArchitecture.Infrastructure.Data; using CleanArchitecture.Infrastructure.Data;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using StructureMap; using StructureMap;
using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.Swagger;
using System;
namespace CleanArchitecture.Web namespace CleanArchitecture.Web
{ {
...@@ -24,6 +26,12 @@ namespace CleanArchitecture.Web ...@@ -24,6 +26,12 @@ namespace CleanArchitecture.Web
public IServiceProvider ConfigureServices(IServiceCollection services) public IServiceProvider ConfigureServices(IServiceCollection services)
{ {
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
// TODO: Add DbContext and IOC // TODO: Add DbContext and IOC
string dbName = Guid.NewGuid().ToString(); string dbName = Guid.NewGuid().ToString();
services.AddDbContext<AppDbContext>(options => services.AddDbContext<AppDbContext>(options =>
...@@ -31,7 +39,8 @@ namespace CleanArchitecture.Web ...@@ -31,7 +39,8 @@ namespace CleanArchitecture.Web
//options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); //options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc() services.AddMvc()
.AddControllersAsServices(); .AddControllersAsServices()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSwaggerGen(c => services.AddSwaggerGen(c =>
{ {
...@@ -50,7 +59,7 @@ namespace CleanArchitecture.Web ...@@ -50,7 +59,7 @@ namespace CleanArchitecture.Web
_.WithDefaultConventions(); _.WithDefaultConventions();
_.ConnectImplementationsToTypesClosing(typeof(IHandle<>)); _.ConnectImplementationsToTypesClosing(typeof(IHandle<>));
}); });
// TODO: Add Registry Classes to eliminate reference to Infrastructure // TODO: Add Registry Classes to eliminate reference to Infrastructure
// TODO: Move to Infrastucture Registry // TODO: Move to Infrastucture Registry
...@@ -80,14 +89,16 @@ namespace CleanArchitecture.Web ...@@ -80,14 +89,16 @@ namespace CleanArchitecture.Web
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseBrowserLink();
} }
else else
{ {
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
app.UseHsts();
} }
app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseCookiePolicy();
// Enable middleware to serve generated Swagger as a JSON endpoint. // Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger(); app.UseSwagger();
......
...@@ -4,12 +4,17 @@ ...@@ -4,12 +4,17 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<h2>To Do Items</h2> <h2>To Do Items (MVC)</h2>
<ul> <ul>
<li><a asp-area="" asp-controller="ToDo" asp-action="Populate">Load Sample To Do Items</a></li> <li><a asp-area="" asp-controller="ToDo" asp-action="Populate">Load Sample To Do Items</a></li>
<li><a asp-area="" asp-controller="ToDo" asp-action="Index">List To Do Items</a></li> <li><a asp-area="" asp-controller="ToDo" asp-action="Index">List To Do Items</a></li>
<li><a href="/swagger">API Documentation (Swagger)</a></li> <li><a href="/swagger">API Documentation (Swagger)</a></li>
</ul> </ul>
<h2>To Do Items (Razor Pages)</h2>
<ul>
<li><a asp-page="/ToDoRazorPage/Populate">Load Sample To Do Items</a></li>
<li><a asp-page="/ToDoRazorPage/Index">List To Do Items</a></li>
</ul>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<h2>About the Author</h2> <h2>About the Author</h2>
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
ViewData["Title"] = "ToDo List"; ViewData["Title"] = "ToDo List";
} }
@model IEnumerable<CleanArchitecture.Core.Entities.ToDoItem> @model IEnumerable<CleanArchitecture.Core.Entities.ToDoItem>
<h2>To Do Items</h2> <h2>To Do Items (MVC View)</h2>
<ul> <ul>
@foreach (var item in Model) @foreach (var item in Model)
{ {
<li>@item.Title<br/>@item.Description</li> <li>@item.Title<br/>@item.Description</li>
} }
</ul> </ul>
...@@ -2,14 +2,10 @@ ...@@ -2,14 +2,10 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext> <PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<None Update="xunit.runner.json"> <None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
...@@ -31,11 +27,11 @@ ...@@ -31,11 +27,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.2" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" /> <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.1" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="Moq" Version="4.8.2" /> <PackageReference Include="Moq" Version="4.8.2" />
<PackageReference Include="NETStandard.Library" Version="2.0.1" /> <PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="xunit" Version="2.3.1" /> <PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.console" Version="2.3.1" /> <PackageReference Include="xunit.runner.console" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
......
...@@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Mvc.Controllers; ...@@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.ViewComponents; using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.AspNetCore.TestHost; using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.PlatformAbstractions;
using System; using System;
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
...@@ -67,7 +66,8 @@ namespace CleanArchitecture.Tests.Integration.Web ...@@ -67,7 +66,8 @@ namespace CleanArchitecture.Tests.Integration.Web
var projectName = startupAssembly.GetName().Name; var projectName = startupAssembly.GetName().Name;
// Get currently executing test project path // Get currently executing test project path
var applicationBasePath = PlatformServices.Default.Application.ApplicationBasePath; // AppContext.BaseDirectory or AppDomain.CurrentDomain.BaseDirectory contain the BaseDirectory.
var applicationBasePath = AppContext.BaseDirectory;
// Find the folder which contains the solution file. We then use this information to find the target // Find the folder which contains the solution file. We then use this information to find the target
// project which we want to test. // project which we want to test.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment