Skip to content

Commit 91ae098

Browse files
authored
Merge pull request #17 from faddiv/TargetNetcoreapp3_0
Target netcoreapp2.1 and netcoreapp3.0
2 parents f818f7f + 2cdcb13 commit 91ae098

File tree

51 files changed

+698
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+698
-172
lines changed

.gitattributes

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto eol=crlf
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
*.cs text diff=csharp
14+
15+
###############################################################################
16+
# diff behavior for common document formats
17+
#
18+
# Convert binary document formats to text before diffing them. This feature
19+
# is only available from the command line. Turn it on by uncommenting the
20+
# entries below.
21+
###############################################################################
22+
*.doc diff=astextplain
23+
*.DOC diff=astextplain
24+
*.docx diff=astextplain
25+
*.DOCX diff=astextplain
26+
*.dot diff=astextplain
27+
*.DOT diff=astextplain
28+
*.pdf diff=astextplain
29+
*.PDF diff=astextplain
30+
*.rtf diff=astextplain
31+
*.RTF diff=astextplain

FluentAssertions.AspNetCore.Mvc.sln

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{A4C33565
1616
EndProject
1717
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentAssertions.AspNetCore.Mvc", "src\FluentAssertions.AspNetCore.Mvc\FluentAssertions.AspNetCore.Mvc.csproj", "{EA71D220-089E-4CB1-B187-D9BB4DFD8624}"
1818
EndProject
19+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentAssertions.AspNetCore.Mvc.Ref", "src\FluentAssertions.AspNetCore.Mvc.Ref\FluentAssertions.AspNetCore.Mvc.Ref.csproj", "{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}"
20+
EndProject
1921
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentAssertions.AspNetCore.Mvc.Tests", "tests\FluentAssertions.AspNetCore.Mvc.Tests\FluentAssertions.AspNetCore.Mvc.Tests.csproj", "{A4962D4A-A99A-4F96-8F76-C5A2F1D06577}"
2022
EndProject
2123
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentAssertions.AspNetCore.Mvc.Sample.Tests", "samples\FluentAssertions.AspNetCore.Mvc.Sample.Tests\FluentAssertions.AspNetCore.Mvc.Sample.Tests.csproj", "{BCFB2639-D0CC-4E81-B431-8CB37F66480F}"
@@ -44,6 +46,18 @@ Global
4446
{EA71D220-089E-4CB1-B187-D9BB4DFD8624}.Release|Mixed Platforms.Build.0 = Release|Any CPU
4547
{EA71D220-089E-4CB1-B187-D9BB4DFD8624}.Release|x86.ActiveCfg = Release|Any CPU
4648
{EA71D220-089E-4CB1-B187-D9BB4DFD8624}.Release|x86.Build.0 = Release|Any CPU
49+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
52+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
53+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|x86.ActiveCfg = Debug|Any CPU
54+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|x86.Build.0 = Debug|Any CPU
55+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
58+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
59+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|x86.ActiveCfg = Release|Any CPU
60+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|x86.Build.0 = Release|Any CPU
4761
{A4962D4A-A99A-4F96-8F76-C5A2F1D06577}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4862
{A4962D4A-A99A-4F96-8F76-C5A2F1D06577}.Debug|Any CPU.Build.0 = Debug|Any CPU
4963
{A4962D4A-A99A-4F96-8F76-C5A2F1D06577}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -86,6 +100,7 @@ Global
86100
EndGlobalSection
87101
GlobalSection(NestedProjects) = preSolution
88102
{EA71D220-089E-4CB1-B187-D9BB4DFD8624} = {89B09C65-4F1E-4B5A-AD58-E244113F2C02}
103+
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF} = {89B09C65-4F1E-4B5A-AD58-E244113F2C02}
89104
{A4962D4A-A99A-4F96-8F76-C5A2F1D06577} = {A4C33565-1E6E-4AE7-8F02-1911DBA00263}
90105
{BCFB2639-D0CC-4E81-B431-8CB37F66480F} = {4E91D524-3DC0-4E08-82FE-6FDAEB89212B}
91106
{263F58EE-CF19-4974-AEBB-2A0E6C3F9054} = {4E91D524-3DC0-4E08-82FE-6FDAEB89212B}

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version: '{build}'
2-
image: Visual Studio 2017
2+
image: Visual Studio 2019
33
configuration: Release
44

55
before_build:

global.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"msbuild-sdks": {
3+
"MSBuild.Sdk.Extras": "2.0.54"
4+
}
5+
}

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.1;netcoreapp3.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

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

+31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using FluentAssertions.AspNetCore.Mvc.Sample.Controllers;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System;
24
using Xunit;
35

46
namespace FluentAssertions.AspNetCore.Mvc.Sample.Tests
@@ -13,5 +15,34 @@ public void List_ShouldReturnView()
1315
.BeViewResult()
1416
.WithViewName("Index");
1517
}
18+
19+
[Fact]
20+
public void GetActionResultOfT_OnFalse_Returns_Data()
21+
{
22+
var controller = new ProductController();
23+
var model = new Models.ProductViewModel { Id = 1, Name = "Text" };
24+
var returnError = false;
25+
26+
var result = controller.GetActionResultOfT(model, returnError);
27+
28+
result.Should().BeConvertibleTo<ObjectResult>()
29+
.And.Value.Should().BeSameAs(model);
30+
}
31+
32+
[Fact]
33+
public void GetActionResultOfT_OnTrue_Returns_BadRequest()
34+
{
35+
var controller = new ProductController();
36+
var model = new Models.ProductViewModel { Id = 1, Name = "Text" };
37+
var returnError = true;
38+
39+
var result = controller.GetActionResultOfT(model, returnError);
40+
41+
result.Should().BeConvertibleTo<BadRequestObjectResult>()
42+
.Which.Value.Should().BeSameAs(model);
43+
44+
result.Should().BeConvertibleTo<BadRequestObjectResult>()
45+
.Which.Should().BeBadRequestObjectResult();
46+
}
1647
}
1748
}

samples/FluentAssertions.AspNetCore.Mvc.Sample/Controllers/ProductController.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using FluentAssertions.AspNetCore.Mvc.Sample.Models;
2+
using Microsoft.AspNetCore.Mvc;
23

34
namespace FluentAssertions.AspNetCore.Mvc.Sample.Controllers
45
{
@@ -9,5 +10,18 @@ public IActionResult List()
910
{
1011
return View("Index");
1112
}
13+
14+
#region ActionResult<T>
15+
[HttpGet]
16+
public ActionResult<ProductViewModel> GetActionResultOfT(
17+
ProductViewModel data, bool error)
18+
{
19+
if (error)
20+
{
21+
return BadRequest(data);
22+
}
23+
return data;
24+
}
25+
#endregion
1226
}
1327
}
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.1;netcoreapp3.0</TargetFrameworks>
55
</PropertyGroup>
66

7-
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
7+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
8+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.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_1
4348
app.UseBrowserLink();
49+
#endif
4450
}
4551
else
4652
{
4753
app.UseExceptionHandler("/Home/Error");
4854
}
55+
#if NETCOREAPP2_1
56+
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
57+
loggerFactory.AddDebug();
58+
#endif
4959

5060
app.UseStaticFiles();
5161

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="MSBuild.Sdk.Extras">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;netcoreapp3.0</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="FluentAssertions" Version="5.0.0" />
9+
</ItemGroup>
10+
11+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
12+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0" />
13+
</ItemGroup>
14+
15+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
16+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<Compile Include="..\FluentAssertions.AspNetCore.Mvc\*.cs" Exclude="..\FluentAssertions.AspNetCore.Mvc\obj\*.cs" />
21+
</ItemGroup>
22+
</Project>

