Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Created fix for Rearrange tests projects https://github.com/sharparchitecture/Sharp-Architecture/issues/16 #19

Merged
merged 1 commit into from

2 participants

Vitaliy K Geoffrey Smith
Vitaliy K

No description provided.

Geoffrey Smith geoffreysmith merged commit af80310 into from
Geoffrey Smith

Thanks! First time I tried automatic merge, let's how it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 18, 2011
  1. Vitaliy K

    Rearranged Test project, fixes #16.

    shatl authored
This page is out of date. Refresh to see the latest.
2  Common/AssemblyVersion.cs
View
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:4.0.30319.225
+// Runtime Version:4.0.30319.235
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
2  Solutions/SharpArch.Specifications/SharpArch.Domain/DomainModel/EntityWithTypedIdSpecs.cs
View
@@ -15,10 +15,10 @@ namespace SharpArch.Specifications.SharpArch.Domain.DomainModel
using System.Reflection;
using global::SharpArch.Domain.DomainModel;
+ using global::SharpArch.Testing.NUnit.Helpers;
using Machine.Specifications;
- using Tests.SharpArch.Domain;
public class entity_with_type_id_specs
{
6 Solutions/SharpArch.Specifications/SharpArch.Specifications.csproj
View
@@ -95,9 +95,9 @@
<Project>{0BD77F13-8DF6-4C16-9508-33AA4CF0677A}</Project>
<Name>SharpArch.NHibernate</Name>
</ProjectReference>
- <ProjectReference Include="..\SharpArch.Tests\SharpArch.Tests.csproj">
- <Project>{C201296D-09B7-4BAE-96F0-AB59F624DB36}</Project>
- <Name>SharpArch.Tests</Name>
+ <ProjectReference Include="..\SharpArch.Testing.NUnit\SharpArch.Testing.NUnit.csproj">
+ <Project>{D6DDE603-4678-44B9-A2D1-101BF5D12AD7}</Project>
+ <Name>SharpArch.Testing.NUnit</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6 ...harpArch.Tests/SharpArch.Domain/EntityIdSetter.cs → ...SharpArch.Testing.NUnit/Helpers/EntityIdSetter.cs
View
@@ -1,9 +1,9 @@
-namespace Tests.SharpArch.Domain
+namespace SharpArch.Testing.NUnit.Helpers
{
using System.Reflection;
- using global::SharpArch.Domain;
- using global::SharpArch.Domain.DomainModel;
+ using SharpArch.Domain;
+ using SharpArch.Domain.DomainModel;
/// <summary>
/// For better data integrity, it is imperitive that the <see cref = "Entity.Id" />
2  Solutions/SharpArch.Testing.NUnit/NHibernate/DatabaseRepositoryTestsBase.cs
View
@@ -4,8 +4,6 @@
using SharpArch.NHibernate;
- using Tests.SharpArch.NHibernate;
-
/// <summary>
/// Initiates a transaction before each test is run and rolls back the transaction after
/// the test completes. Consequently, tests make no permanent changes to the DB.
2  Solutions/SharpArch.Testing.NUnit/NHibernate/RepositoryBehaviorSpecificationTestsBase.cs
View
@@ -2,8 +2,6 @@
{
using global::NUnit.Framework;
- using Tests.SharpArch.NHibernate;
-
/// <summary>
/// Provides a behavior driven approach to unit testsing data persisted to a database.
/// This base class creates the database from scratch using the specified connection details
2  Solutions/SharpArch.Testing.NUnit/NHibernate/RepositoryTestsBase.cs
View
@@ -2,8 +2,6 @@
{
using global::NUnit.Framework;
- using Tests.SharpArch.NHibernate;
-
/// <summary>
/// Provides a base class for running unit tests against an in-memory database created
/// during test execution. This builds the database using the connection details within
78 Solutions/SharpArch.Testing.NUnit/NHibernate/RepositoryTestsHelper.cs
View
@@ -0,0 +1,78 @@
+namespace SharpArch.Testing.NUnit.NHibernate
+{
+ using System;
+ using System.Configuration;
+ using System.Linq;
+ using System.Reflection;
+
+ using FluentNHibernate.Automapping;
+
+ using SharpArch.Domain;
+ using SharpArch.NHibernate;
+ using SharpArch.NHibernate.FluentNHibernate;
+
+ using global::NHibernate.Tool.hbm2ddl;
+
+ using Configuration = global::NHibernate.Cfg.Configuration;
+
+ /// <summary>
+ /// Provides helper methods for consolidating duplicated code from test fixture base classes.
+ /// </summary>
+ public class RepositoryTestsHelper
+ {
+ public static void FlushSessionAndEvict(object instance)
+ {
+ // Commits any changes up to this point to the database
+ NHibernateSession.Current.Flush();
+
+ // Evicts the instance from the current session so that it can be loaded during testing;
+ // this gives the test a clean slate, if you will, to work with
+ NHibernateSession.Current.Evict(instance);
+ }
+
+ public static AutoPersistenceModel GetAutoPersistenceModel(string[] assemblies)
+ {
+ return (from asmName in assemblies
+ select Assembly.Load(asmName)
+ into asm
+ from asmType in asm.GetTypes()
+ where typeof(IAutoPersistenceModelGenerator).IsAssignableFrom(asmType)
+ select Activator.CreateInstance(asmType) as IAutoPersistenceModelGenerator
+ into generator
+ select generator.Generate()).FirstOrDefault();
+ }
+
+ public static string[] GetMappingAssemblies()
+ {
+ var mappingAssembliesSetting = ConfigurationManager.AppSettings["nhibernate.mapping.assembly"];
+
+ Check.Require(
+ !string.IsNullOrEmpty(mappingAssembliesSetting),
+ "Please add an AppSetting to your app.config for 'nhibernate.mapping.assembly.' This setting " +
+ "takes a comma delimited list of assemblies containing NHibernate mapping files. Including '.dll' " +
+ "at the end of each is optional.");
+
+ return mappingAssembliesSetting.Split(',');
+ }
+
+ public static void InitializeDatabase()
+ {
+ var cfg = InitializeNHibernateSession();
+ var connection = NHibernateSession.Current.Connection;
+ new SchemaExport(cfg).Execute(false, true, false, connection, null);
+ }
+
+ public static Configuration InitializeNHibernateSession()
+ {
+ var mappingAssemblies = GetMappingAssemblies();
+ var autoPersistenceModel = GetAutoPersistenceModel(mappingAssemblies);
+ return NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies, autoPersistenceModel);
+ }
+
+ public static void Shutdown()
+ {
+ NHibernateSession.CloseAllSessions();
+ NHibernateSession.Reset();
+ }
+ }
+}
11 Solutions/SharpArch.Testing.NUnit/SharpArch.Testing.NUnit.csproj
View
@@ -67,6 +67,7 @@
<HintPath>..\..\ReferencedAssemblies\NUnit\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@@ -80,9 +81,11 @@
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="BehaviorSpecificationTestsBase.cs" />
+ <Compile Include="Helpers\EntityIdSetter.cs" />
<Compile Include="NHibernate\DatabaseRepositoryTestsBase.cs" />
<Compile Include="NHibernate\RepositoryBehaviorSpecificationTestsBase.cs" />
<Compile Include="NHibernate\RepositoryTestsBase.cs" />
+ <Compile Include="NHibernate\RepositoryTestsHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SyntaxHelpers.cs" />
</ItemGroup>
@@ -104,14 +107,14 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\SharpArch.Domain\SharpArch.Domain.csproj">
+ <Project>{E12E99BB-8732-441F-B3A6-861F0CE23D3D}</Project>
+ <Name>SharpArch.Domain</Name>
+ </ProjectReference>
<ProjectReference Include="..\SharpArch.NHibernate\SharpArch.NHibernate.csproj">
<Project>{0BD77F13-8DF6-4C16-9508-33AA4CF0677A}</Project>
<Name>SharpArch.NHibernate</Name>
</ProjectReference>
- <ProjectReference Include="..\SharpArch.Tests\SharpArch.Tests.csproj">
- <Project>{C201296D-09B7-4BAE-96F0-AB59F624DB36}</Project>
- <Name>SharpArch.Tests</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.
3  Solutions/SharpArch.Tests/SharpArch.Domain/DomainModel/BaseObjectEqualityComparerTests.cs
View
@@ -8,6 +8,9 @@ namespace Tests.SharpArch.Domain.DomainModel
using NUnit.Framework;
+ using global::SharpArch.Testing.NUnit;
+ using global::SharpArch.Testing.NUnit.Helpers;
+
[TestFixture]
public class BaseObjectEqualityComparerTests
{
3  Solutions/SharpArch.Tests/SharpArch.Domain/DomainModel/EntityTests.cs
View
@@ -4,6 +4,9 @@ namespace Tests.SharpArch.Domain.DomainModel
using NUnit.Framework;
+ using global::SharpArch.Testing.NUnit;
+ using global::SharpArch.Testing.NUnit.Helpers;
+
[TestFixture]
public class EntityTests
{
5 Solutions/SharpArch.Tests/SharpArch.Tests.csproj
View
@@ -147,7 +147,6 @@
<Compile Include="SharpArch.Domain\DomainModel\BaseObjectEqualityComparerTests.cs" />
<Compile Include="SharpArch.Domain\DomainModel\EntityTests.cs" />
<Compile Include="SharpArch.Domain\DomainModel\ValueObjectTests.cs" />
- <Compile Include="SharpArch.Domain\EntityIdSetter.cs" />
<Compile Include="SharpArch.NHibernate\NHibernateSessionTests.cs" />
<Compile Include="SharpArch.NHibernate\RepositoryTestsHelper.cs" />
<Compile Include="SharpArch.NHibernate\SafeServiceLocatorTests.cs" />
@@ -180,6 +179,10 @@
<Project>{0BD77F13-8DF6-4C16-9508-33AA4CF0677A}</Project>
<Name>SharpArch.NHibernate</Name>
</ProjectReference>
+ <ProjectReference Include="..\SharpArch.Testing.NUnit\SharpArch.Testing.NUnit.csproj">
+ <Project>{D6DDE603-4678-44B9-A2D1-101BF5D12AD7}</Project>
+ <Name>SharpArch.Testing.NUnit</Name>
+ </ProjectReference>
<ProjectReference Include="..\SharpArch.Web.Mvc\SharpArch.Web.Mvc.csproj">
<Project>{BF4E3D18-2EFB-49E3-9D8D-0F9F9BE1094A}</Project>
<Name>SharpArch.Web.Mvc</Name>
Something went wrong with that request. Please try again.