Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add tests to Create DB and scripts

These tests were quite handy for quickly generating the schema script and had been removed at some point, adding them again.
  • Loading branch information...
commit 03719c0a69cda52b842d51b98c58d1e22e10be22 1 parent b23c08d
@seif seif authored
View
1  Database/_placeholder.txt
@@ -0,0 +1 @@
+
View
84 .../SharpArchTemplate.Tests/SharpArchTemplate.Data/NHibernateMaps/MappingIntegrationTests.cs
@@ -0,0 +1,84 @@
+namespace SharpArchTemplate.Tests.SharpArchTemplate.Data.NHibernateMaps
+{
+ using System.IO;
+
+ using NHibernate;
+ using NHibernate.Cfg;
+ using NHibernate.Tool.hbm2ddl;
+
+ using NUnit.Framework;
+
+ using SharpArch.NHibernate;
+ using SharpArch.Testing.NUnit.NHibernate;
+
+ using global::SharpArchTemplate.Infrastructure.NHibernateMaps;
+
+ /// <summary>
+ /// Provides a means to verify that the target database is in compliance with all mappings.
+ /// Taken from http://ayende.com/Blog/archive/2006/08/09/NHibernateMappingCreatingSanityChecks.aspx.
+ ///
+ /// If this is failing, the error will likely inform you that there is a missing table or column
+ /// which needs to be added to your database.
+ /// </summary>
+ [TestFixture]
+ [Category("DB Tests")]
+ public class MappingIntegrationTests
+ {
+ private Configuration configuration;
+
+ [SetUp]
+ public virtual void SetUp()
+ {
+ string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
+ this.configuration = NHibernateSession.Init(
+ new SimpleSessionStorage(),
+ mappingAssemblies,
+ new AutoPersistenceModelGenerator().Generate(),
+ "../../../../Solutions/SharpArchTemplate.Web.Mvc/NHibernate.config");
+ }
+
+ [TearDown]
+ public virtual void TearDown()
+ {
+ NHibernateSession.CloseAllSessions();
+ NHibernateSession.Reset();
+ }
+
+ [Test]
+ public void CanConfirmDatabaseMatchesMappings()
+ {
+ var allClassMetadata = NHibernateSession.GetDefaultSessionFactory().GetAllClassMetadata();
+
+ foreach (var entry in allClassMetadata)
+ {
+ NHibernateSession.Current.CreateCriteria(entry.Value.GetMappedClass(EntityMode.Poco))
+ .SetMaxResults(0).List();
+ }
+ }
+
+ /// <summary>
+ /// Generates and outputs the database schema SQL to the console
+ /// </summary>
+ [Test]
+ public void CanGenerateDatabaseSchema()
+ {
+ var session = NHibernateSession.GetDefaultSessionFactory().OpenSession();
+
+ using (TextWriter stringWriter = new StreamWriter("../../../../Database/UnitTestGeneratedSchema.sql"))
+ {
+ new SchemaExport(this.configuration).Execute(true, false, false, session.Connection, stringWriter);
+ }
+ }
+
+ /// <summary>
+ /// Creates/Updates database schema, this runs on database configured in
+ /// Mvc project and is marked as Explicit because it changes the database.
+ /// </summary>
+ [Test]
+ [Explicit]
+ public void CanCreateDatabase()
+ {
+ new SchemaExport(this.configuration).Execute(false, true, false);
+ }
+ }
+}
View
5 Solutions/SharpArchTemplate.Tests/SharpArchTemplate.Tests.csproj
@@ -87,12 +87,17 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceLocatorInitializer.cs" />
+ <Compile Include="SharpArchTemplate.Data\NHibernateMaps\MappingIntegrationTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SharpArchTemplate.Domain\SharpArchTemplate.Domain.csproj">
<Project>{8DEF56CD-601E-443C-9DCE-C4EC54C0B6A6}</Project>
<Name>SharpArchTemplate.Domain</Name>
</ProjectReference>
+ <ProjectReference Include="..\SharpArchTemplate.Infrastructure\SharpArchTemplate.Infrastructure.csproj">
+ <Project>{9544D94B-9B6E-4B61-8A09-88382205BF86}</Project>
+ <Name>SharpArchTemplate.Infrastructure</Name>
+ </ProjectReference>
<ProjectReference Include="..\SharpArchTemplate.Web.Mvc\SharpArchTemplate.Web.Mvc.csproj">
<Project>{6F92992D-8D75-4BA8-87C3-146581235054}</Project>
<Name>SharpArchTemplate.Web.Mvc</Name>
Please sign in to comment.
Something went wrong with that request. Please try again.