Skip to content

Target netcoreapp2.1 and netcoreapp3.0 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto eol=crlf

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
*.cs text diff=csharp

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
15 changes: 15 additions & 0 deletions FluentAssertions.AspNetCore.Mvc.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{A4C33565
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentAssertions.AspNetCore.Mvc", "src\FluentAssertions.AspNetCore.Mvc\FluentAssertions.AspNetCore.Mvc.csproj", "{EA71D220-089E-4CB1-B187-D9BB4DFD8624}"
EndProject
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}"
EndProject
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}"
EndProject
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}"
Expand Down Expand Up @@ -44,6 +46,18 @@ Global
{EA71D220-089E-4CB1-B187-D9BB4DFD8624}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{EA71D220-089E-4CB1-B187-D9BB4DFD8624}.Release|x86.ActiveCfg = Release|Any CPU
{EA71D220-089E-4CB1-B187-D9BB4DFD8624}.Release|x86.Build.0 = Release|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|x86.ActiveCfg = Debug|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Debug|x86.Build.0 = Debug|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|Any CPU.Build.0 = Release|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|x86.ActiveCfg = Release|Any CPU
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF}.Release|x86.Build.0 = Release|Any CPU
{A4962D4A-A99A-4F96-8F76-C5A2F1D06577}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4962D4A-A99A-4F96-8F76-C5A2F1D06577}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4962D4A-A99A-4F96-8F76-C5A2F1D06577}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -86,6 +100,7 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{EA71D220-089E-4CB1-B187-D9BB4DFD8624} = {89B09C65-4F1E-4B5A-AD58-E244113F2C02}
{BA15EEA1-7305-42D3-A60E-3BDEC8CBECAF} = {89B09C65-4F1E-4B5A-AD58-E244113F2C02}
{A4962D4A-A99A-4F96-8F76-C5A2F1D06577} = {A4C33565-1E6E-4AE7-8F02-1911DBA00263}
{BCFB2639-D0CC-4E81-B431-8CB37F66480F} = {4E91D524-3DC0-4E08-82FE-6FDAEB89212B}
{263F58EE-CF19-4974-AEBB-2A0E6C3F9054} = {4E91D524-3DC0-4E08-82FE-6FDAEB89212B}
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: '{build}'
image: Visual Studio 2017
image: Visual Studio 2019
configuration: Release

before_build:
Expand Down
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"msbuild-sdks": {
"MSBuild.Sdk.Extras": "2.0.54"
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.Collections.Generic;
using System.Net.Mime;
using System.Security.Claims;
using FluentAssertions.AspNetCore.Mvc.Sample.Controllers;
using FluentAssertions.AspNetCore.Mvc.Sample.Controllers;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Routing;
using Microsoft.EntityFrameworkCore.ValueGeneration.Internal;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
using System;
using System.Collections.Generic;
using System.Security.Claims;
using Xunit;

namespace FluentAssertions.AspNetCore.Mvc.Sample.Tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using FluentAssertions.AspNetCore.Mvc.Sample.Controllers;
using Microsoft.AspNetCore.Mvc;
using System;
using Xunit;

namespace FluentAssertions.AspNetCore.Mvc.Sample.Tests
Expand All @@ -13,5 +15,34 @@ public void List_ShouldReturnView()
.BeViewResult()
.WithViewName("Index");
}

[Fact]
public void GetActionResultOfT_OnFalse_Returns_Data()
{
var controller = new ProductController();
var model = new Models.ProductViewModel { Id = 1, Name = "Text" };
var returnError = false;

var result = controller.GetActionResultOfT(model, returnError);

result.Should().BeConvertibleTo<ObjectResult>()
.And.Value.Should().BeSameAs(model);
}

