Skip to content

Commit a5b2c14

Browse files
author
CaseyBurns
committed
More ViewResult assertions
1 parent 1eeaa59 commit a5b2c14

File tree

8 files changed

+83
-25
lines changed

8 files changed

+83
-25
lines changed

src/FluentAssertions.Mvc.Tests/ControllerAssertions_Tests.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,27 @@ public void BeView_GivenViewResultWithExpectedName_ShouldPass ()
2121
var controller = new FakeController (new ViewResult { ViewName = "Index"});
2222
controller.Index ().Should ().BeView ();
2323
}
24-
24+
2525
[Test]
2626
public void BeView_GivenRedirection_ShouldFail ()
2727
{
2828
var controller = new FakeController (new RedirectResult ("/"));
2929
Action action = () => controller.Index ().Should ().BeView ();
30-
action.ShouldThrow<AssertionException> ().WithMessage ("Expected ActionResult to be ViewResult but was \"RedirectResult\"");
30+
action.ShouldThrow<AssertionException> ();
31+
}
32+
33+
[Test]
34+
public void a ()
35+
{
36+
var controller = new FakeController (new ViewResult { ViewName = "Index"});
37+
controller.Index ().Should ().BeView ().WithViewName ("Index");
38+
}
39+
40+
[Test]
41+
public void b ()
42+
{
43+
var controller = new FakeController (new ViewResult { ViewName = "Index", MasterName="Fake"});
44+
controller.Index ().Should ().BeView ().WithViewName ("Index").WithControllerName ("Fake");
3145
}
3246
}
3347
}

src/FluentAssertions.Mvc.Tests/Fakes/FakeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public FakeController (ActionResult indexResult)
1212
_indexResult = indexResult;
1313
}
1414

15-
public ActionResult Index()
15+
public ActionResult Index ()
1616
{
1717
return _indexResult;
1818
}

src/FluentAssertions.Mvc.userprefs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<Properties>
2-
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
3-
<MonoDevelop.Ide.Workbench ActiveDocument="FluentAssertions.Mvc.Tests\ControllerAssertions_Tests.cs">
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
3+
<MonoDevelop.Ide.Workbench ActiveDocument="FluentAssertions.Mvc3\ViewResultAndConstraint.cs">
44
<Files>
5-
<File FileName="FluentAssertions.Mvc.Tests\ControllerAssertions_Tests.cs" Line="5" Column="1" />
5+
<File FileName="FluentAssertions.Mvc.Tests\ControllerAssertions_Tests.cs" Line="45" Column="4" />
6+
<File FileName="d:\Development\FluentAssertions.MVC\src\FluentAssertions.Mvc3\AssertionsExtensions.cs" Line="16" Column="1" />
7+
<File FileName="FluentAssertions.Mvc3\ActionResultAssertions.cs" Line="31" Column="4" />
8+
<File FileName="FluentAssertions.Mvc.Tests\Fakes\FakeController.cs" Line="21" Column="1" />
9+
<File FileName="FluentAssertions.Mvc3\ViewResultAndConstraint.cs" Line="1" Column="14" />
10+
<File FileName="FluentAssertions.Mvc3\ControllerAssertions.cs" Line="1" Column="1" />
611
</Files>
712
<Pads>
813
<Pad Id="ProjectPad">
914
<State expanded="True">
1015
<Option id="ShowAllFiles" value="False" />
1116
<Option id="ShowVersionControlOverlays" value="True" />
17+
<Node name="FluentAssertions.Mvc.Tests" expanded="True" />
1218
<Node name="FluentAssertions.Mvc3" expanded="True" selected="True" />
1319
</State>
1420
</Pad>
@@ -19,7 +25,17 @@
1925
<State />
2026
</Pad>
2127
<Pad Id="MonoDevelop.NUnit.TestPad">
22-
<State expanded="True" selected="True" />
28+
<State expanded="True" selected="True">
29+
<Node name="FluentAssertions.Mvc.Tests" expanded="True">
30+
<Node name="FluentAssertions" expanded="True">
31+
<Node name="Mvc" expanded="True">
32+
<Node name="Tests" expanded="True">
33+
<Node name="ActionResultAssertions_Tests" expanded="True" />
34+
</Node>
35+
</Node>
36+
</Node>
37+
</Node>
38+
</State>
2339
</Pad>
2440
</Pads>
2541
</MonoDevelop.Ide.Workbench>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Web.Mvc;
3+
4+
namespace FluentAssertions.Mvc
5+
{
6+
public class ActionResultAndConstraint : AndConstraint<ActionResult>
7+
{
8+
public ActionResultAndConstraint (ActionResult subject) : base(subject)
9+
{
10+
}
11+
12+
public ActionResultAndConstraint WithViewName (string viewName)
13+
{
14+
throw new NotImplementedException ();
15+
return this;
16+
}
17+
18+
public ActionResultAndConstraint WithViewName (string viewName, string reason, params object[] reasonArgs)
19+
{
20+
return this;
21+
}
22+
23+
public ActionResultAndConstraint WithControllerName (string viewName)
24+
{
25+
throw new NotImplementedException ();
26+
return this;
27+
}
28+
29+
public ActionResultAndConstraint WithControllerName (string viewName, string reason, params object[] reasonArgs)
30+
{
31+
throw new NotImplementedException ();
32+
return this;
33+
}
34+
}
35+
}
36+

