Skip to content

Commit 94a0acc

Browse files
committed
Updated the library to use ASP.NET Core 2.2
1 parent fdc0177 commit 94a0acc

File tree

38 files changed

+315
-65
lines changed

38 files changed

+315
-65
lines changed

MyTested.AspNetCore.Mvc.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTested.AspNetCore.Mvc.Con
231231
EndProject
232232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTested.AspNetCore.Mvc.ViewComponents.Results.Test", "test\MyTested.AspNetCore.Mvc.ViewComponents.Results.Test\MyTested.AspNetCore.Mvc.ViewComponents.Results.Test.csproj", "{32B24AD2-9D35-4A5A-86CE-8C7862DED27E}"
233233
EndProject
234+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.Core.MissingWebSdk", "samples\Configuration\Test.Core.MissingWebSdk\Test.Core.MissingWebSdk.csproj", "{E88A7195-A252-4C51-8255-6442ADD67874}"
235+
EndProject
234236
Global
235237
GlobalSection(SolutionConfigurationPlatforms) = preSolution
236238
Debug|Any CPU = Debug|Any CPU
@@ -645,6 +647,10 @@ Global
645647
{32B24AD2-9D35-4A5A-86CE-8C7862DED27E}.Debug|Any CPU.Build.0 = Debug|Any CPU
646648
{32B24AD2-9D35-4A5A-86CE-8C7862DED27E}.Release|Any CPU.ActiveCfg = Release|Any CPU
647649
{32B24AD2-9D35-4A5A-86CE-8C7862DED27E}.Release|Any CPU.Build.0 = Release|Any CPU
650+
{E88A7195-A252-4C51-8255-6442ADD67874}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
651+
{E88A7195-A252-4C51-8255-6442ADD67874}.Debug|Any CPU.Build.0 = Debug|Any CPU
652+
{E88A7195-A252-4C51-8255-6442ADD67874}.Release|Any CPU.ActiveCfg = Release|Any CPU
653+
{E88A7195-A252-4C51-8255-6442ADD67874}.Release|Any CPU.Build.0 = Release|Any CPU
648654
EndGlobalSection
649655
GlobalSection(SolutionProperties) = preSolution
650656
HideSolutionNode = FALSE
@@ -761,6 +767,7 @@ Global
761767
{03CFC257-39A4-4FFE-8FB5-AB43D055DFE8} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
762768
{4E038FA2-52FA-47CD-8797-6FD6CAE8741E} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
763769
{32B24AD2-9D35-4A5A-86CE-8C7862DED27E} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
770+
{E88A7195-A252-4C51-8255-6442ADD67874} = {7BEC9808-8650-4322-BCC6-1D7D91B53678}
764771
EndGlobalSection
765772
GlobalSection(ExtensibilityGlobals) = postSolution
766773
SolutionGuid = {99A2DEDD-5195-4EE6-A546-B1CA54C5539F}

samples/ApplicationParts/ApplicationParts.Test/ApplicationParts.Test.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66
</PropertyGroup>
77

@@ -15,7 +15,6 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="Microsoft.AspNetCore.App" />
1918
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
2019
<PackageReference Include="NUnit" Version="3.12.0" />
2120
<PackageReference Include="NUnit3TestAdapter" Version="3.14.0" />

samples/Autofac/Autofac.NoContainerBuilder.Web/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
2828

2929
services.AddSingleton<IDateTimeService>(_ => new DateTimeService());
3030

31-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
31+
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
3232

3333
var builder = this.GetContainerBuilder(services);
3434

samples/Autofac/Autofac.Web/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void ConfigureServices(IServiceCollection services)
2626

2727
services.AddSingleton<IDateTimeService>(_ => new DateTimeService());
2828

29-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
29+
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
3030
}
3131

3232
public void ConfigureContainer(ContainerBuilder builder)

