Skip to content

Commit

Permalink
Added Tests project
Browse files Browse the repository at this point in the history
  • Loading branch information
David Kennedy committed Jun 15, 2012
1 parent f7b2d21 commit fa065c9
Show file tree
Hide file tree
Showing 20 changed files with 27,140 additions and 0 deletions.
@@ -0,0 +1,70 @@
<?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)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{CC8A4376-DCDD-4CDA-98C5-F9097C7AC8CF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CastleFluentNHibernateMvc3.Tests</RootNamespace>
<AssemblyName>CastleFluentNHibernateMvc3.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.0.12054\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\HomeControllerTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CastleFluentNHibernateMvc3\CastleFluentNHibernateMvc3.csproj">
<Project>{17C8E6FF-7F3C-4DD6-9DD1-6B6FEF3D1F48}</Project>
<Name>CastleFluentNHibernateMvc3</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>
134 changes: 134 additions & 0 deletions CastleFluentNHibernateMvc3.Tests/Controllers/HomeControllerTest.cs
@@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web.Mvc;

using CastleFluentNHibernateMvc3.Controllers;
using CastleFluentNHibernateMvc3.Models;
using CastleFluentNHibernateMvc3.Repositories;
using Moq;
using NUnit.Framework;

namespace CastleFluentNHibernateMvc3.Tests.Controllers
{
[TestFixture]
public class HomeControllerTest
{
private Mock<IRepository<Store>> storeRepositoryMock;

public HomeControllerTest()
{
storeRepositoryMock = new Mock<IRepository<Store>>();
}

public HomeController GetHomeController()
{
var controller = new HomeController( storeRepositoryMock.Object );

return controller;
}

[Test]
public void Index()
{
// Arrange
var controller = GetHomeController();

var stores = new List<Store>();

storeRepositoryMock.Setup( s => s.GetAll() )
.Returns( stores.AsQueryable() )
.Verifiable();

// Act
var result = controller.Index();

// Assert
storeRepositoryMock.Verify();

Assert.IsInstanceOf<ViewResult>( result );
}

[Test]
public void Test()
{
// Arrange
var controller = GetHomeController();

var store = new Store
{
Name = "Bargin Basin"
};
var stores = new List<Store>
{
store
};

storeRepositoryMock.Setup( s => s.Get( It.IsAny<Expression<Func<Store, bool>>>() ) )
.Returns( stores.AsQueryable() )
.Verifiable();

// Act
var result = controller.Test();

// Assert
storeRepositoryMock.Verify();

Assert.IsInstanceOf<RedirectToRouteResult>( result );
Assert.AreEqual( store.Name, "Bargain Basin" );
}

[Test]
public void Test_NotFound()
{
// Arrange
var controller = GetHomeController();

var stores = new List<Store>();

storeRepositoryMock.Setup( s => s.Get( It.IsAny<Expression<Func<Store, bool>>>() ) )
.Returns( stores.AsQueryable() )
.Verifiable();

// Act
var result = controller.Test();

// Assert
storeRepositoryMock.Verify();

Assert.IsInstanceOf<RedirectToRouteResult>( result );
}

[Test]
public void Seed()
{
// Arrange
var controller = GetHomeController();

var stores = new List<Store>
{
new Store
{
Name = "Foo Foundry"
},
new Store
{
Name = "Bar Bohemia"
}
};

storeRepositoryMock.Setup( s => s.SaveOrUpdateAll( It.IsAny<Store>(), It.IsAny<Store>() ) )
.Returns( stores.AsEnumerable() )
.Verifiable();

// Act
var result = controller.Seed();

// Assert
storeRepositoryMock.Verify();

Assert.IsInstanceOf<RedirectToRouteResult>( result );
}
}
}
36 changes: 36 additions & 0 deletions CastleFluentNHibernateMvc3.Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle( "CastleFluentNHibernateMvc3.Tests" )]
[assembly: AssemblyDescription( "" )]
[assembly: AssemblyConfiguration( "" )]
[assembly: AssemblyCompany( "Microsoft" )]
[assembly: AssemblyProduct( "CastleFluentNHibernateMvc3.Tests" )]
[assembly: AssemblyCopyright( "Copyright © Microsoft 2012" )]
[assembly: AssemblyTrademark( "" )]
[assembly: AssemblyCulture( "" )]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible( false )]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid( "9e8742e7-b01c-48b5-b152-13cfd338cc0c" )]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion( "1.0.0.0" )]
[assembly: AssemblyFileVersion( "1.0.0.0" )]
5 changes: 5 additions & 0 deletions CastleFluentNHibernateMvc3.Tests/packages.config
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Moq" version="4.0.10827" />
<package id="NUnit" version="2.6.0.12054" />
</packages>
6 changes: 6 additions & 0 deletions CastleFluentNHibernateMvc3.sln
Expand Up @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CastleFluentNHibernateMvc3", "CastleFluentNHibernateMvc3\CastleFluentNHibernateMvc3.csproj", "{17C8E6FF-7F3C-4DD6-9DD1-6B6FEF3D1F48}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CastleFluentNHibernateMvc3.Tests", "CastleFluentNHibernateMvc3.Tests\CastleFluentNHibernateMvc3.Tests.csproj", "{CC8A4376-DCDD-4CDA-98C5-F9097C7AC8CF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -13,6 +15,10 @@ Global
{17C8E6FF-7F3C-4DD6-9DD1-6B6FEF3D1F48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17C8E6FF-7F3C-4DD6-9DD1-6B6FEF3D1F48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17C8E6FF-7F3C-4DD6-9DD1-6B6FEF3D1F48}.Release|Any CPU.Build.0 = Release|Any CPU
{CC8A4376-DCDD-4CDA-98C5-F9097C7AC8CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC8A4376-DCDD-4CDA-98C5-F9097C7AC8CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC8A4376-DCDD-4CDA-98C5-F9097C7AC8CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC8A4376-DCDD-4CDA-98C5-F9097C7AC8CF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
39 changes: 39 additions & 0 deletions packages/Moq.4.0.10827/License.txt
@@ -0,0 +1,39 @@
Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD
http://code.google.com/p/moq/
All rights reserved.

Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the following conditions are met:

* Redistributions of source code must retain the
above copyright notice, this list of conditions and
the following disclaimer.

* Redistributions in binary form must reproduce
the above copyright notice, this list of conditions
and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the
names of its contributors may be used to endorse
or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

[This is the BSD license, see
http://www.opensource.org/licenses/bsd-license.php]
Binary file added packages/Moq.4.0.10827/Moq.4.0.10827.nupkg
Binary file not shown.
Binary file added packages/Moq.4.0.10827/Moq.chm
Binary file not shown.
Binary file added packages/Moq.4.0.10827/lib/NET35/Moq.dll
Binary file not shown.

0 comments on commit fa065c9

Please sign in to comment.