[Fact]
public void GetActionResultOfT_OnTrue_Returns_BadRequest()
{
var controller = new ProductController();
var model = new Models.ProductViewModel { Id = 1, Name = "Text" };
var returnError = true;

var result = controller.GetActionResultOfT(model, returnError);

result.Should().BeConvertibleTo<BadRequestObjectResult>()
.Which.Value.Should().BeSameAs(model);

result.Should().BeConvertibleTo<BadRequestObjectResult>()
.Which.Should().BeBadRequestObjectResult();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using FluentAssertions.AspNetCore.Mvc.Sample.Models;
using Microsoft.AspNetCore.Mvc;

namespace FluentAssertions.AspNetCore.Mvc.Sample.Controllers
{
Expand All @@ -9,5 +10,18 @@ public IActionResult List()
{
return View("Index");
}

#region ActionResult<T>
[HttpGet]
public ActionResult<ProductViewModel> GetActionResultOfT(
ProductViewModel data, bool error)
{
if (error)
{
return BadRequest(data);
}
return data;
}
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0" />
</ItemGroup>

</Project>
28 changes: 19 additions & 9 deletions samples/FluentAssertions.AspNetCore.Mvc.Sample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -28,24 +24,38 @@ public Startup(IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddMvc(options =>
{
#if NETCOREAPP3_0
options.EnableEndpointRouting = false;
#endif
});

services.AddLogging(configure =>
{
configure.AddConsole();
configure.AddDebug();
});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
#if NETCOREAPP2_1
app.UseBrowserLink();
#endif
}
else
{
app.UseExceptionHandler("/Home/Error");
}
#if NETCOREAPP2_1
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
#endif

app.UseStaticFiles();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="MSBuild.Sdk.Extras">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\FluentAssertions.AspNetCore.Mvc\*.cs" Exclude="..\FluentAssertions.AspNetCore.Mvc\obj\*.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace FluentAssertions.AspNetCore.Mvc
public class AcceptedAtActionResultAssertions : ObjectAssertions
{
/// <summary>
/// Initializes a new instance of the <see cref="T:AcceptedAtActionResultAssertions" /> class.
/// Initializes a new instance of the <see cref="AcceptedAtActionResultAssertions" /> class.
/// </summary>
public AcceptedAtActionResultAssertions(AcceptedAtActionResult subject) : base(subject) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace FluentAssertions.AspNetCore.Mvc
public class AcceptedAtRouteResultAssertions : ObjectAssertions
{
/// <summary>
/// Initializes a new instance of the <see cref="T:AcceptedAtRouteResultAssertions" /> class.
/// Initializes a new instance of the <see cref="AcceptedAtRouteResultAssertions" /> class.
/// </summary>
public AcceptedAtRouteResultAssertions(AcceptedAtRouteResult subject) : base(subject) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AcceptedResultAssertions : ObjectAssertions
#region Public Constructors

/// <summary>
/// Initializes a new instance of the <see cref="T:AcceptedResultAssertions" /> class.
/// Initializes a new instance of the <see cref="AcceptedResultAssertions" /> class.
/// </summary>
/// <param name="subject">The object to test assertion on</param>
public AcceptedResultAssertions(AcceptedResult subject) : base(subject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ActionResultAssertions : ObjectAssertions
#region Public Constructors

/// <summary>
/// Initializes a new instance of the <see cref="T:ActionResultAssertions" /> class.
/// Initializes a new instance of the <see cref="ActionResultAssertions" /> class.
/// </summary>
public ActionResultAssertions(IActionResult subject) : base(subject)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using FluentAssertions.Execution;
using FluentAssertions.Primitives;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using System.Diagnostics;

namespace FluentAssertions.AspNetCore.Mvc
{
/// <summary>
/// Contains a number of methods to assert that an <see cref="ActionResult"/> is in the expected state.
/// </summary>
[DebuggerNonUserCode]
public class ActionResultAssertions<TValue> : ReferenceTypeAssertions<ActionResult<TValue>, ActionResultAssertions<TValue>>
{
#region Public Constructors

/// <summary>
/// Initializes a new instance of the <see cref="ActionResultAssertions{TValue}" /> class.
/// </summary>
public ActionResultAssertions(ActionResult<TValue> subject)
{
Subject = subject;
}

#endregion Public Constructors

#region Protected Properties

/// <inheritdoc />
protected override string Identifier { get; } = $"ActionResult<{typeof(TValue).Name}>";

#endregion Protected Properties

#region Public Properties

/// <summary>
/// Gets the <see cref="ActionResult{TValue}.Result"/> of the Subject.
/// </summary>
public ActionResult Result => Subject.Result;

/// <summary>
/// Gets the <see cref="ActionResult{TValue}.Value"/> of the Subject.
/// </summary>
public TValue Value => Subject.Value;

#endregion Public Properties

#region Public Methods

/// <summary>
/// Asserts that the <see cref="ActionResult{TValue}.Result"/> is type of <typeparamref name="TActionResult"/>.
/// </summary>
/// <param name="reason">
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
/// </param>
/// <param name="reasonArgs">
/// Zero or more objects to format using the placeholders in <paramref name="reason"/>.
/// </param>
/// <returns>
/// An <see cref="AndWhichConstraint{TParentConstraint, TMatchedElement}"/> where the Which contains
/// the result of Result converted to <typeparamref name="TActionResult"/>.
/// </returns>
[CustomAssertion]
public AndWhichConstraint<ActionResultAssertions<TValue>, TActionResult> BeConvertibleTo<TActionResult>(
string reason = "", params object[] reasonArgs)
where TActionResult : ActionResult
{
var convertResult = ((IConvertToActionResult)Subject).Convert();
Execute.Assertion
.BecauseOf(reason, reasonArgs)
.ForCondition(convertResult != null)
.FailWith(FailureMessages.ConvertibleActionFailMessage, typeof(TActionResult), null);

Execute.Assertion
.BecauseOf(reason, reasonArgs)
.ForCondition(convertResult.GetType() == typeof(TActionResult))
.FailWith(FailureMessages.ConvertibleActionFailMessage, typeof(TActionResult), convertResult.GetType());

return new AndWhichConstraint<ActionResultAssertions<TValue>, TActionResult>(this, (TActionResult)convertResult);
}
}
#endregion Public Methods
}
Loading