Skip to content

Commit d334bcd

Browse files
committed
Merge pull request #8 from robdmoore/example-project
Example project
2 parents ab40c97 + 6bf7d22 commit d334bcd

File tree

128 files changed

+35409
-22
lines changed

Some content is hidden

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

128 files changed

+35409
-22
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ _ReSharper*
1313
*/NUnit*/tools
1414
*/NhibernateProfiler*/tools
1515
packages
16-
*.DotSettings
16+
*.DotSettings
17+
/TestStack.FluentMVCTesting.Example/App_Data
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System.Web.Mvc;
2+
using System.Web.Routing;
3+
using NSubstitute;
4+
using NUnit.Framework;
5+
using TestStack.FluentMVCTesting.Sample.Controllers;
6+
using TestStack.FluentMVCTesting.Sample.Models;
7+
using TestStack.FluentMVCTesting.Sample.Services;
8+
9+
namespace TestStack.FluentMVCTesting.Sample.Tests.Controllers
10+
{
11+
class AccountControllerTests
12+
{
13+
private AccountController _controller;
14+
private IAuthenticationService _authenticationService;
15+
16+
[SetUp]
17+
public void Setup()
18+
{
19+
_authenticationService = Substitute.For<IAuthenticationService>();
20+
_controller = new AccountController(_authenticationService)
21+
{
22+
Url = new UrlHelper(Substitute.For<RequestContext>())
23+
};
24+
}
25+
26+
[Test]
27+
public void WhenViewingLoginPage_ThenShowDefaultViewWithReturnUrl()
28+
{
29+
const string returnUrl = "http://www.google.com.au/";
30+
31+
_controller.WithCallTo(c => c.Login(returnUrl))
32+
.ShouldRenderDefaultView();
33+
34+
Assert.That(_controller.ViewBag.ReturnUrl, Is.EqualTo(returnUrl));
35+
}
36+
37+
[Test]
38+
public void GivenInvalidSubmission_WhenPostingLoginDetails_ThenShowDefaultViewWithInvalidModelAndReturnUrl()
39+
{
40+
var vm = new LoginModel();
41+
const string returnUrl = "http://www.google.com.au/";
42+
43+
_controller.WithModelErrors()
44+
.WithCallTo(c => c.Login(vm, returnUrl))
45+
.ShouldRenderDefaultView()
46+
.WithModel(vm);
47+
48+
Assert.That(_controller.ViewBag.ReturnUrl, Is.EqualTo(returnUrl));
49+
}
50+
51+
[Test]
52+
public void GivenValidSubmissionButIncorrectDetails_WhenPostingLoginDetails_ThenShowDefaultViewWithInvalidModelAndReturnUrlAndErrorMessage()
53+
{
54+
var vm = new LoginModel();
55+
const string returnUrl = "http://www.google.com.au/";
56+
_authenticationService.Login(vm).Returns(false);
57+
58+
_controller.WithCallTo(c => c.Login(vm, returnUrl))
59+
.ShouldRenderDefaultView()
60+
.WithModel(vm)
61+
.AndModelError("").ThatEquals("The user name or password provided is incorrect.");
62+
63+
Assert.That(_controller.ViewBag.ReturnUrl, Is.EqualTo(returnUrl));
64+
}
65+
66+
[Test]
67+
public void GivenLocalReturnUrlAndValidSubmission_WhenPostingLoginDetails_ThenLogUserInAndRedirectToReturnUrl()
68+
{
69+
var vm = new LoginModel();
70+
const string returnUrl = "/localurl";
71+
_authenticationService.Login(vm).Returns(true);
72+
73+
_controller.WithCallTo(c => c.Login(vm, returnUrl))
74+
.ShouldRedirectTo(returnUrl);
75+
}
76+
77+
[Test]
78+
public void GivenNonLocalReturnUrlAndValidSubmission_WhenPostingLoginDetails_ThenLogUserInAndRedirectToHomepage()
79+
{
80+
var vm = new LoginModel();
81+
const string returnUrl = "http://www.google.com.au/";
82+
_authenticationService.Login(vm).Returns(true);
83+
84+
_controller.WithCallTo(c => c.Login(vm, returnUrl))
85+
.ShouldRedirectTo<HomeController>(c => c.Index());
86+
}
87+
88+
[Test]
89+
public void GivenNoReturnUrlAndValidSubmission_WhenPostingLoginDetails_ThenLogUserInAndRedirectToHomepage([Values(null, "")] string returnUrl)
90+
{
91+
var vm = new LoginModel();
92+
_authenticationService.Login(vm).Returns(true);
93+
94+
_controller.WithCallTo(c => c.Login(vm, returnUrl))
95+
.ShouldRedirectTo<HomeController>(c => c.Index());
96+
}
97+
}
98+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("TestStack.FluentMVCTesting.Example.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("TestStack.FluentMVCTesting.Example.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2013")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("d9c8385f-0b68-48ec-9399-360df30e0707")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{F36BC506-1076-49BF-A1A4-A76D6560AA64}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>TestStack.FluentMVCTesting.Sample.Tests</RootNamespace>
11+
<AssemblyName>TestStack.FluentMVCTesting.Sample.Tests</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
15+
<RestorePackages>true</RestorePackages>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
36+
<Private>True</Private>
37+
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
38+
</Reference>
39+
<Reference Include="NSubstitute">
40+
<HintPath>..\packages\NSubstitute.1.6.1.0\lib\NET40\NSubstitute.dll</HintPath>
41+
</Reference>
42+
<Reference Include="nunit.framework">
43+
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
44+
</Reference>
45+
<Reference Include="System" />
46+
<Reference Include="System.Core" />
47+
<Reference Include="System.Web" />
48+
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
49+
<Private>True</Private>
50+
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.Helpers.dll</HintPath>
51+
</Reference>
52+
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
53+
<Private>True</Private>
54+
<HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll</HintPath>
55+
</Reference>
56+
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57+
<Private>True</Private>
58+
<HintPath>..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll</HintPath>
59+
</Reference>
60+
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
61+
<Private>True</Private>
62+
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.dll</HintPath>
63+
</Reference>
64+
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
65+
<Private>True</Private>
66+
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Deployment.dll</HintPath>
67+
</Reference>
68+
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
69+
<Private>True</Private>
70+
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
71+
</Reference>
72+
<Reference Include="System.Xml.Linq" />
73+
<Reference Include="System.Data.DataSetExtensions" />
74+
<Reference Include="Microsoft.CSharp" />
75+
<Reference Include="System.Data" />
76+
<Reference Include="System.Xml" />
77+
</ItemGroup>
78+
<ItemGroup>
79+
<Compile Include="Controllers\AccountControllerTests.cs" />
80+
<Compile Include="Properties\AssemblyInfo.cs" />
81+
</ItemGroup>
82+
<ItemGroup>
83+
<None Include="packages.config" />
84+
</ItemGroup>
85+
<ItemGroup>
86+
<ProjectReference Include="..\TestStack.FluentMVCTesting.Example\TestStack.FluentMVCTesting.Sample.csproj">
87+
<Project>{0BD41AAC-8155-4328-A1A2-CB634430BB39}</Project>
88+
<Name>TestStack.FluentMVCTesting.Sample</Name>
89+
</ProjectReference>
90+
<ProjectReference Include="..\TestStack.FluentMVCTesting\TestStack.FluentMVCTesting.csproj">
91+
<Project>{152ca00f-18d3-4cf5-8ca0-2c5b70cbea19}</Project>
92+
<Name>TestStack.FluentMVCTesting</Name>
93+
</ProjectReference>
94+
</ItemGroup>
95+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
96+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
97+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
98+
Other similar extension points exist, see Microsoft.Common.targets.
99+
<Target Name="BeforeBuild">
100+
</Target>
101+
<Target Name="AfterBuild">
102+
</Target>
103+
-->
104+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net40" />
4+
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net40" />
5+
<package id="Microsoft.AspNet.WebPages" version="2.0.30506.0" targetFramework="net40" />
6+
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
7+
<package id="NSubstitute" version="1.6.1.0" targetFramework="net40" />
8+
<package id="NUnit" version="2.6.2" targetFramework="net40" />
9+
</packages>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Web.Optimization;
2+
3+
namespace TestStack.FluentMVCTesting.Sample.App_Start
4+
{
5+
public class BundleConfig
6+
{
7+
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
8+
public static void RegisterBundles(BundleCollection bundles)
9+
{
10+
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
11+
"~/Scripts/jquery-{version}.js"));
12+
13+
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
14+
"~/Scripts/jquery-ui-{version}.js"));
15+
16+
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
17+
"~/Scripts/jquery.unobtrusive*",
18+
"~/Scripts/jquery.validate*"));
19+
20+
// Use the development version of Modernizr to develop with and learn from. Then, when you're
21+
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
22+
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
23+
"~/Scripts/modernizr-*"));
24+
25+
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));
26+
27+
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
28+
"~/Content/themes/base/jquery.ui.core.css",
29+
"~/Content/themes/base/jquery.ui.resizable.css",
30+
"~/Content/themes/base/jquery.ui.selectable.css",
31+
"~/Content/themes/base/jquery.ui.accordion.css",
32+
"~/Content/themes/base/jquery.ui.autocomplete.css",
33+
"~/Content/themes/base/jquery.ui.button.css",
34+
"~/Content/themes/base/jquery.ui.dialog.css",
35+
"~/Content/themes/base/jquery.ui.slider.css",
36+
"~/Content/themes/base/jquery.ui.tabs.css",
37+
"~/Content/themes/base/jquery.ui.datepicker.css",
38+
"~/Content/themes/base/jquery.ui.progressbar.css",
39+
"~/Content/themes/base/jquery.ui.theme.css"));
40+
}
41+
}
42+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Web.Mvc;
2+
3+
namespace TestStack.FluentMVCTesting.Sample.App_Start
4+
{
5+
public class FilterConfig
6+
{
7+
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
8+
{
9+
filters.Add(new HandleErrorAttribute());
10+
}
11+
}
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Web.Mvc;
2+
using System.Web.Routing;
3+
4+
namespace TestStack.FluentMVCTesting.Sample.App_Start
5+
{
6+
public class RouteConfig
7+
{
8+
public static void RegisterRoutes(RouteCollection routes)
9+
{
10+
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
11+
12+
routes.MapRoute(
13+
name: "Default",
14+
url: "{controller}/{action}/{id}",
15+
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
16+
);
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)