src/FluentAssertions.Mvc3/ActionResultAssertions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ public ActionResultAssertions (ActionResult subject)
1111
Subject = subject;
1212
}
1313

14-
public AndConstraint<ActionResultAssertions> BeView ()
14+
public ActionResultAndConstraint BeView ()
1515
{
1616
var andConstraint = BeView (string.Empty, new object[] { });
1717
return andConstraint;
1818
}
1919

20-
public AndConstraint<ActionResultAssertions> BeView (string reason, params object [] reasonArgs)
20+
public ActionResultAndConstraint BeView (string reason, params object [] reasonArgs)
2121
{
2222
Execute.Verification
2323
.ForCondition (Subject is ViewResult)
2424
.BecauseOf (reason, reasonArgs)
2525
.FailWith ("Expected ActionResult to be View but was {0}", Subject.GetType ().Name);
2626

27-
return new AndConstraint<ActionResultAssertions> (this);
28-
}
27+
return new ActionResultAndConstraint (Subject);
28+
}
2929
}
3030
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/FluentAssertions.Mvc3/FluentAssertions.Mvc3.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<ErrorReport>prompt</ErrorReport>
2020
<WarningLevel>4</WarningLevel>
2121
<ConsolePause>false</ConsolePause>
22+
<GenerateDocumentation>true</GenerateDocumentation>
2223
</PropertyGroup>
2324
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2425
<DebugType>full</DebugType>
@@ -34,7 +35,6 @@
3435
<Reference Include="System" />
3536
<Reference Include="FluentAssertions">
3637
<HintPath>..\..\lib\FluentAssertions.1.7.0\Lib\net40\FluentAssertions.dll</HintPath>
37-
<Private>False</Private>
3838
</Reference>
3939
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
4040
<Private>False</Private>
@@ -49,7 +49,10 @@
4949
<Compile Include="AssertionsExtensions.cs" />
5050
<Compile Include="ControllerAssertions.cs" />
5151
<Compile Include="ActionResultAssertions.cs" />
52-
<Compile Include="ViewResultAndConstraint.cs" />
52+
<Compile Include="ActionResultAndConstraint.cs" />
5353
</ItemGroup>
5454
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
55+
<ItemGroup>
56+
<EmbeddedResource Include="AssertionFailureReasons.resources" />
57+
</ItemGroup>
5558
</Project>

src/FluentAssertions.Mvc3/ViewResultAndConstraint.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)