samples/Blog/Blog.Web/Startup.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Blog.Web
22
{
33
using AutoMapper;
4+
using Controllers;
45
using Data;
56
using Data.Models;
67
using Infrastructure;
@@ -9,7 +10,6 @@
910
using Microsoft.AspNetCore.Hosting;
1011
using Microsoft.AspNetCore.Http;
1112
using Microsoft.AspNetCore.Identity;
12-
using Microsoft.AspNetCore.Identity.UI;
1313
using Microsoft.AspNetCore.Mvc;
1414
using Microsoft.EntityFrameworkCore;
1515
using Microsoft.Extensions.Configuration;
@@ -51,17 +51,18 @@ public void ConfigureServices(IServiceCollection services)
5151
options.Password.RequireUppercase = false;
5252
});
5353

54-
services.AddAutoMapper(typeof(IArticleService).Assembly);
54+
services.AddAutoMapper(
55+
typeof(IArticleService).Assembly,
56+
typeof(HomeController).Assembly);
5557

56-
services.AddTransient<IArticleService, ArticleService>();
57-
services.AddTransient<IDateTimeProvider, DateTimeProvider>();
58+
services
59+
.AddTransient<IArticleService, ArticleService>()
60+
.AddTransient<IDateTimeProvider, DateTimeProvider>();
5861

5962
services
60-
.AddMvc(options =>
61-
{
62-
options.AddAutoValidateAntiforgeryToken();
63-
})
64-
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
63+
.AddMvc(options => options
64+
.AddAutoValidateAntiforgeryToken())
65+
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
6566
}
6667

6768
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace Test.Core.MissingWebSdk
2+
{
3+
using System;
4+
using MyTested.AspNetCore.Mvc;
5+
using WebApplication.Controllers;
6+
using Xunit;
7+
8+
public class HomeControllerTest
9+
{
10+
[Fact]
11+
public void MissingSdkShouldThrowCorrectException()
12+
{
13+
var exception = Assert.Throws<InvalidOperationException>(() =>
14+
{
15+
MyController<HomeController>
16+
.Instance()
17+
.Calling(c => c.Index())
18+
.ShouldReturn()
19+
.View();
20+
});
21+
22+
Assert.Equal("HomeController is not recognized as a valid controller type. Classes decorated with 'NonControllerAttribute' are not considered as passable controllers. Additionally, make sure the SDK is set to 'Microsoft.NET.Sdk.Web' in your test project's '.csproj' file in order to enable proper controller discovery. If your type is still not recognized, you may manually add it in the application part manager by using the 'AddMvc().PartManager.ApplicationParts.Add(applicationPart))' method.", exception.Message);
23+
}
24+
}
25+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using System.Runtime.InteropServices;
2+
using Xunit;
3+
4+
[assembly: ComVisible(false)]
5+
6+
[assembly: CollectionBehavior(MaxParallelThreads = -1)]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
6+
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.AspNetCore.App" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
13+
<PackageReference Include="xunit" Version="2.4.1" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\..\..\src\MyTested.AspNetCore.Mvc\MyTested.AspNetCore.Mvc.csproj" />
22+
<ProjectReference Include="..\WebApplication.Core\WebApplication.Core.csproj" />
23+
</ItemGroup>
24+
25+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Test.Core.MissingWebSdk
2+
{
3+
using Microsoft.Extensions.Configuration;
4+
using WebApplication.Core;
5+
6+
public class TestStartup : Startup
7+
{
8+
public TestStartup(IConfiguration configuration)
9+
: base(configuration)
10+
{
11+
}
12+
}
13+
}

samples/Configuration/WebApplication.Core/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void ConfigureServices(IServiceCollection services)
2626
services.AddTransient<IDataService, DataService>();
2727
services.AddTransient<IDateTimeService, DateTimeService>();
2828

29-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
29+
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
3030
}
3131

3232
public void Configure(IApplicationBuilder app, IHostingEnvironment env)

0 commit comments

Comments
 (0)