Skip to content

Commit

Permalink
Update samples and test projects to target netcoreapp3.1, update NuGe…
Browse files Browse the repository at this point in the history
…t packages and update samples project to use newer client side libraries
  • Loading branch information
shaynevanasperen committed Feb 26, 2020
1 parent f253056 commit a3a59a4
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 119 deletions.
16 changes: 6 additions & 10 deletions samples/Samples.Tests/Samples.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<NoWarn>$(NoWarn);CA2007;CA1307</NoWarn>
</PropertyGroup>

Expand All @@ -10,18 +10,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.7.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="FluentAssertions" Version="5.10.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Serilog" Version="2.8.0" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Specify" Version="2.4.0" />
<PackageReference Include="TestStack.BDDfy.Xunit" Version="1.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 0 additions & 4 deletions samples/Samples/.bowerrc

This file was deleted.

6 changes: 4 additions & 2 deletions samples/Samples/Domain/JsonPlaceHolderHttpClient.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Samples.Domain
{
Expand All @@ -19,7 +20,8 @@ public JsonPlaceHolderHttpClient(HttpClient httpClient)
public async Task<T> GetAsync<T>(string requestUri, CancellationToken cancellationToken = default)
{
var response = await _httpClient.GetAsync(requestUri, cancellationToken);
return await response.Content.ReadAsAsync<T>(cancellationToken);
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(content);
}

public Task<HttpResponseMessage> PostAsync<T>(string requestUri, T data, CancellationToken cancellationToken = default) =>
Expand Down
11 changes: 5 additions & 6 deletions samples/Samples/Samples.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<NoWarn>$(NoWarn);CA2007;CA1819;CA1054;CA2234</NoWarn>
</PropertyGroup>

Expand All @@ -10,10 +10,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BuildBundlerMinifier" Version="2.9.406" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.7.1" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="2.2.0" />
<PackageReference Include="BuildBundlerMinifier" Version="3.2.435" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.13.1" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 12 additions & 7 deletions samples/Samples/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Polly;
Expand All @@ -20,7 +21,7 @@ namespace Samples
{
public class Startup
{
public Startup(IHostingEnvironment environment, IConfiguration configuration)
public Startup(IWebHostEnvironment environment, IConfiguration configuration)
{
Environment = environment;
Configuration = configuration;
Expand All @@ -29,13 +30,13 @@ public Startup(IHostingEnvironment environment, IConfiguration configuration)

void InitializeAlbums()
{
using (var streamReader = new StreamReader(Environment.ContentRootFileProvider.GetFileInfo(Album.AllAlbumsFilename).CreateReadStream()))
File.WriteAllText(Path.Combine(Environment.WebRootPath, Album.AllAlbumsFilename), streamReader.ReadToEnd());
using var streamReader = new StreamReader(Environment.ContentRootFileProvider.GetFileInfo(Album.AllAlbumsFilename).CreateReadStream());
File.WriteAllText(Path.Combine(Environment.WebRootPath, Album.AllAlbumsFilename), streamReader.ReadToEnd());
}

public IConfiguration Configuration { get; }

protected IHostingEnvironment Environment { get; }
protected IWebHostEnvironment Environment { get; }

public void ConfigureServices(IServiceCollection services)
{
Expand Down Expand Up @@ -80,8 +81,8 @@ public void ConfigureServices(IServiceCollection services)
// Here we specify how cache keys are created. This is optional as there is already a default built-in method,
// but consumers may want to use their own method instead.
CachedQuery.UseKeyCreator((prefix, varyBy) => $"{prefix}.{JsonConvert.SerializeObject(varyBy)}");
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

services.AddControllersWithViews().SetCompatibilityVersion(CompatibilityVersion.Latest);
}

public void Configure(IApplicationBuilder app)
Expand All @@ -100,7 +101,11 @@ public void Configure(IApplicationBuilder app)
app.UseStaticFiles();
app.UseCookiePolicy();

app.UseMvc();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
6 changes: 3 additions & 3 deletions samples/Samples/Views/Posts/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model IEnumerable<Post>
@model IEnumerable<Post>

@{
ViewData["Title"] = "Posts";
Expand All @@ -17,11 +17,11 @@
@foreach (var post in Model)
{
<tr>
<td>@Html.ActionLink(post.Id.ToString(), "Index", new { post.Id })</td>
<td><a asp-area="" asp-controller="Posts" asp-action="Index", asp-route-id="@post.Id">@post.Id</a></td>
<td>@post.Title</td>
<td>@post.Body</td>
<td>@post.UserId</td>
</tr>
}
</tbody>
</table>
</table>
75 changes: 36 additions & 39 deletions samples/Samples/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
<!DOCTYPE html>
<html>
<head>
Expand All @@ -7,63 +7,60 @@
<title>@ViewData["Title"] - Samples</title>

<environment names="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="~/lib/twitter-bootstrap/css/bootstrap.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
</environment>
<environment names="Staging,Production">
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha256-L/W5Wfqfa0sdBNIKN9cG6QA5F2qx4qICmU2VgLruv9Y="
crossorigin="anonymous"
asp-fallback-href="~/lib/twitter-bootstrap/css/bootstrap.min.css"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
@Html.Raw(JavaScriptSnippet.FullScript)
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a asp-area="" asp-controller="Home" asp-action="Index" class="navbar-brand">Samples</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a asp-area="" asp-controller="Home" asp-action="Index">Home</a></li>
<li><a asp-controller="Users" asp-action="Index" asp-route-id="">Users</a></li>
<li><a asp-controller="Posts" asp-action="Index" asp-route-id="">Posts</a></li>
</ul>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item"><a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a></li>
<li class="nav-item"><a class="nav-link text-dark" asp-controller="Users" asp-action="Index" asp-route-id="">Users</a></li>
<li class="nav-item"><a class="nav-link text-dark" asp-controller="Posts" asp-action="Index" asp-route-id="">Posts</a></li>
</ul>
</div>
</div>
</div>
</nav>
</nav>
</header>

<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>&copy; 2018 - Samples</p>
</footer>
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2020 - Samples
</div>
</footer>


<environment names="Development">
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
<script src="~/lib/twitter-bootstrap/js/bootstrap.bundle.js"></script>
</environment>
<environment names="Staging,Production">
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
asp-fallback-test="window.jQuery"
crossorigin="anonymous"
integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.bundle.min.js"
integrity="sha256-OUFW7hFO0/r5aEGTQOz9F/aXQOt+TwqI1Z4fbVvww04="
crossorigin="anonymous"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa">
asp-fallback-src="~/lib/twitter-bootstrap/js/bootstrap.bundle.min.js"
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal">
</script>
</environment>

Expand Down
4 changes: 2 additions & 2 deletions samples/Samples/Views/Users/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model IEnumerable<User>
@model IEnumerable<User>

@{
ViewData["Title"] = "Users";
Expand All @@ -21,7 +21,7 @@
@foreach (var user in Model)
{
<tr>
<td>@Html.ActionLink(user.Id.ToString(), "Index", new { user.Id })</td>
<td><a asp-area="" asp-controller="Users" asp-action="Index", asp-route-id="@user.Id">@user.Id</a></td>
<td>@user.Username</td>
<td>@user.Name</td>
<td>@user.Email</td>
Expand Down
11 changes: 0 additions & 11 deletions samples/Samples/bower.json

This file was deleted.

10 changes: 10 additions & 0 deletions samples/Samples/libman.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": [
{
"library": "[email protected]",
"destination": "wwwroot/lib/twitter-bootstrap/"
}
]
}
Loading

0 comments on commit a3a59a4

Please sign in to comment.