Skip to content

Commit 02f1f92

Browse files
committed
Multitarget netcoreapp2.0 and netcoreapp3.0
1 parent 69724db commit 02f1f92

11 files changed

+200
-73
lines changed

samples/FluentAssertions.AspNetCore.Mvc.Sample.Tests/ApiController_Tests.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Net.Mime;
4-
using System.Security.Claims;
5-
using FluentAssertions.AspNetCore.Mvc.Sample.Controllers;
1+
using FluentAssertions.AspNetCore.Mvc.Sample.Controllers;
62
using Microsoft.AspNetCore.Authentication;
73
using Microsoft.AspNetCore.Mvc.ModelBinding;
8-
using Microsoft.AspNetCore.Routing;
9-
using Microsoft.EntityFrameworkCore.ValueGeneration.Internal;
104
using Microsoft.Extensions.Primitives;
115
using Microsoft.Net.Http.Headers;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Security.Claims;
129
using Xunit;
1310

1411
namespace FluentAssertions.AspNetCore.Mvc.Sample.Tests

samples/FluentAssertions.AspNetCore.Mvc.Sample.Tests/FluentAssertions.AspNetCore.Mvc.Sample.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFrameworks>netcoreapp2.0;netcoreapp3.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFrameworks>netcoreapp2.0;netcoreapp3.0</TargetFrameworks>
55
</PropertyGroup>
66

7-
<ItemGroup>
7+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
88
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
99
</ItemGroup>
1010

11+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
12+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0" />
13+
</ItemGroup>
14+
1115
</Project>

samples/FluentAssertions.AspNetCore.Mvc.Sample/Startup.cs

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Builder;
1+
using Microsoft.AspNetCore.Builder;
62
using Microsoft.AspNetCore.Hosting;
73
using Microsoft.Extensions.Configuration;
84
using Microsoft.Extensions.DependencyInjection;
@@ -28,24 +24,38 @@ public Startup(IHostingEnvironment env)
2824
public void ConfigureServices(IServiceCollection services)
2925
{
3026
// Add framework services.
31-
services.AddMvc();
27+
services.AddMvc(options =>
28+
{
29+
#if NETCOREAPP3_0
30+
options.EnableEndpointRouting = false;
31+
#endif
32+
});
33+
34+
services.AddLogging(configure =>
35+
{
36+
configure.AddConsole();
37+
configure.AddDebug();
38+
});
3239
}
3340

