Skip to content

Commit b45553e

Browse files
author
CaseyBurns
committed
outgoing route tests working, more unit tests and sample code
1 parent c8d6ec7 commit b45553e

22 files changed

+369
-51
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Web.Mvc;
33

4-
namespace FluentAssertions.Mvc.Tests.Fakes
4+
namespace FluentAssertions.Mvc3.Tests.Fakes
55
{
66
public class FakeController : Controller
77
{

src/FluentAssertions.Mvc.Tests/FluentAssertions.Mvc3.Tests.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@
4545
</Reference>
4646
</ItemGroup>
4747
<ItemGroup>
48-
<Compile Include="AssemblyInfo.cs" />
48+
<Compile Include="..\SolutionInfo.cs">
49+
<Link>Properties\SolutionInfo.cs</Link>
50+
</Compile>
51+
<Compile Include="Properties\AssemblyInfo.cs" />
4952
<Compile Include="Fakes\FakeController.cs" />
5053
<Compile Include="ActionResultAssertions_Tests.cs" />
54+
<Compile Include="RouteDataAssertions_Tests.cs" />
55+
<Compile Include="RouteValueDictionary_Extensions_Tests.cs" />
5156
<Compile Include="ViewResultAssertions_Tests.cs" />
5257
</ItemGroup>
5358
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

src/FluentAssertions.Mvc.Tests/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,11 @@
66

77
[assembly: AssemblyTitle("FluentAssertions.Mvc3.Tests")]
88
[assembly: AssemblyDescription("")]
9-
[assembly: AssemblyConfiguration("")]
10-
[assembly: AssemblyCompany("")]
11-
[assembly: AssemblyProduct("")]
12-
[assembly: AssemblyCopyright("Casey Burns")]
13-
[assembly: AssemblyTrademark("")]
14-
[assembly: AssemblyCulture("")]
159

1610
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
1711
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
1812
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
1913

20-
[assembly: AssemblyVersion("1.0.0.0")]
21-
2214
// The following attributes are used to specify the signing key for the assembly,
2315
// if desired. See the Mono documentation for more information about signing.
2416

src/FluentAssertions.Mvc.Tests/RouteDataAssertions_Tests.cs

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
using System.Text;
55
using System.Web.Routing;
66
using System.Web.Mvc;
7+
using NUnit.Framework;
78

8-
namespace FluentAssertions.Mvc.Tests
9+
namespace FluentAssertions.Mvc3.Tests
910
{
11+
[TestFixture]
1012
public class RouteDataAssertions_Tests
1113
{
1214
private RouteCollection _routes;
@@ -22,7 +24,109 @@ public RouteDataAssertions_Tests()
2224
Action = "Index",
2325
Id = UrlParameter.Optional
2426
}),
27+
DataTokens = new RouteValueDictionary(new
28+
{
29+
Area = "area51"
30+
})
2531
});
2632
}
33+
34+
[Test]
35+
public void HaveValue_GivenKeyDoesExist_ShouldFail()
36+
{
37+
var routeData = _routes.GetRouteDataForUrl("/accounts/check");
38+
Action a = () => routeData.Should().HaveValue("xyz", "");
39+
a.ShouldThrow<Exception>();
40+
}
41+
42+
[Test]
43+
public void HaveValue_GivenExpectedController_ShouldPass()
44+
{
45+
var routeData = _routes.GetRouteDataForUrl("/accounts/check");
46+
routeData.Should().HaveValue("controller", "accounts");
47+
}
48+
49+
[Test]
50+
public void HaveValue_GivenUnexpectedController_ShouldFail()
51+
{
52+
var routeData = _routes.GetRouteDataForUrl("/accounts/check");
53+
Action a = () => routeData.Should().HaveValue("controller", "xyz");
54+
a.ShouldThrow<Exception>();
55+
}
56+
57+
[Test]
58+
public void HaveValue_GivenNoId_ShouldPass()
59+
{
60+
var routeData = _routes.GetRouteDataForUrl("/accounts/check");
61+
routeData.Should().HaveValue("id", UrlParameter.Optional);
62+
}
63+
64+
[Test]
65+
public void HaveValue_GivenExpectedId_ShouldPass()
66+
{
67+
var routeData = _routes.GetRouteDataForUrl("/accounts/check/44");
68+
routeData.Should().HaveValue("id", "44");
69+
}
70+
71+
[Test]
72+
public void HaveValue_GivenUnexpectedId_ShouldFail()
73+
{
74+
var routeData = _routes.GetRouteDataForUrl("/accounts/check/44");
75+
Action a = () => routeData.Should().HaveValue("id", "999");
76+
a.ShouldThrow<Exception>();
77+
}
78+
79+
[Test]
80+
public void HaveController_GivenExpectedValue_ShouldPass()
81+
{
82+
var routeData = _routes.GetRouteDataForUrl("/accounts/check/44");
83+
routeData.Should().HaveController("accounts");
84+
}
85+
86+
[Test]
87+
public void HaveController_GivenUnexpectedValue_ShouldFail()
88+
{
89+
var routeData = _routes.GetRouteDataForUrl("/accounts/check/44");
90+
Action a = () => routeData.Should().HaveController("xyz");
91+
a.ShouldThrow<Exception>();
92+
}
93+
94+
[Test]
95+
public void HaveAction_GivenExpectedValue_ShouldPass()
96+
{
97+
var routeData = _routes.GetRouteDataForUrl("/accounts/check/44");
98+
routeData.Should().HaveAction("check");
99+
}
100+
101+
[Test]
102+
public void HaveAction_GivenUnexpectedValue_ShouldFail()
103+
{
104+
var routeData = _routes.GetRouteDataForUrl("/accounts/check/44");
105+
Action a = () => routeData.Should().HaveAction("xyz");
106+
a.ShouldThrow<Exception>();
107+
}
108+
109+
[Test]
110+
public void HaveDataToken_GivenKeyDoesExist_ShouldFail()
111+
{
112+
var routeData = _routes.GetRouteDataForUrl("/accounts/check");
113+
Action a = () => routeData.Should().HaveDataToken("xyz", "");
114+
a.ShouldThrow<Exception>();
115+
}
116+
117+
[Test]
118+
public void HaveDataToken_GivenExpectedArea_ShouldPass()
119+
{
120+
var routeData = _routes.GetRouteDataForUrl("/accounts/check");
121+
routeData.Should().HaveDataToken("area", "area51");
122+
}
123+
124+
[Test]
125+
public void HaveDataToken_GivenUnexpectedArea_ShouldFail()
126+
{
127+
var routeData = _routes.GetRouteDataForUrl("/accounts/check");
128+
Action a = () => routeData.Should().HaveDataToken("area", "xyz");
129+
a.ShouldThrow<Exception>();
130+
}
27131
}
28132
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using NUnit.Framework;
6+
using System.Web.Routing;
7+
using System.Web.Mvc;
8+
9+
namespace FluentAssertions.Mvc3.Tests
10+
{
11+
[TestFixture]
12+
public class RouteValueDictionary_Extensions_Tests
13+
{
14+
public static void a()
15+
{
16+
var routes = new RouteCollection();
17+
routes.Add(new Route("{controller}/{action}/{id}", new MvcRouteHandler())
18+
{
19+
Defaults = new RouteValueDictionary(new
20+
{
21+
Controller = "Home",
22+
Action = "Index",
23+
Id = UrlParameter.Optional
24+
}),
25+
});
26+
27+
var routeValues = new RouteValueDictionary(new
28+
{
29+
Controller = "Home",
30+
Action = "Index"
31+
});
32+
33+
var url = routeValues.GenerateUrl(routes);
34+
url.Should().Be("/abcHome");
35+
}
36+
}
37+
}

