-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from stack72/master
Unit Tests for MemberController
- Loading branch information
Showing
4 changed files
with
207 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,89 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{F67701A2-8F3E-41B0-910E-7DF0874133AD}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>GiveCRM.Web.Tests</RootNamespace> | ||
<AssemblyName>GiveCRM.Web.Tests</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<TargetFrameworkProfile> | ||
</TargetFrameworkProfile> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartupObject /> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="MvcContrib.TestHelper"> | ||
<HintPath>..\packages\MvcContrib.Mvc3.TestHelper-ci.3.0.90.0\lib\MvcContrib.TestHelper.dll</HintPath> | ||
</Reference> | ||
<Reference Include="NSubstitute"> | ||
<HintPath>..\packages\NSubstitute.1.2.1.0\lib\NET40\NSubstitute.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nunit.framework"> | ||
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="controllers\CampaignController.Tests.cs" /> | ||
<Compile Include="controllers\DonationController.Tests.cs" /> | ||
<Compile Include="controllers\HomeController.Tests.cs" /> | ||
<Compile Include="controllers\SetUpController.Tests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\GiveCRM.Models\GiveCRM.Models.csproj"> | ||
<Project>{EF13BB24-17A9-4A39-BB5C-9A3B36519CB1}</Project> | ||
<Name>GiveCRM.Models</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\GiveCRM.Web\GiveCRM.Web.csproj"> | ||
<Project>{4BFCD2B3-0EF2-4770-994F-D563AEFFB90B}</Project> | ||
<Name>GiveCRM.Web</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{F67701A2-8F3E-41B0-910E-7DF0874133AD}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>GiveCRM.Web.Tests</RootNamespace> | ||
<AssemblyName>GiveCRM.Web.Tests</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<TargetFrameworkProfile> | ||
</TargetFrameworkProfile> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartupObject /> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="MvcContrib.TestHelper"> | ||
<HintPath>..\packages\MvcContrib.Mvc3.TestHelper-ci.3.0.90.0\lib\MvcContrib.TestHelper.dll</HintPath> | ||
</Reference> | ||
<Reference Include="NSubstitute"> | ||
<HintPath>..\packages\NSubstitute.1.2.1.0\lib\NET40\NSubstitute.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nunit.framework"> | ||
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="controllers\CampaignController.Tests.cs" /> | ||
<Compile Include="controllers\DonationController.Tests.cs" /> | ||
<Compile Include="controllers\HomeController.Tests.cs" /> | ||
<Compile Include="controllers\MemberController.Tests.cs" /> | ||
<Compile Include="controllers\SetUpController.Tests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\GiveCRM.Models\GiveCRM.Models.csproj"> | ||
<Project>{EF13BB24-17A9-4A39-BB5C-9A3B36519CB1}</Project> | ||
<Name>GiveCRM.Models</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\GiveCRM.Web\GiveCRM.Web.csproj"> | ||
<Project>{4BFCD2B3-0EF2-4770-994F-D563AEFFB90B}</Project> | ||
<Name>GiveCRM.Web</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
--> | ||
</Project> |
92 changes: 92 additions & 0 deletions
92
src/GiveCRM.Web.Tests/controllers/MemberController.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System.Collections.Generic; | ||
using GiveCRM.Models; | ||
using GiveCRM.Web.Controllers; | ||
using GiveCRM.Web.Models.Members; | ||
using GiveCRM.Web.Services; | ||
using MvcContrib.TestHelper; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace GiveCRM.Web.Tests.controllers | ||
{ | ||
[TestFixture] | ||
public class MemberControllerTests | ||
{ | ||
private IDonationsService _donationsService; | ||
private IMemberService _memberService; | ||
private ICampaignService _campaignService; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_campaignService = Substitute.For<ICampaignService>(); | ||
_donationsService = Substitute.For<IDonationsService>(); | ||
_memberService = Substitute.For<IMemberService>(); | ||
} | ||
|
||
[Test] | ||
public void Index_Action_Returns_View() | ||
{ | ||
var controller = new MemberController(_donationsService, _memberService, _campaignService); | ||
var result = controller.Index(); | ||
|
||
result.AssertViewRendered(); | ||
} | ||
|
||
[Test] | ||
public void Add_Action_Returns_View_With_ViewModel() | ||
{ | ||
var controller = new MemberController(_donationsService, _memberService, _campaignService); | ||
var result = controller.Add(); | ||
|
||
result.AssertViewRendered().WithViewData<MemberEditViewModel>(); | ||
} | ||
|
||
[Test] | ||
public void Edit_Action_Returns_Named_View_With_ViewModel() | ||
{ | ||
_memberService.Get(1).Returns(new Member()); | ||
|
||
var controller = new MemberController(_donationsService, _memberService, _campaignService); | ||
var result = controller.Edit(1); | ||
|
||
Assert.That(result.AssertViewRendered().ViewName == "Add"); | ||
result.AssertViewRendered().WithViewData<MemberEditViewModel>(); | ||
} | ||
|
||
[Test] | ||
public void Delete_Action_Returns_RedirectToAction() | ||
{ | ||
_memberService.Get(1).Returns(new Member()); | ||
_memberService.Update(new Member()); | ||
|
||
var controller = new MemberController(_donationsService, _memberService, _campaignService); | ||
var result = controller.Delete(1); | ||
|
||
result.AssertActionRedirect().ToAction("Index"); | ||
} | ||
|
||
[Test] | ||
public void Donate_Action_Returns_View_With_Model() | ||
{ | ||
_memberService.Get(1).Returns(new Member()); | ||
_campaignService.AllOpen().Returns(new List<Campaign>()); | ||
|
||
var controller = new MemberController(_donationsService, _memberService, _campaignService); | ||
var result = controller.Donate(1); | ||
|
||
result.AssertViewRendered().WithViewData<Donation>(); | ||
} | ||
|
||
[Test] | ||
public void QuickDonation_Action_RedirectsToAction() | ||
{ | ||
_donationsService.QuickDonation(new Donation()); | ||
|
||
var controller = new MemberController(_donationsService, _memberService, _campaignService); | ||
var result = controller.SaveDonation(new Donation()); | ||
|
||
result.AssertActionRedirect().ToAction("Index"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters