Skip to content
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

Unit Tests for MemberController #15

Merged
merged 2 commits into from
Oct 26, 2011
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
163 changes: 82 additions & 81 deletions src/GiveCRM.Web.Tests/GiveCRM.Web.Tests.csproj
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 src/GiveCRM.Web.Tests/controllers/MemberController.Tests.cs
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");
}
}
}
64 changes: 32 additions & 32 deletions src/GiveCRM.Web.Tests/controllers/SetUpController.Tests.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
using System.Collections.Generic;
using GiveCRM.Models;
using System.Collections.Generic;
using GiveCRM.Models;
using GiveCRM.Web.Controllers;
using GiveCRM.Web.Models.Facets;
using GiveCRM.Web.Services;
using MvcContrib.TestHelper;
using NSubstitute;
using NUnit.Framework;

namespace GiveCRM.Web.Tests.controllers
{
[TestFixture]
public class SetUpControllerTests
using GiveCRM.Web.Services;
using MvcContrib.TestHelper;
using NSubstitute;
using NUnit.Framework;
namespace GiveCRM.Web.Tests.controllers
{
[TestFixture]
public class SetUpControllerTests
{
private IFacetsService _facetService;

[SetUp]
private IFacetsService _facetService;
[SetUp]
public void SetUp()
{
_facetService = Substitute.For<IFacetsService>();
}

[Test]
}
[Test]
public void Index_Action_Returns_View()
{
var controller = new SetupController(_facetService);
var result = controller.Index();

result.AssertViewRendered();
}

[Test]
}
[Test]
public void AddFacet_Action_Returns_View_With_A_Facet()
{
var controller = new SetupController(_facetService);
var result = controller.AddFacet();

result.AssertViewRendered().ForView("EditFacet").WithViewData<Facet>();
}

[Test]
}
[Test]
public void EditFacet_Action_Returns_View_With_A_Facet()
{
_facetService.Get(1).Returns(new Facet());
Expand All @@ -47,9 +47,9 @@ public void EditFacet_Action_Returns_View_With_A_Facet()
var result = controller.AddFacet();

result.AssertViewRendered().ForView("EditFacet").WithViewData<Facet>();
}

[Test]
}
[Test]
public void SaveFacet_Action_With_New_Facet_Inserts_And_Redirects_To_Action()
{
_facetService.Insert(new Facet());
Expand All @@ -72,9 +72,9 @@ public void SaveFacet_Action_With_Exsting_Facet_Inserts_And_Redirects_To_Action(
});

result.AssertActionRedirect();
}

[Test]
}
[Test]
public void ListFacets_Action_Returns_View_With_A_ViewModel()
{
_facetService.All().Returns(new List<Facet>());
Expand All @@ -83,6 +83,6 @@ public void ListFacets_Action_Returns_View_With_A_ViewModel()
var result = controller.ListFacets();

result.AssertViewRendered().WithViewData<FacetListViewModel>();
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/GiveCRM.Web/Controllers/MemberController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public MemberController(IDonationsService donationsService, IMemberService membe

public ActionResult Index()
{
return View("Index");
return View();
}

public ActionResult Add()
Expand Down