3441
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
3542
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
3643
{
37-
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
38-
loggerFactory.AddDebug();
39-
4044
if (env.IsDevelopment())
4145
{
4246
app.UseDeveloperExceptionPage();
47+
#if NETCOREAPP2_0
4348
app.UseBrowserLink();
49+
#endif
4450
}
4551
else
4652
{
4753
app.UseExceptionHandler("/Home/Error");
4854
}
55+
#if NETCOREAPP2_0
56+
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
57+
loggerFactory.AddDebug();
58+
#endif
4959

5060
app.UseStaticFiles();
5161

src/FluentAssertions.AspNetCore.Mvc/FluentAssertions.AspNetCore.Mvc.csproj

+35-30
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,43 @@
44
<Description>Fluent Assertions extensions for ASP.NET Core MVC.</Description>
55
<Copyright>Copyright 2018</Copyright>
66
<AssemblyTitle>Fluent Assertions extensions for ASP.NET Core MVC</AssemblyTitle>
7-
<Title>Fluent Assertions for ASP.NET Core MVC</Title>
8-
<VersionPrefix>2.4.0</VersionPrefix>
9-
<Authors>Casey Burns;Kevin Kuszyk</Authors>
10-
<TargetFramework>netstandard2.0</TargetFramework>
11-
<AssemblyName>FluentAssertions.AspNetCore.Mvc</AssemblyName>
12-
<PackageId>FluentAssertions.AspNetCore.Mvc</PackageId>
13-
<PackageTags>TDD;TDD;Fluent;Mvc;AspNetMvc;aspnetcore;aspnetcoremvc</PackageTags>
14-
<PackageReleaseNotes>See https://github.com/fluentassertions/fluentassertions.aspnetcore.mvc/releases </PackageReleaseNotes>
15-
<PackageProjectUrl>https://github.com/fluentassertions/fluentassertions.aspnetcore.mvc</PackageProjectUrl>
16-
<PackageLicenseUrl>https://github.com/fluentassertions/fluentassertions.aspnetcore.mvc/blob/master/license.txt</PackageLicenseUrl>
17-
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
18-
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
19-
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
20-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
21-
</PropertyGroup>
7+
<Title>Fluent Assertions for ASP.NET Core MVC</Title>
8+
<VersionPrefix>2.4.0</VersionPrefix>
9+
<Authors>Casey Burns;Kevin Kuszyk</Authors>
10+
<TargetFrameworks>netstandard2.0;netcoreapp3.0</TargetFrameworks>
11+
<AssemblyName>FluentAssertions.AspNetCore.Mvc</AssemblyName>
12+
<PackageId>FluentAssertions.AspNetCore.Mvc</PackageId>
13+
<PackageTags>TDD;TDD;Fluent;Mvc;AspNetMvc;aspnetcore;aspnetcoremvc</PackageTags>
14+
<PackageReleaseNotes>See https://github.com/fluentassertions/fluentassertions.aspnetcore.mvc/releases </PackageReleaseNotes>
15+
<PackageProjectUrl>https://github.com/fluentassertions/fluentassertions.aspnetcore.mvc</PackageProjectUrl>
16+
<PackageLicenseUrl>https://github.com/fluentassertions/fluentassertions.aspnetcore.mvc/blob/master/license.txt</PackageLicenseUrl>
17+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
18+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
19+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
20+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
21+
<OutputType>Library</OutputType>
22+
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\FluentAssertions.AspNetCore.Mvc.xml</DocumentationFile>
23+
</PropertyGroup>
2224

23-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
24-
<OutputPath>bin\Debug\netstandard2.0\</OutputPath>
25-
<DocumentationFile>bin\Debug\netstandard2.0\FluentAssertions.AspNetCore.Mvc.xml</DocumentationFile>
26-
</PropertyGroup>
25+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
26+
<OutputPath>bin\Debug\netstandard2.0\</OutputPath>
27+
</PropertyGroup>
2728

28-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
29-
<DocumentationFile>bin\Release\netstandard2.0\FluentAssertions.AspNetCore.Mvc.xml</DocumentationFile>
30-
</PropertyGroup>
29+
<ItemGroup>
30+
<PackageReference Include="FluentAssertions" Version="5.0.0" />
31+
</ItemGroup>
3132

32-
<ItemGroup>
33-
<PackageReference Include="FluentAssertions" Version="5.0.0" />
34-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
35-
</ItemGroup>
36-
37-
<ItemGroup>
38-
<Compile Update="FailureMessages.Designer.cs">
39-
<DesignTime>True</DesignTime>
33+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
34+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
35+
</ItemGroup>
36+
37+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
38+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
39+
</ItemGroup>
40+
41+
<ItemGroup>
42+
<Compile Update="FailureMessages.Designer.cs">
43+
<DesignTime>True</DesignTime>
4044
<AutoGen>True</AutoGen>
4145
<DependentUpon>FailureMessages.resx</DependentUpon>
4246
</Compile>
@@ -50,3 +54,4 @@
5054
</ItemGroup>
5155

5256
</Project>
57+

src/FluentAssertions.AspNetCore.Mvc/JsonResultAssertions.cs

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using FluentAssertions.Execution;
1+
using FluentAssertions.Execution;
22
using FluentAssertions.Primitives;
33
using Microsoft.AspNetCore.Mvc;
4-
using Newtonsoft.Json;
54
using System;
65
using System.Diagnostics;
76

@@ -31,26 +30,30 @@ public JsonResultAssertions(JsonResult subject) : base(subject)
3130
/// <summary>
3231
/// The <see cref="JsonResult.SerializerSettings"/> on the tested subject.
3332
/// </summary>
34-
public JsonSerializerSettings SerializerSettings => JsonResultSubject.SerializerSettings;
35-
33+
#if NETCOREAPP3_0
34+
public object SerializerSettings => JsonResultSubject.SerializerSettings;
35+
#else
36+
public Newtonsoft.Json.JsonSerializerSettings SerializerSettings => JsonResultSubject.SerializerSettings;
37+
#endif
38+
3639

3740
/// <summary>
3841
/// The <see cref="JsonResult.Value"/> on the tested subject.
39-
/// </summary>
40-
public object Value => JsonResultSubject.Value;
41-
42-
#endregion
43-
44-
#region Private Properties
45-
46-
private JsonResult JsonResultSubject => (JsonResult)Subject;
47-
48-
#endregion Private Properties
49-
50-
#region Public Methods
51-
52-
/// <summary>
53-
/// Asserts that the content type is the expected content type.
42+
/// </summary>
43+
public object Value => JsonResultSubject.Value;
44+
45+
#endregion
46+
47+
#region Private Properties
48+
49+
private JsonResult JsonResultSubject => (JsonResult)Subject;
50+
51+
#endregion Private Properties
52+
53+
#region Public Methods
54+
55+
/// <summary>
56+
/// Asserts that the content type is the expected content type.
5457
/// </summary>
5558
/// <param name="expectedContentType">The expected content type.</param>
5659
/// <param name="reason">
@@ -118,6 +121,6 @@ public TValue ValueAs<TValue>()
118121

119122
return (TValue)value;
120123
}
121-
#endregion
124+
#endregion
122125
}
123126
}

