Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…runk@1668 d7b3437e-3345-0410-94a8-cbd290e69f67
  • Loading branch information
felpo committed Mar 25, 2011
1 parent 5edbfd5 commit ecf9bbd
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="keymanytoone.hbm.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Complexmapwithkeymanytoone.hbm.xml">
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<StartProgram>C:\Program Files (x86)\NUnit 2.5.3\bin\net-2.0\nunit.exe</StartProgram>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<StartAction>Project</StartAction>
<StartProgram>C:\Program Files\NUnit 2.5\bin\net-2.0\nunit.exe</StartProgram>
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files (x86)\NUnit 2.5.3\bin\net-2.0\nunit.exe</StartProgram>
</PropertyGroup>
<PropertyGroup>
<PublishUrlHistory />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,45 @@ public void Map()
CheckMappingAgainstCode(asm, mappingFile.FullName);

}

[Test]

public void KeyManyToOne()
{

FileInfo configFile = new FileInfo(Path.GetTempFileName());

// the mapping file needs to be written to the same
// directory as the config file for this test
string hbm = "keymanytoone.hbm.xml";
FileInfo mappingFile = new FileInfo(Path.Combine(configFile.DirectoryName, hbm));
if (mappingFile.Exists)
mappingFile.Delete();
ResourceHelper.WriteToFileFromResource(mappingFile, hbm);

TestHelper.CreateConfigFile(configFile, TestHelper.T4DefaultTemplate, TestHelper.T4Renderer, "unused", "clazz.GeneratedName+\".generated.cs\"");

// ensure that test is setup correctly
Assert.IsTrue(configFile.Exists && configFile.Length != 0);
Assert.IsTrue(mappingFile.Exists && mappingFile.Length != 0);
Assert.AreEqual(mappingFile.DirectoryName, configFile.DirectoryName);

string[] args = new string[] { "--config=" + configFile.FullName, mappingFile.FullName };
CodeGenerator.Generate(args, this);


Assembly asm = AssertedCompileGeneratedFiles("KMTONE");
try
{
CheckMappingAgainstCode(asm, mappingFile.FullName);
}
catch (Exception e)
{
Assert.AreEqual(e.InnerException.Message, "composite-id class must override Equals(): Eg.Cat");
}

}

[Test]
public void Set()
{
Expand All @@ -188,7 +227,9 @@ public void Set()


Assembly asm = AssertedCompileGeneratedFiles("Set");
CheckMappingAgainstCode(asm, mappingFile.FullName);

CheckMappingAgainstCode(asm, mappingFile.FullName);


}
[Test]
Expand Down Expand Up @@ -415,6 +456,37 @@ public void ComplexMap()

}

[Test]
public void ComplexMapWithKeyManyToOne()
{

FileInfo configFile = new FileInfo(Path.GetTempFileName());

// the mapping file needs to be written to the same
// directory as the config file for this test
string hbm = "Complexmapwithkeymanytoone.hbm.xml";
FileInfo mappingFile = new FileInfo(Path.Combine(configFile.DirectoryName, hbm));
if (mappingFile.Exists)
mappingFile.Delete();
ResourceHelper.WriteToFileFromResource(mappingFile, hbm);

TestHelper.CreateConfigFile(configFile, TestHelper.T4DefaultTemplate, TestHelper.T4Renderer, "unused", "clazz.GeneratedName+\".generated.cs\"");

// ensure that test is setup correctly
Assert.IsTrue(configFile.Exists && configFile.Length != 0);
Assert.IsTrue(mappingFile.Exists && mappingFile.Length != 0);
Assert.AreEqual(mappingFile.DirectoryName, configFile.DirectoryName);

string[] args = new string[] { "--config=" + configFile.FullName, mappingFile.FullName };
CodeGenerator.Generate(args, this);


Assembly asm = AssertedCompileGeneratedFiles("ComplexMapKM2N");
CheckMappingAgainstCode(asm, mappingFile.FullName);

}


[Test(Description = "mapping example from:http://ayende.com/Blog/archive/2009/04/11/nhibernate-mapping-ltdynamic-componentgt.aspx")]
public void DynamicComponent()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<id name="Id">
<generator class="hilo"/>
</id>

<map name="ComplexFavoritePlaces" table="UsersComplexFavoritePlaces" >
<key column="UserId"/>
<composite-index class="FavPlaceKey">
Expand All @@ -18,5 +19,14 @@
<property name="Lat"/>
</composite-element>
</map>




</class>
<class name="Boo">
<id name="Id" type="Int32">
<generator class="native"></generator>
</id>
</class>
</hibernate-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,8 @@ protected internal virtual void InitWith(string classPackage, ClassName mySuperC
//implementEquals();
propertyList.AddAll(0, cmpid.SelectNodes("urn:key-property", CodeGenerator.nsmgr));
manyToOneList.AddAll(0, cmpid.SelectNodes("urn:key-many-to-one", CodeGenerator.nsmgr));
ImplementEquals();
if( manyToOneList.Count == 0 )
ImplementEquals();
}
else
{
Expand Down

0 comments on commit ecf9bbd

Please sign in to comment.