src/FluentAssertions.Mvc.Tests/ViewResultAssertions_Tests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ public void ModelAs_GivenWrongType_ShouldFail()
303303
ActionResult result = _controller.Index();
304304

305305
//ASSERT
306-
result.Should().BeView().ModelAs<int>().Should().Be(2);
307306
Action a = () => result.Should().BeView().ModelAs<int>().Should().Be(2);
308307
a.ShouldThrow<Exception>();
309308
}

src/FluentAssertions.Mvc.sln

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11

22
Microsoft Visual Studio Solution File, Format Version 11.00
33
# Visual C# Express 2010
4-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentAssertions.Mvc.Tests", "FluentAssertions.Mvc.Tests\FluentAssertions.Mvc.Tests.csproj", "{3CB00FF9-3DC2-460F-82E8-EBFB6339247D}"
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentAssertions.Mvc3.Tests", "FluentAssertions.Mvc.Tests\FluentAssertions.Mvc3.Tests.csproj", "{3CB00FF9-3DC2-460F-82E8-EBFB6339247D}"
55
EndProject
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentAssertions.Mvc3", "FluentAssertions.Mvc3\FluentAssertions.Mvc3.csproj", "{53589F79-0908-409A-8366-3E18DC637600}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{D29AE253-FEE8-4A54-BFBD-323CAD27F549}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentAssertions.Mvc3.Samples", "FluentAssertions.Mvc3.Samples\FluentAssertions.Mvc3.Samples.csproj", "{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -47,6 +49,16 @@ Global
4749
{D29AE253-FEE8-4A54-BFBD-323CAD27F549}.Release|Mixed Platforms.Build.0 = Release|x86
4850
{D29AE253-FEE8-4A54-BFBD-323CAD27F549}.Release|x86.ActiveCfg = Release|x86
4951
{D29AE253-FEE8-4A54-BFBD-323CAD27F549}.Release|x86.Build.0 = Release|x86
52+
{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53+
{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}.Debug|Any CPU.Build.0 = Debug|Any CPU
54+
{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
55+
{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
56+
{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}.Debug|x86.ActiveCfg = Debug|Any CPU
57+
{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}.Release|Any CPU.ActiveCfg = Release|Any CPU
58+
{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}.Release|Any CPU.Build.0 = Release|Any CPU
59+
{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
60+
{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}.Release|Mixed Platforms.Build.0 = Release|Any CPU
61+
{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}.Release|x86.ActiveCfg = Release|Any CPU
5062
EndGlobalSection
5163
GlobalSection(SolutionProperties) = preSolution
5264
HideSolutionNode = FALSE

src/FluentAssertions.Mvc3.Samples/ActionResultSamples.cs renamed to src/FluentAssertions.Mvc3.Samples/ActionResult_Samples.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace FluentAssertions.Mvc3.Samples
1111
{
12-
public class ActionResultSamples
12+
public class ActionResult_Samples
1313
{
1414
public void ViewResult_Sample()
1515
{

src/FluentAssertions.Mvc3.Samples/FluentAssertions.Mvc3.Samples.csproj

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
66
<ProductVersion>8.0.30703</ProductVersion>
77
<SchemaVersion>2.0</SchemaVersion>
8-
<ProjectGuid>c791f407-a2ac-4908-9fb4-0041fdc5d992</ProjectGuid>
8+
<ProjectGuid>{7B9B969E-C3E1-47DD-89B1-AD17232D4A23}</ProjectGuid>
99
<OutputType>Library</OutputType>
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>FluentAssertions.Mvc3.Samples</RootNamespace>
@@ -31,18 +31,41 @@
3131
<WarningLevel>4</WarningLevel>
3232
</PropertyGroup>
3333
<ItemGroup>
34+
<Reference Include="FluentAssertions">
35+
<HintPath>..\..\lib\FluentAssertions.1.7.0\Lib\net40\FluentAssertions.dll</HintPath>
36+
</Reference>
3437
<Reference Include="System" />
3538
<Reference Include="System.Core" />
39+
<Reference Include="System.Web" />
40+
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
41+
<SpecificVersion>False</SpecificVersion>
42+
<HintPath>C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll</HintPath>
43+
</Reference>
44+
<Reference Include="System.Web.Routing" />
3645
<Reference Include="System.Xml.Linq" />
3746
<Reference Include="System.Data.DataSetExtensions" />
3847
<Reference Include="Microsoft.CSharp" />
3948
<Reference Include="System.Data" />
4049
<Reference Include="System.Xml" />
4150
</ItemGroup>
4251
<ItemGroup>
43-
<Compile Include="Class1.cs" />
52+
<Compile Include="..\SolutionInfo.cs">
53+
<Link>Properties\SolutionInfo.cs</Link>
54+
</Compile>
55+
<Compile Include="ActionResult_Samples.cs" />
56+
<Compile Include="Controllers\HomeController.cs" />
57+
<Compile Include="IncomingUrl_Samples.cs" />
58+
<Compile Include="Models\WelcomeModel.cs" />
59+
<Compile Include="MvcApplication.cs" />
60+
<Compile Include="OutGoingUrl_Samples.cs" />
4461
<Compile Include="Properties\AssemblyInfo.cs" />
4562
</ItemGroup>
63+
<ItemGroup>
64+
<ProjectReference Include="..\FluentAssertions.Mvc3\FluentAssertions.Mvc3.csproj">
65+
<Project>{53589F79-0908-409A-8366-3E18DC637600}</Project>
66+
<Name>FluentAssertions.Mvc3</Name>
67+
</ProjectReference>
68+
</ItemGroup>
4669
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
4770
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
4871
Other similar extension points exist, see Microsoft.Common.targets.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Web.Routing;
6+
7+
namespace FluentAssertions.Mvc3.Samples
8+
{
9+
public class IncomingUrl_Samples
10+
{
11+
private RouteCollection GetRoutes()
12+
{
13+
var routes = new RouteCollection();
14+
MvcApplication.RegisterRoutes(routes);
15+
return routes;
16+
}
17+
18+
public void IncomingUrl_Sample()
19+
{
20+
var routes = GetRoutes();
21+
var routeData = routes.GetRouteDataForUrl("product/view/444");
22+
routeData.Should()
23+
.HaveController("product")
24+
.HaveAction("view")
25+
.HaveValue("Id", "444")
26+
.HaveDataToken("Area", "products");
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)