Permalink
Browse files

Copy initial test case from NHibernate

  • Loading branch information...
hazzik committed Jun 24, 2012
1 parent 14efcc0 commit 339fbfc8d339a4e8005a278b0fb6669ecdcdf355
@@ -0,0 +1,10 @@
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH0000
+{
+ class Entity
+ {
+ public virtual Guid Id { get; set; }
+ public virtual string Name { get; set; }
+ }
+}
@@ -0,0 +1,52 @@
+using System.Linq;
+using NHibernate.Linq;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH0000
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ protected override void OnSetUp()
+ {
+ using (var session = OpenSession())
+ using (var transaction = session.BeginTransaction())
+ {
+ var e1 = new Entity {Name = "Bob"};
+ session.Save(e1);
+
+ var e2 = new Entity {Name = "Sally"};
+ session.Save(e2);
+
+ session.Flush();
+ transaction.Commit();
+ }
+ }
+
+ protected override void OnTearDown()
+ {
+ using (var session = OpenSession())
+ using (var transaction = session.BeginTransaction())
+ {
+ session.Delete("from System.Object");
+
+ session.Flush();
+ transaction.Commit();
+ }
+ }
+
+ [Test]
+ public void YourTestName()
+ {
+ using (var session = OpenSession())
+ using (session.BeginTransaction())
+ {
+ var entities = (from e in session.Query<Entity>()
+ where e.Name == "Bob"
+ select e).ToList();
+
+ Assert.AreEqual(1, entities.Count);
+ }
+ }
+ }
+}
@@ -0,0 +1,73 @@
+using System.Linq;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Linq;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH0000
+{
+ /// <summary>
+ /// Fixture using 'by code' mappings
+ /// </summary>
+ /// <remarks>
+ /// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entity" /> mapping is performed
+ /// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach
+ /// if you prefer.
+ /// </remarks>
+ public class FixtureByCode : TestCaseMappingByCode
+ {
+ protected override HbmMapping GetMappings()
+ {
+ var mapper = new ModelMapper();
+ mapper.Class<Entity>(rc =>
+ {
+ rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
+ rc.Property(x => x.Name);
+ });
+
+ return mapper.CompileMappingForAllExplicitlyAddedEntities();
+ }
+
+ protected override void OnSetUp()
+ {
+ using (var session = OpenSession())
+ using (var transaction = session.BeginTransaction())
+ {
+ var e1 = new Entity { Name = "Bob" };
+ session.Save(e1);
+
+ var e2 = new Entity { Name = "Sally" };
+ session.Save(e2);
+
+ session.Flush();
+ transaction.Commit();
+ }
+ }
+
+ protected override void OnTearDown()
+ {
+ using (var session = OpenSession())
+ using (var transaction = session.BeginTransaction())
+ {
+ session.Delete("from System.Object");
+
+ session.Flush();
+ transaction.Commit();
+ }
+ }
+
+ [Test]
+ public void YourTestName()
+ {
+ using (var session = OpenSession())
+ using (session.BeginTransaction())
+ {
+ var entities = (from e in session.Query<Entity>()
+ where e.Name == "Bob"
+ select e).ToList();
+
+ Assert.AreEqual(1, entities.Count);
+ }
+ }
+ }
+}
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH0000">
+
+ <class name="Entity">
+ <id name="Id" generator="guid.comb" />
+ <property name="Name" />
+ </class>
+
+</hibernate-mapping>
@@ -1,22 +0,0 @@
-
-
-namespace NHibernate.Test.NHSpecificTest.NH1234
-{
- public class DomainClass
- {
- private byte[] byteData;
- private int id;
-
- public int Id
- {
- get { return id; }
- set { id = value; }
- }
-
- public byte[] ByteData
- {
- get { return byteData; }
- set { byteData = value; }
- }
- }
-}
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
- namespace="NHibernate.Test.NHSpecificTest.NH1234" default-access="field.camelcase"
- default-lazy="false">
- <class name="DomainClass">
- <id name="Id">
- <generator class="assigned" />
- </id>
- <property name="ByteData" />
- </class>
-</hibernate-mapping>
@@ -1,56 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Text;
-using NHibernate.Dialect;
-using NUnit.Framework;
-
-namespace NHibernate.Test.NHSpecificTest.NH1234
-{
- [TestFixture]
- public class SampleTest : BugTestCase
- {
- protected override void OnSetUp()
- {
- base.OnSetUp();
- using (ISession session = this.OpenSession())
- {
- DomainClass entity = new DomainClass();
- entity.Id = 1;
- entity.ByteData = new byte[] {1, 2, 3};
- session.Save(entity);
- session.Flush();
- }
- }
-
- protected override void OnTearDown()
- {
- base.OnTearDown();
- using (ISession session = this.OpenSession())
- {
- string hql = "from System.Object";
- session.Delete(hql);
- session.Flush();
- }
- }
-
- protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect)
- {
- return dialect as MsSql2005Dialect != null;
- }
-
- [Test]
- public void BytePropertyShouldBeRetrievedCorrectly()
- {
- using (ISession session = this.OpenSession())
- {
- DomainClass entity = session.Get<DomainClass>(1);
-
- Assert.AreEqual(3, entity.ByteData.Length);
- Assert.AreEqual(1, entity.ByteData[0]);
- Assert.AreEqual(2, entity.ByteData[1]);
- Assert.AreEqual(3, entity.ByteData[2]);
- }
- }
- }
-}
@@ -86,10 +86,12 @@
<ItemGroup>
<Compile Include="DebugConnectionProvider.cs" />
<Compile Include="NHSpecificTest\BugTestCase.cs" />
- <Compile Include="NHSpecificTest\NH1234\DomainClass.cs" />
- <Compile Include="NHSpecificTest\NH1234\SampleTest.cs" />
+ <Compile Include="NHSpecificTest\NH0000\Entity.cs" />
+ <Compile Include="NHSpecificTest\NH0000\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH0000\FixtureByCode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestCase.cs" />
+ <Compile Include="TestCaseMappingByCode.cs" />
<Compile Include="TestConfigurationHelper.cs" />
<Compile Include="TestDialect.cs" />
</ItemGroup>
@@ -99,9 +101,6 @@
<ItemGroup>
<Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" />
</ItemGroup>
- <ItemGroup>
- <EmbeddedResource Include="NHSpecificTest\NH1234\Mappings.hbm.xml" />
- </ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
@@ -123,6 +122,7 @@
<Content Include="hibernate.cfg.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <EmbeddedResource Include="NHSpecificTest\NH0000\Mappings.hbm.xml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
View
@@ -0,0 +1,25 @@
+using System.Collections;
+using NHibernate.Cfg.MappingSchema;
+
+namespace NHibernate.Test
+{
+ public abstract class TestCaseMappingByCode : TestCase
+ {
+ protected override IList Mappings
+ {
+ get { return new string[0]; }
+ }
+
+ protected override string MappingsAssembly
+ {
+ get { return null; }
+ }
+
+ protected override void AddMappings(Cfg.Configuration configuration)
+ {
+ configuration.AddDeserializedMapping(GetMappings(), "TestDomain");
+ }
+
+ protected abstract HbmMapping GetMappings();
+ }
+}

0 comments on commit 339fbfc

Please sign in to comment.