src/FluentAssertions.AspNetCore.Mvc/AcceptedAtActionResultAssertions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace FluentAssertions.AspNetCore.Mvc
1313
public class AcceptedAtActionResultAssertions : ObjectAssertions
1414
{
1515
/// <summary>
16-
/// Initializes a new instance of the <see cref="T:AcceptedAtActionResultAssertions" /> class.
16+
/// Initializes a new instance of the <see cref="AcceptedAtActionResultAssertions" /> class.
1717
/// </summary>
1818
public AcceptedAtActionResultAssertions(AcceptedAtActionResult subject) : base(subject) { }
1919

src/FluentAssertions.AspNetCore.Mvc/AcceptedAtRouteResultAssertions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace FluentAssertions.AspNetCore.Mvc
1313
public class AcceptedAtRouteResultAssertions : ObjectAssertions
1414
{
1515
/// <summary>
16-
/// Initializes a new instance of the <see cref="T:AcceptedAtRouteResultAssertions" /> class.
16+
/// Initializes a new instance of the <see cref="AcceptedAtRouteResultAssertions" /> class.
1717
/// </summary>
1818
public AcceptedAtRouteResultAssertions(AcceptedAtRouteResult subject) : base(subject) { }
1919

src/FluentAssertions.AspNetCore.Mvc/AcceptedResultAssertions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class AcceptedResultAssertions : ObjectAssertions
1515
#region Public Constructors
1616

1717
/// <summary>
18-
/// Initializes a new instance of the <see cref="T:AcceptedResultAssertions" /> class.
18+
/// Initializes a new instance of the <see cref="AcceptedResultAssertions" /> class.
1919
/// </summary>
2020
/// <param name="subject">The object to test assertion on</param>
2121
public AcceptedResultAssertions(AcceptedResult subject) : base(subject)

src/FluentAssertions.AspNetCore.Mvc/ActionResultAssertions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ActionResultAssertions : ObjectAssertions
1414
#region Public Constructors
1515

1616
/// <summary>
17-
/// Initializes a new instance of the <see cref="T:ActionResultAssertions" /> class.
17+
/// Initializes a new instance of the <see cref="ActionResultAssertions" /> class.
1818
/// </summary>
1919
public ActionResultAssertions(IActionResult subject) : base(subject)
2020
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using FluentAssertions.Execution;
2+
using FluentAssertions.Primitives;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.AspNetCore.Mvc.Infrastructure;
5+
using System.Diagnostics;
6+
7+
namespace FluentAssertions.AspNetCore.Mvc
8+
{
9+
/// <summary>
10+
/// Contains a number of methods to assert that an <see cref="ActionResult"/> is in the expected state.
11+
/// </summary>
12+
[DebuggerNonUserCode]
13+
public class ActionResultAssertions<TValue> : ReferenceTypeAssertions<ActionResult<TValue>, ActionResultAssertions<TValue>>
14+
{
15+
#region Public Constructors
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="ActionResultAssertions{TValue}" /> class.
19+
/// </summary>
20+
public ActionResultAssertions(ActionResult<TValue> subject)
21+
{
22+
Subject = subject;
23+
}
24+
25+
#endregion Public Constructors
26+
27+
#region Protected Properties
28+
29+
/// <inheritdoc />
30+
protected override string Identifier { get; } = $"ActionResult<{typeof(TValue).Name}>";
31+
32+
#endregion Protected Properties
33+
34+
#region Public Properties
35+
36+
/// <summary>
37+
/// Gets the <see cref="ActionResult{TValue}.Result"/> of the Subject.
38+
/// </summary>
39+
public ActionResult Result => Subject.Result;
40+
41+
/// <summary>
42+
/// Gets the <see cref="ActionResult{TValue}.Value"/> of the Subject.
43+
/// </summary>
44+
public TValue Value => Subject.Value;
45+
46+
#endregion Public Properties
47+
48+
#region Public Methods
49+
50+
/// <summary>
51+
/// Asserts that the <see cref="ActionResult{TValue}.Result"/> is type of <typeparamref name="TActionResult"/>.
52+
/// </summary>
53+
/// <param name="reason">
54+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
55+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
56+
/// </param>
57+
/// <param name="reasonArgs">
58+
/// Zero or more objects to format using the placeholders in <paramref name="reason"/>.
59+
/// </param>
60+
/// <returns>
61+
/// An <see cref="AndWhichConstraint{TParentConstraint, TMatchedElement}"/> where the Which contains
62+
/// the result of Result converted to <typeparamref name="TActionResult"/>.
63+
/// </returns>
64+
[CustomAssertion]
65+
public AndWhichConstraint<ActionResultAssertions<TValue>, TActionResult> BeConvertibleTo<TActionResult>(
66+
string reason = "", params object[] reasonArgs)
67+
where TActionResult : ActionResult
68+
{
69+
var convertResult = ((IConvertToActionResult)Subject).Convert();
70+
Execute.Assertion
71+
.BecauseOf(reason, reasonArgs)
72+
.ForCondition(convertResult != null)
73+
.FailWith(FailureMessages.ConvertibleActionFailMessage, typeof(TActionResult), null);
74+
75+
Execute.Assertion
76+
.BecauseOf(reason, reasonArgs)
77+
.ForCondition(convertResult.GetType() == typeof(TActionResult))
78+
.FailWith(FailureMessages.ConvertibleActionFailMessage, typeof(TActionResult), convertResult.GetType());
79+
80+
return new AndWhichConstraint<ActionResultAssertions<TValue>, TActionResult>(this, (TActionResult)convertResult);
81+
}
82+
}
83+
#endregion Public Methods
84+
}

0 commit comments

Comments
 (0)