tests/FluentAssertions.AspNetCore.Mvc.Tests/ChallengeResultAssertions_Tests.cs

+29-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void WithAuthenticationProperties_GivenUnexpected_ShouldFail()
3030
var actualAuthenticationProperties = new AuthenticationProperties();
3131
var expectedAuthenticationProperties = new AuthenticationProperties();
3232
ActionResult result = new ChallengeResult(actualAuthenticationProperties);
33+
#if NETCOREAPP3_0
3334
var failureMessage = @"Expected ChallengeResult.AuthenticationProperties to be
3435
3536
Microsoft.AspNetCore.Authentication.AuthenticationProperties
@@ -39,6 +40,7 @@ public void WithAuthenticationProperties_GivenUnexpected_ShouldFail()
3940
IsPersistent = False
4041
IssuedUtc = <null>
4142
Items = {empty}
43+
Parameters = {empty}
4244
RedirectUri = <null>
4345
} because it is 10 but found
4446
@@ -49,8 +51,32 @@ public void WithAuthenticationProperties_GivenUnexpected_ShouldFail()
4951
IsPersistent = False
5052
IssuedUtc = <null>
5153
Items = {empty}
54+
Parameters = {empty}
5255
RedirectUri = <null>
5356
}.";
57+
#else
58+
var failureMessage = @"Expected ChallengeResult.AuthenticationProperties to be
59+
60+
Microsoft.AspNetCore.Authentication.AuthenticationProperties
61+
{
62+
AllowRefresh = <null>
63+
ExpiresUtc = <null>
64+
IsPersistent = False
65+
IssuedUtc = <null>
66+
Items = {empty}
67+
RedirectUri = <null>
68+
} because it is 10 but found
69+
70+
Microsoft.AspNetCore.Authentication.AuthenticationProperties
71+
{
72+
AllowRefresh = <null>
73+
ExpiresUtc = <null>
74+
IsPersistent = False
75+
IssuedUtc = <null>
76+
Items = {empty}
77+
RedirectUri = <null>
78+
}.";
79+
#endif
5480

5581
Action a = () => result.Should().BeChallengeResult().WithAuthenticationProperties(expectedAuthenticationProperties, Reason, ReasonArgs);
5682

@@ -336,8 +362,8 @@ public void WithAuthenticationSchemes_GivenExpected_ShouldPass()
336362
[Fact]
337363
public void WithAuthenticationSchemes_GivenUnexpected_ShouldFail()
338364
{
339-
var actualAuthenticationSchemes = new List<string>() { "one", "two", "three"};
340-
var expectedAuthenticationSchemes = new List<string> { "three", "four", "five"};
365+
var actualAuthenticationSchemes = new List<string>() { "one", "two", "three" };
366+
var expectedAuthenticationSchemes = new List<string> { "three", "four", "five" };
341367
ActionResult result = new ChallengeResult(actualAuthenticationSchemes);
342368
var failureMessage = string.Format(FailureMessages.CommonListsNotIdentical, "ChallengeResult.AuthenticationSchemes");
343369

@@ -350,7 +376,7 @@ public void WithAuthenticationSchemes_GivenUnexpected_ShouldFail()
350376
public void ContainsScheme_GivenExpected_ShouldPass()
351377
{
352378
const string testScheme = "testScheme";
353-
var actualSchemes = new List<string> {testScheme};
379+
var actualSchemes = new List<string> { testScheme };
354380
ActionResult result = new ChallengeResult(actualSchemes);
355381

356382
result.Should().BeChallengeResult().ContainsScheme(testScheme);

tests/FluentAssertions.AspNetCore.Mvc.Tests/FluentAssertions.AspNetCore.Mvc.Tests.csproj

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFrameworks>netcoreapp2.0;netcoreapp3.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
@@ -15,6 +15,10 @@
1515
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
1616
</ItemGroup>
1717

18+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
19+
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
20+
</ItemGroup>
21+
1822
<ItemGroup>
1923
<ProjectReference Include="..\..\src\FluentAssertions.AspNetCore.Mvc\FluentAssertions.AspNetCore.Mvc.csproj" />
2024
</ItemGroup>

tests/FluentAssertions.AspNetCore.Mvc.Tests/ForbidResultAssertions_Tests.cs

+26
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void WithAuthenticationProperties_GivenUnexpected_ShouldFail()
3030
var actualAuthenticationProperties = new AuthenticationProperties();
3131
var expectedAuthenticationProperties = new AuthenticationProperties();
3232
ActionResult result = new ForbidResult(actualAuthenticationProperties);
33+
#if NETCOREAPP3_0
3334
var failureMessage = @"Expected ForbidResult.AuthenticationProperties to be
3435
3536
Microsoft.AspNetCore.Authentication.AuthenticationProperties
@@ -39,6 +40,7 @@ public void WithAuthenticationProperties_GivenUnexpected_ShouldFail()
3940
IsPersistent = False
4041
IssuedUtc = <null>
4142
Items = {empty}
43+
Parameters = {empty}
4244
RedirectUri = <null>
4345
} because it is 10 but found
4446
@@ -49,8 +51,32 @@ public void WithAuthenticationProperties_GivenUnexpected_ShouldFail()
4951
IsPersistent = False
5052
IssuedUtc = <null>
5153
Items = {empty}
54+
Parameters = {empty}
5255
RedirectUri = <null>
5356
}.";
57+
#else
58+
var failureMessage = @"Expected ForbidResult.AuthenticationProperties to be
59+
60+
Microsoft.AspNetCore.Authentication.AuthenticationProperties
61+
{
62+
AllowRefresh = <null>
63+
ExpiresUtc = <null>
64+
IsPersistent = False
65+
IssuedUtc = <null>
66+
Items = {empty}
67+
RedirectUri = <null>
68+
} because it is 10 but found
69+
70+
Microsoft.AspNetCore.Authentication.AuthenticationProperties
71+
{
72+
AllowRefresh = <null>
73+
ExpiresUtc = <null>
74+
IsPersistent = False
75+
IssuedUtc = <null>
76+
Items = {empty}
77+
RedirectUri = <null>
78+
}.";
79+
#endif
5480

5581
Action a = () => result.Should().BeForbidResult().WithAuthenticationProperties(expectedAuthenticationProperties, Reason, ReasonArgs);
5682

0 commit comments

Comments
 (0)