Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

start replacing magic strings with reflection (more to go)

  • Loading branch information...
commit 8dc71bfa204f9e050699e18f91f512b6874d85f2 1 parent e31485a
Cℓinton Sheppard handcraftsman authored
Showing with 1,203 additions and 93 deletions.
  1. +1 −1  Converter/ClassMapBody.cs
  2. +8 −0 Converter/Converter.csproj
  3. +1 −1  Converter/Extensions/CodeFileBuilderExtensions.cs
  4. +8 −0 Converter/FakeMap.cs
  5. +11 −1 Converter/Methods/Column.cs
  6. +27 −8 Converter/Methods/GeneratedBy.cs
  7. +34 −0 Converter/Methods/Index.cs
  8. +20 −3 Converter/Methods/Join/Cascade.cs
  9. +15 −2 Converter/Methods/Join/Inverse.cs
  10. +20 −3 Converter/Methods/Join/KeyColumn.cs
  11. +15 −2 Converter/Methods/Join/LazyLoad.cs
  12. +9 −1 Converter/Methods/Join/OrderBy.cs
  13. +13 −2 Converter/Methods/Join/Table.cs
  14. +11 −3 Converter/Methods/Join/Where.cs
  15. +11 −1 Converter/Methods/Length.cs
  16. +9 −3 Converter/Methods/Unique.cs
  17. +29 −0 Converter/Methods/UnsavedValue.cs
  18. +5 −0 Converter/NamedConstant.cs
  19. +38 −0 Converter/ReflectionUtility.cs
  20. +7 −0 Converter/Types/Id.cs
  21. +18 −1 ConverterTests/ConverterTests.csproj
  22. +51 −52 ConverterTests/Extensions/NHibernate/HbmIdExtensionsTests.cs
  23. +4 −5 ConverterTests/Extensions/NHibernate/HbmManyToOneExtensionsTests.cs
  24. +3 −3 ConverterTests/Extensions/NHibernate/HbmPropertyExtensionsTests.cs
  25. +1 −1  ConverterTests/{ → Extensions}/StringExtensionTests.cs
  26. +98 −0 ConverterTests/Methods/ColumnTests.cs
  27. +123 −0 ConverterTests/Methods/GeneratedByTests.cs
  28. +18 −0 ConverterTests/Methods/IndexTests.cs
  29. +61 −0 ConverterTests/Methods/Join/CascadeTests.cs
  30. +55 −0 ConverterTests/Methods/Join/InverseTests.cs
  31. +69 −0 ConverterTests/Methods/Join/KeyColumnTests.cs
  32. +64 −0 ConverterTests/Methods/Join/LazyLoadTests.cs
  33. +49 −0 ConverterTests/Methods/Join/OrderByTests.cs
  34. +49 −0 ConverterTests/Methods/Join/TableTests.cs
  35. +49 −0 ConverterTests/Methods/Join/WhereTests.cs
  36. +65 −0 ConverterTests/Methods/LengthTests.cs
  37. +68 −0 ConverterTests/Methods/UniqueTests.cs
  38. +66 −0 ConverterTests/Methods/UnsavedValueTests.cs
  39. BIN  WinForm/bin/Debug/FluentNHibernate.dll
  40. BIN  WinForm/bin/Debug/NHibernateHbmToFluent.Converter.dll
  41. BIN  WinForm/bin/Debug/NHibernateHbmToFluent.Converter.pdb
  42. BIN  WinForm/bin/Debug/NHibernateHbmToFluent.exe
  43. BIN  WinForm/bin/Debug/NHibernateHbmToFluent.pdb
  44. BIN  lib/FluentNHibernate.dll
2  Converter/ClassMapBody.cs
View
@@ -20,7 +20,7 @@ public void Add(string prefix, MappedPropertyInfo info)
new Length(_builder),
new Nullability(_builder),
new Unique(_builder),
- new GeneratedBy(_builder)
+ new Index(_builder)
};
GeneratedBy generatedBy = new GeneratedBy(_builder);
info.Type.StartMethod(prefix, _builder, info);
8 Converter/Converter.csproj
View
@@ -31,6 +31,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\lib\FluentNHibernate.dll</HintPath>
+ </Reference>
<Reference Include="JetBrains.Annotations, Version=4.5.1230.4, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\JetBrains.Annotations.dll</HintPath>
@@ -67,6 +71,10 @@
<Compile Include="MappedClassInfo.cs" />
<Compile Include="MappedPropertyInfo.cs" />
<Compile Include="MappingConverter.cs" />
+ <Compile Include="FakeMap.cs" />
+ <Compile Include="Methods\Index.cs" />
+ <Compile Include="Methods\UnsavedValue.cs" />
+ <Compile Include="ReflectionUtility.cs" />
<Compile Include="Types\Bag.cs" />
<Compile Include="Methods\Join\Cascade.cs" />
<Compile Include="ClassMapBody.cs" />
2  Converter/Extensions/CodeFileBuilderExtensions.cs
View
@@ -4,7 +4,7 @@ public static class CodeFileBuilderExtensions
{
public static void StartMethod(this CodeFileBuilder builder, string prefix, string methodBody)
{
- builder.AddLine(prefix+methodBody);
+ builder.AddLine(prefix + methodBody);
builder.Indent();
}
}
8 Converter/FakeMap.cs
View
@@ -0,0 +1,8 @@
+using FluentNHibernate.Mapping;
+
+namespace NHibernateHbmToFluent.Converter
+{
+ internal class FakeMap : ClassMap<string>
+ {
+ }
+}
12 Converter/Methods/Column.cs
View
@@ -1,3 +1,5 @@
+using FluentNHibernate.Mapping;
+
namespace NHibernateHbmToFluent.Converter.Methods
{
public class Column : ICommonMapMethod
@@ -20,7 +22,15 @@ public void Add(MappedPropertyInfo item)
}
if (item.ColumnName != null)
{
- _builder.AddLine(".Column(\"" + item.ColumnName + "\")");
+ _builder.AddLine(string.Format(".{0}(\"{1}\")", FluentNHibernateNames.Column, item.ColumnName));
+ }
+ }
+
+ public static class FluentNHibernateNames
+ {
+ public static string Column
+ {
+ get { return ReflectionUtility.GetMethodName((IdentityPart ip) => ip.Column(null)); }
}
}
}
35 Converter/Methods/GeneratedBy.cs
View
@@ -1,8 +1,9 @@
+using FluentNHibernate.Mapping;
using NHibernate.Cfg.MappingSchema;
namespace NHibernateHbmToFluent.Converter.Methods
{
- public class GeneratedBy : ICommonMapMethod
+ public class GeneratedBy
{
private readonly CodeFileBuilder _builder;
@@ -28,24 +29,42 @@ public void Add(MappedPropertyInfo info)
{
HbmParam[] parameters = generator.param;
string[] text = parameters[0].Text;
- _builder.AddLine(".GeneratedBy.Sequence(\"" + text[0] + "\")");
+ _builder.AddLine(string.Format(".{0}.{1}(\"{2}\")", FluentNHibernateNames.GeneratedBy, FluentNHibernateNames.Sequence, text[0]));
break;
}
case "assigned":
- _builder.AddLine(".GeneratedBy.Assigned()");
+ _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.GeneratedBy, FluentNHibernateNames.Assigned));
break;
case "native":
- _builder.AddLine(".GeneratedBy.Native()");
+ _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.GeneratedBy, FluentNHibernateNames.Native));
break;
default:
- _builder.AddLine(".GeneratedBy. ?");
+ _builder.AddLine(string.Format(".{0}. ?", FluentNHibernateNames.GeneratedBy));
break;
}
}
- if (id.unsavedvalue != null)
+ }
+
+ public static class FluentNHibernateNames
+ {
+ public static string GeneratedBy
+ {
+ get { return ReflectionUtility.GetPropertyName((IdentityPart ip) => ip.GeneratedBy); }
+ }
+
+ public static string Assigned
+ {
+ get { return ReflectionUtility.GetMethodName((IdentityPart ip) => ip.GeneratedBy.Assigned()); }
+ }
+
+ public static string Native
+ {
+ get { return ReflectionUtility.GetMethodName((IdentityPart ip) => ip.GeneratedBy.Native()); }
+ }
+
+ public static string Sequence
{
- var unsavedValue = id.unsavedvalue == "null" ? "String.Empty" : id.unsavedvalue;
- _builder.AddLine(".UnsavedValue(" + unsavedValue + ")");
+ get { return ReflectionUtility.GetMethodName((IdentityPart ip) => ip.GeneratedBy.Sequence(null)); }
}
}
}
34 Converter/Methods/Index.cs
View
@@ -0,0 +1,34 @@
+using FluentNHibernate.Mapping;
+
+namespace NHibernateHbmToFluent.Converter.Methods
+{
+ public class Index : ICommonMapMethod
+ {
+ private readonly CodeFileBuilder _builder;
+
+ public Index(CodeFileBuilder builder)
+ {
+ _builder = builder;
+ }
+
+ public void Add(MappedPropertyInfo info)
+ {
+ if (info.Type == PropertyMappingType.Id)
+ {
+ return;
+ }
+ if (info.UniqueIndex != null)
+ {
+ _builder.AddLine(string.Format(".{0}(\"{1}\")", FluentNHibernateNames.Index, info.UniqueIndex));
+ }
+ }
+
+ public static class FluentNHibernateNames
+ {
+ public static string Index
+ {
+ get { return ReflectionUtility.GetMethodName((PropertyPart ip) => ip.Index(null)); }
+ }
+ }
+ }
+}
23 Converter/Methods/Join/Cascade.cs
View
@@ -16,17 +16,34 @@ public void Add(string cascadeType)
switch (cascadeType)
{
case "save-update":
- _builder.AddLine(".Cascade.SaveUpdate()");
+ _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.Cascade, FluentNHibernateNames.SaveUpdate));
break;
case "none":
- _builder.AddLine(".Cascade.None()");
+ _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.Cascade, FluentNHibernateNames.None));
break;
default:
- _builder.AddLine(".Cascade.?");
+ _builder.AddLine(string.Format(".{0}.?", FluentNHibernateNames.Cascade));
break;
}
}
}
+ public static class FluentNHibernateNames
+ {
+ public static string Cascade
+ {
+ get { return ReflectionUtility.GetPropertyName((FakeMap f) => f.HasMany<string>(x => x.ToLower()).Cascade); }
+ }
+
+ public static string SaveUpdate
+ {
+ get { return ReflectionUtility.GetMethodName((FakeMap f) => f.HasMany<string>(x => x.ToLower()).Cascade.SaveUpdate()); }
+ }
+
+ public static string None
+ {
+ get { return ReflectionUtility.GetMethodName((FakeMap f) => f.HasMany<string>(x => x.ToLower()).Cascade.None()); }
+ }
+ }
}
}
17 Converter/Methods/Join/Inverse.cs
View
@@ -13,11 +13,24 @@ public void Add(bool inverse)
{
if (inverse)
{
- _builder.AddLine(".Inverse()");
+ _builder.AddLine(string.Format(".{0}()", FluentNHibernateNames.Inverse));
}
else
{
- _builder.AddLine(".Not.Inverse()");
+ _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.Not, FluentNHibernateNames.Inverse));
+ }
+ }
+
+ public static class FluentNHibernateNames
+ {
+ public static string Not
+ {
+ get { return ReflectionUtility.GetPropertyName((FakeMap f) => f.HasMany<string>(x => x.ToLower()).Not); }
+ }
+
+ public static string Inverse
+ {
+ get { return ReflectionUtility.GetMethodName((FakeMap f) => f.HasMany<string>(x => x.ToLower()).Inverse()); }
}
}
}
23 Converter/Methods/Join/KeyColumn.cs
View
@@ -15,18 +15,35 @@ public void Add(bool isInverse, string columnName, PropertyMappingType type)
{
if (isInverse)
{
- _builder.AddLine(".ChildKeyColumn(\"" + columnName + "\")");
+ _builder.AddLine(string.Format(".{0}(\"{1}\")", FluentNHibernateNames.ChildKeyColumn, columnName));
}
else
{
- _builder.AddLine(".ParentKeyColumn(\"" + columnName + "\")");
+ _builder.AddLine(string.Format(".{0}(\"{1}\")", FluentNHibernateNames.ParentKeyColumn, columnName));
}
}
else if (type == PropertyMappingType.OneToMany)
{
- _builder.AddLine(".KeyColumn(\"" + columnName + "\")");
+ _builder.AddLine(string.Format(".{0}(\"{1}\")", FluentNHibernateNames.KeyColumn, columnName));
}
}
+ public static class FluentNHibernateNames
+ {
+ public static string ChildKeyColumn
+ {
+ get { return ReflectionUtility.GetMethodName((FakeMap f) => f.HasManyToMany<string>(x => x.ToLower()).ChildKeyColumn(null)); }
+ }
+
+ public static string ParentKeyColumn
+ {
+ get { return ReflectionUtility.GetMethodName((FakeMap f) => f.HasManyToMany<string>(x => x.ToLower()).ParentKeyColumn(null)); }
+ }
+
+ public static string KeyColumn
+ {
+ get { return ReflectionUtility.GetMethodName((FakeMap f) => f.HasMany<string>(x => x.ToLower()).KeyColumn(null)); }
+ }
+ }
}
}
17 Converter/Methods/Join/LazyLoad.cs
View
@@ -17,13 +17,26 @@ public void Add(bool lazySpecified, HbmCollectionLazy lazy)
{
if (lazy == HbmCollectionLazy.False)
{
- _builder.AddLine(".Not.LazyLoad()");
+ _builder.AddLine(string.Format(".{0}.{1}()", FluentNHibernateNames.Not, FluentNHibernateNames.LazyLoad));
}
else
{
- _builder.AddLine(".LazyLoad()");
+ _builder.AddLine(string.Format(".{0}()", FluentNHibernateNames.LazyLoad));
}
}
}
+
+ public static class FluentNHibernateNames
+ {
+ public static string Not
+ {
+ get { return ReflectionUtility.GetPropertyName((FakeMap f) => f.HasManyToMany<string>(x => x.ToLower()).Not); }
+ }
+
+ public static string LazyLoad
+ {
+ get { return ReflectionUtility.GetMethodName((FakeMap f) => f.HasManyToMany<string>(x => x.ToLower()).LazyLoad()); }
+ }
+ }
}
}
10 Converter/Methods/Join/OrderBy.cs
View
@@ -13,7 +13,15 @@ public void Add(string orderBy)
{
if (orderBy != null)
{
- _builder.AddLine(".OrderBy(\"" + orderBy + "\")");
+ _builder.AddLine(string.Format(".{0}(\"{1}\")", FluentNHibernateNames.OrderBy, orderBy));
+ }
+ }
+
+ public static class FluentNHibernateNames
+ {
+ public static string OrderBy
+ {
+ get { return ReflectionUtility.GetMethodName((FakeMap f) => f.HasManyToMany<string>(x => x.ToLower()).OrderBy(null)); }
}
}
}
15 Converter/Methods/Join/Table.cs
View
@@ -9,9 +9,20 @@ public Table(CodeFileBuilder builder)
_builder = builder;
}
- public void Add(string table)
+ public void Add(string tableName)
{
- _builder.AddLine(".Table(\"" + table + "\")");
+ if (tableName != null)
+ {
+ _builder.AddLine(string.Format(".{0}(\"{1}\")", FluentNHibernateNames.Table, tableName));
+ }
+ }
+
+ public static class FluentNHibernateNames
+ {
+ public static string Table
+ {
+ get { return ReflectionUtility.GetMethodName((FakeMap f) => f.HasManyToMany<string>(x => x.ToLower()).Table(null)); }
+ }
}
}
}
14 Converter/Methods/Join/Where.cs
View
@@ -9,11 +9,19 @@ public Where(CodeFileBuilder builder)
_builder = builder;
}
- public void Add(string @where)
+ public void Add(string sqlWhereClause)
{
- if (@where != null)
+ if (sqlWhereClause != null)
{
- _builder.AddLine(".Where(x => x." + @where.Replace("'", "\"").Replace("=", "==") + ")");
+ _builder.AddLine(string.Format(".{0}(x => x.{1})", FluentNHibernateNames.Where, sqlWhereClause.Replace("'", "\"").Replace("=", "==")));
+ }
+ }
+
+ public static class FluentNHibernateNames
+ {
+ public static string Where
+ {
+ get { return ReflectionUtility.GetMethodName((FakeMap f) => f.HasManyToMany<string>(x => x.ToLower()).Where(x => 1 == 1)); }
}
}
}
12 Converter/Methods/Length.cs
View
@@ -1,3 +1,5 @@
+using FluentNHibernate.Mapping;
+
namespace NHibernateHbmToFluent.Converter.Methods
{
public class Length : ICommonMapMethod
@@ -17,7 +19,15 @@ public void Add(MappedPropertyInfo item)
}
if (item.MaxLength != null)
{
- _builder.AddLine(".Length(" + item.MaxLength + ")");
+ _builder.AddLine(string.Format(".{0}({1})", FluentNHibernateNames.Length, item.MaxLength));
+ }
+ }
+
+ public static class FluentNHibernateNames
+ {
+ public static string Length
+ {
+ get { return ReflectionUtility.GetMethodName((PropertyPart ip) => ip.Length(6)); }
}
}
}
12 Converter/Methods/Unique.cs
View
@@ -1,3 +1,5 @@
+using FluentNHibernate.Mapping;
+
namespace NHibernateHbmToFluent.Converter.Methods
{
public class Unique : ICommonMapMethod
@@ -17,11 +19,15 @@ public void Add(MappedPropertyInfo info)
}
if (info.IsUnique != null && info.IsUnique.Value)
{
- _builder.AddLine(".Unique()");
+ _builder.AddLine(string.Format(".{0}()", FluentNHibernateNames.Unique));
}
- if (info.UniqueIndex != null)
+ }
+
+ public static class FluentNHibernateNames
+ {
+ public static string Unique
{
- _builder.AddLine(".Index(\"" + info.UniqueIndex + "\")");
+ get { return ReflectionUtility.GetMethodName((PropertyPart ip) => ip.Unique()); }
}
}
}
29 Converter/Methods/UnsavedValue.cs
View
@@ -0,0 +1,29 @@
+using NHibernate.Cfg.MappingSchema;
+
+namespace NHibernateHbmToFluent.Converter.Methods
+{
+ public class UnsavedValue
+ {
+ private readonly CodeFileBuilder _builder;
+
+ public UnsavedValue(CodeFileBuilder builder)
+ {
+ _builder = builder;
+ }
+
+ public void Add(MappedPropertyInfo info)
+ {
+ if (info.Type != PropertyMappingType.Id)
+ {
+ return;
+ }
+
+ HbmId id = info.HbmObject<HbmId>();
+ if (id.unsavedvalue != null)
+ {
+ var unsavedValue = id.unsavedvalue == "null" ? "String.Empty" : id.unsavedvalue;
+ _builder.AddLine(".UnsavedValue(" + unsavedValue + ")");
+ }
+ }
+ }
+}
5 Converter/NamedConstant.cs
View
@@ -46,5 +46,10 @@ protected static T Get(string key)
{
return !(a == b);
}
+
+ public static IEnumerable<T> AllValues
+ {
+ get { return NamedConstants.Values; }
+ }
}
}
38 Converter/ReflectionUtility.cs
View
@@ -0,0 +1,38 @@
+using System;
+using System.Diagnostics;
+using System.Linq.Expressions;
+
+namespace NHibernateHbmToFluent.Converter
+{
+ public static class ReflectionUtility
+ {
+ [DebuggerStepThrough]
+ public static string GetMethodName<T, TReturn>(Expression<Func<T, TReturn>> expression)
+ {
+ var memberExpression = expression.Body as MethodCallExpression;
+ if (memberExpression == null)
+ {
+ throw new ArgumentException("expression must be in the form: (Foo instance) => instance.Method");
+ }
+ return memberExpression.Method.Name;
+ }
+
+ [DebuggerStepThrough]
+ public static string GetPropertyName<T, TReturn>(Expression<Func<T, TReturn>> expression)
+ {
+ MemberExpression memberExpression = expression.Body as MemberExpression;
+ if (memberExpression == null)
+ {
+ throw new ArgumentException(
+ "expression must be in the form: (Thing instance) => instance.Property[.Optional.Other.Properties.In.Chain]");
+ }
+ string name = memberExpression.Member.Name;
+ while (memberExpression.Expression as MemberExpression != null)
+ {
+ memberExpression = (MemberExpression) memberExpression.Expression;
+ name = memberExpression.Member.Name + "." + name;
+ }
+ return name;
+ }
+ }
+}
7 Converter/Types/Id.cs
View
@@ -1,19 +1,26 @@
using NHibernateHbmToFluent.Converter.Extensions;
+using NHibernateHbmToFluent.Converter.Methods;
namespace NHibernateHbmToFluent.Converter.Types
{
public class Id : IMapStart
{
private readonly CodeFileBuilder _builder;
+ private readonly GeneratedBy _generatedBy;
+ private readonly UnsavedValue _unsavedValue;
public Id(CodeFileBuilder builder)
{
_builder = builder;
+ _generatedBy = new GeneratedBy(_builder);
+ _unsavedValue = new UnsavedValue(_builder);
}
public void Start(string prefix, MappedPropertyInfo item)
{
_builder.StartMethod(prefix, "Id(x => x." + item.Name + ")");
+ _generatedBy.Add(item);
+ _unsavedValue.Add(item);
}
}
}
19 ConverterTests/ConverterTests.csproj
View
@@ -31,6 +31,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\lib\FluentNHibernate.dll</HintPath>
+ </Reference>
<Reference Include="JetBrains.Annotations, Version=4.5.1230.4, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\JetBrains.Annotations.dll</HintPath>
@@ -68,8 +72,21 @@
<Compile Include="Extensions\NHibernate\HbmPropertyExtensionsTests.cs" />
<Compile Include="Extensions\NHibernate\HbmSetExtensionsTests.cs" />
<Compile Include="MappedPropertyInfoTests.cs" />
+ <Compile Include="Methods\ColumnTests.cs" />
+ <Compile Include="Methods\IndexTests.cs" />
+ <Compile Include="Methods\Join\CascadeTests.cs" />
+ <Compile Include="Methods\GeneratedByTests.cs" />
+ <Compile Include="Methods\Join\InverseTests.cs" />
+ <Compile Include="Methods\Join\KeyColumnTests.cs" />
+ <Compile Include="Methods\Join\LazyLoadTests.cs" />
+ <Compile Include="Methods\Join\OrderByTests.cs" />
+ <Compile Include="Methods\Join\TableTests.cs" />
+ <Compile Include="Methods\LengthTests.cs" />
+ <Compile Include="Methods\UniqueTests.cs" />
+ <Compile Include="Methods\UnsavedValueTests.cs" />
+ <Compile Include="Methods\Join\WhereTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="StringExtensionTests.cs" />
+ <Compile Include="Extensions\StringExtensionTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Converter\Converter.csproj">
103 ConverterTests/Extensions/NHibernate/HbmIdExtensionsTests.cs
View
@@ -14,9 +14,9 @@ public void Should_get_the_correct_value()
{
const string expected = "FirstName";
HbmId id = new HbmId
- {
- name = expected
- };
+ {
+ name = expected
+ };
string result = id.GetPropertyName();
result.ShouldBeEqualTo(expected);
}
@@ -30,9 +30,9 @@ public void Should_get_the_correct_value()
{
const string expected = "System.String";
HbmId id = new HbmId
- {
- type1 = expected + ", mscorlib"
- };
+ {
+ type1 = expected + ", mscorlib"
+ };
string result = id.GetReturnType();
result.ShouldBeEqualTo(expected);
}
@@ -46,15 +46,15 @@ public void Should_get_the_correct_value_from_column()
{
const string expected = "VARCHAR2";
HbmId id = new HbmId
- {
- column = new[]
+ {
+ column = new[]
{
new HbmColumn
{
sqltype = expected
}
}
- };
+ };
string result = id.GetSqlType();
result.ShouldBeEqualTo(expected);
}
@@ -68,15 +68,15 @@ public void Should_get_the_correct_value_from_column_given_null_column()
{
const string expected = "FirstName";
HbmId id = new HbmId
- {
- column = new []
+ {
+ column = new[]
{
new HbmColumn
{
name = expected
}
}
- };
+ };
string result = id.GetColumnName();
result.ShouldBeEqualTo(expected);
}
@@ -90,9 +90,9 @@ public void Should_get_the_correct_value_from_length_if_not_null()
{
const int expected = 16;
HbmId id = new HbmId
- {
- length = expected.ToString()
- };
+ {
+ length = expected.ToString()
+ };
int? result = id.GetMaxLength();
result.ShouldNotBeNull();
result.Value.ShouldBeEqualTo(expected);
@@ -103,15 +103,15 @@ public void Should_get_the_correct_value_from_column_given_null_length()
{
const int expected = 16;
HbmId id = new HbmId
- {
- column = new []
+ {
+ column = new[]
{
new HbmColumn
{
length = expected.ToString()
}
}
- };
+ };
int? result = id.GetMaxLength();
result.ShouldNotBeNull();
result.Value.ShouldBeEqualTo(expected);
@@ -121,9 +121,9 @@ public void Should_get_the_correct_value_from_column_given_null_length()
public void Should_get_null_given_null_length_and_column_length()
{
HbmId id = new HbmId
- {
- column = new [] { new HbmColumn() }
- };
+ {
+ column = new[] {new HbmColumn()}
+ };
int? result = id.GetMaxLength();
result.ShouldBeNull();
}
@@ -137,15 +137,15 @@ public void Should_get_the_correct_value_from_column()
{
const string expected = "Name";
HbmId id = new HbmId
- {
- column = new []
+ {
+ column = new[]
{
new HbmColumn
{
index = expected
}
}
- };
+ };
string result = id.GetUniqueIndex();
result.ShouldNotBeNull();
result.ShouldBeEqualTo(expected);
@@ -155,9 +155,9 @@ public void Should_get_the_correct_value_from_column()
public void Should_get_null_given_null_index_and_column_index()
{
HbmId id = new HbmId
- {
- column = new [] { new HbmColumn() }
- };
+ {
+ column = new[] {new HbmColumn()}
+ };
string result = id.GetUniqueIndex();
result.ShouldBeNull();
}
@@ -170,9 +170,9 @@ public class When_asked_if_CanBeNull
public void Should_get_null_given_column_is_null()
{
HbmId id = new HbmId
- {
- column = null
- };
+ {
+ column = null
+ };
bool? result = id.CanBeNull();
result.ShouldBeNull();
}
@@ -181,15 +181,15 @@ public void Should_get_null_given_column_is_null()
public void Should_get_null_given_column_notnullSpecified_is_false()
{
HbmId id = new HbmId
- {
- column = new []
+ {
+ column = new[]
{
new HbmColumn
{
notnullSpecified = false
}
}
- };
+ };
bool? result = id.CanBeNull();
result.ShouldBeNull();
}
@@ -198,8 +198,8 @@ public void Should_get_null_given_column_notnullSpecified_is_false()
public void Should_get__true__given_column_notnullSpecified_is_true_and_notnull_is_false()
{
HbmId id = new HbmId
- {
- column = new []
+ {
+ column = new[]
{
new HbmColumn
{
@@ -207,7 +207,7 @@ public void Should_get__true__given_column_notnullSpecified_is_true_and_notnull_
notnull = false
}
}
- };
+ };
bool? result = id.CanBeNull();
result.ShouldNotBeNull();
result.Value.ShouldBeTrue();
@@ -217,8 +217,8 @@ public void Should_get__true__given_column_notnullSpecified_is_true_and_notnull_
public void Should_get__false__given_column_notnullSpecified_is_true_and_notnull_is_true()
{
HbmId id = new HbmId
- {
- column = new []
+ {
+ column = new[]
{
new HbmColumn
{
@@ -226,7 +226,7 @@ public void Should_get__false__given_column_notnullSpecified_is_true_and_notnull
notnull = true
}
}
- };
+ };
bool? result = id.CanBeNull();
result.ShouldNotBeNull();
result.Value.ShouldBeFalse();
@@ -240,9 +240,9 @@ public class When_asked_if_IsUnique
public void Should_get_null_given_column_is_null()
{
HbmId id = new HbmId
- {
- column = null
- };
+ {
+ column = null
+ };
bool? result = id.IsUnique();
result.ShouldBeNull();
}
@@ -251,15 +251,15 @@ public void Should_get_null_given_column_is_null()
public void Should_get_null_given_column_uniqueSpecified_is_false()
{
HbmId id = new HbmId
- {
- column = new []
+ {
+ column = new[]
{
new HbmColumn
{
uniqueSpecified = false
}
}
- };
+ };
bool? result = id.IsUnique();
result.ShouldBeNull();
}
@@ -268,8 +268,8 @@ public void Should_get_null_given_column_uniqueSpecified_is_false()
public void Should_get__true__given_column_uniqueSpecified_is_true_and_column_unique_is_true()
{
HbmId id = new HbmId
- {
- column = new []
+ {
+ column = new[]
{
new HbmColumn
{
@@ -277,7 +277,7 @@ public void Should_get__true__given_column_uniqueSpecified_is_true_and_column_un
unique = true
}
}
- };
+ };
bool? result = id.IsUnique();
result.ShouldNotBeNull();
result.Value.ShouldBeTrue();
@@ -287,8 +287,8 @@ public void Should_get__true__given_column_uniqueSpecified_is_true_and_column_un
public void Should_get__false__given_column_uniqueSpecified_is_true_and_column_unique_is_false()
{
HbmId id = new HbmId
- {
- column = new []
+ {
+ column = new[]
{
new HbmColumn
{
@@ -296,12 +296,11 @@ public void Should_get__false__given_column_uniqueSpecified_is_true_and_column_u
unique = false
}
}
- };
+ };
bool? result = id.IsUnique();
result.ShouldNotBeNull();
result.Value.ShouldBeFalse();
}
}
-
}
}
9 ConverterTests/Extensions/NHibernate/HbmManyToOneExtensionsTests.cs
View
@@ -281,7 +281,7 @@ public void Should_get__true__given_notnullSpecified_is_true_and_notnull_is_fals
result.Value.ShouldBeTrue();
}
- [Test, ExpectedException(typeof(NullReferenceException))]
+ [Test, ExpectedException(typeof (NullReferenceException))]
public void Should_get_exception_given_notnullSpecified_is_false_and_Items_is_null()
{
HbmManyToOne manyToOne = new HbmManyToOne
@@ -360,19 +360,18 @@ public void Should_get_the_correct_value_from_Items()
{
const string expected = "FirstName";
HbmManyToOne manyToOne = new HbmManyToOne
- {
- Items = new object[]
+ {
+ Items = new object[]
{
new HbmColumn
{
name = expected
}
}
- };
+ };
string result = manyToOne.GetColumnName();
result.ShouldBeEqualTo(expected);
}
}
-
}
}
6 ConverterTests/Extensions/NHibernate/HbmPropertyExtensionsTests.cs
View
@@ -46,9 +46,9 @@ public void Should_get_the_correct_value_from_column_if_not_null()
{
const string expected = "VARCHAR2";
HbmProperty property = new HbmProperty
- {
- column = expected
- };
+ {
+ column = expected
+ };
string result = property.GetSqlType();
result.ShouldBeEqualTo(expected);
}
2  ConverterTests/StringExtensionTests.cs → ConverterTests/Extensions/StringExtensionTests.cs
View
@@ -1,7 +1,7 @@
using NHibernateHbmToFluent.Converter.Extensions;
using NUnit.Framework;
-namespace ConverterTests
+namespace ConverterTests.Extensions
{
public class StringExtensionTests
{
98 ConverterTests/Methods/ColumnTests.cs
View
@@ -0,0 +1,98 @@
+using NHibernate.Cfg.MappingSchema;
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods
+{
+ public class ColumnTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__Column()
+ {
+ Column.FluentNHibernateNames.Column.ShouldBeEqualTo("Column");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_a_column_name
+ {
+ private CodeFileBuilder _builder;
+ private Column _column;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _column = new Column(_builder);
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_Component()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmComponent(), null);
+ _column.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_Property()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmProperty(), null);
+ _column.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_Set()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmSet(), null);
+ _column.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_Bag()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmBag(), null);
+ _column.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_Id_and_columnName_is_null()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmId(), null);
+ _column.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_MappedPropertyInfo_Type_is_Id_and_columnName_is_not_null()
+ {
+ const string columnName = "FirstName";
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmId
+ {
+ column = new[]
+ {
+ new HbmColumn
+ {
+ name = columnName
+ }
+ }
+ }, null);
+ _column.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}(\"{1}\")\r\n", Column.FluentNHibernateNames.Column, columnName));
+ }
+ }
+ }
+}
123 ConverterTests/Methods/GeneratedByTests.cs
View
@@ -0,0 +1,123 @@
+using System;
+using NHibernate.Cfg.MappingSchema;
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods
+{
+ public class GeneratedByTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__GeneratedBy()
+ {
+ GeneratedBy.FluentNHibernateNames.GeneratedBy.ShouldBeEqualTo("GeneratedBy");
+ }
+
+ [Test]
+ public void Should_return_the_correct_value_for__Assigned()
+ {
+ GeneratedBy.FluentNHibernateNames.Assigned.ShouldBeEqualTo("Assigned");
+ }
+
+ [Test]
+ public void Should_return_the_correct_value_for__Native()
+ {
+ GeneratedBy.FluentNHibernateNames.Native.ShouldBeEqualTo("Native");
+ }
+
+ [Test]
+ public void Should_return_the_correct_value_for__Sequence()
+ {
+ GeneratedBy.FluentNHibernateNames.Sequence.ShouldBeEqualTo("Sequence");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_unsaved_value
+ {
+ private CodeFileBuilder _builder;
+ private GeneratedBy _generatedBy;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _generatedBy = new GeneratedBy(_builder);
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_not_Id()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmSet(), null);
+ _generatedBy.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_Id_and_generator_is_null()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmId(), null);
+ _generatedBy.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_MappedPropertyInfo_Type_is_not_Id_and_generator_class_is__sequence()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmId
+ {
+ generator = new HbmGenerator
+ {
+ @class = "sequence",
+ param = new[]
+ {
+ new HbmParam
+ {
+ Text = new[] {"IX_NAME"}
+ }
+ }
+ }
+ }, null);
+ _generatedBy.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}.{1}(\"IX_NAME\")\r\n", GeneratedBy.FluentNHibernateNames.GeneratedBy, GeneratedBy.FluentNHibernateNames.Sequence));
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_MappedPropertyInfo_Type_is_not_Id_and_generator_class_is__assigned()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmId
+ {
+ generator = new HbmGenerator
+ {
+ @class = "assigned"
+ }
+ }, null);
+ _generatedBy.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(String.Format(".{0}.{1}()\r\n", GeneratedBy.FluentNHibernateNames.GeneratedBy, GeneratedBy.FluentNHibernateNames.Assigned));
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_MappedPropertyInfo_Type_is_not_Id_and_generator_class_is__native()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmId
+ {
+ generator = new HbmGenerator
+ {
+ @class = "native"
+ }
+ }, null);
+ _generatedBy.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}.{1}()\r\n", GeneratedBy.FluentNHibernateNames.GeneratedBy, GeneratedBy.FluentNHibernateNames.Native));
+ }
+ }
+ }
+}
18 ConverterTests/Methods/IndexTests.cs
View
@@ -0,0 +1,18 @@
+using NHibernateHbmToFluent.Converter.Methods;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods
+{
+ public class IndexTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__Index()
+ {
+ Index.FluentNHibernateNames.Index.ShouldBeEqualTo("Index");
+ }
+ }
+ }
+}
61 ConverterTests/Methods/Join/CascadeTests.cs
View
@@ -0,0 +1,61 @@
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods.Join;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods.Join
+{
+ public class CascadeTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__Cascade()
+ {
+ Cascade.FluentNHibernateNames.Cascade.ShouldBeEqualTo("Cascade");
+ }
+
+ [Test]
+ public void Should_return_the_correct_value_for__SaveUpdate()
+ {
+ Cascade.FluentNHibernateNames.SaveUpdate.ShouldBeEqualTo("SaveUpdate");
+ }
+
+ [Test]
+ public void Should_return_the_correct_value_for__None()
+ {
+ Cascade.FluentNHibernateNames.None.ShouldBeEqualTo("None");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_a_cascade_type
+ {
+ private CodeFileBuilder _builder;
+ private Cascade _cascade;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _cascade = new Cascade(_builder);
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given__save_update()
+ {
+ _cascade.Add("save-update");
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}.{1}()\r\n", Cascade.FluentNHibernateNames.Cascade, Cascade.FluentNHibernateNames.SaveUpdate));
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given__none()
+ {
+ _cascade.Add("none");
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}.{1}()\r\n", Cascade.FluentNHibernateNames.Cascade, Cascade.FluentNHibernateNames.None));
+ }
+ }
+ }
+}
55 ConverterTests/Methods/Join/InverseTests.cs
View
@@ -0,0 +1,55 @@
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods.Join;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods.Join
+{
+ public class InverseTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__Not()
+ {
+ Inverse.FluentNHibernateNames.Not.ShouldBeEqualTo("Not");
+ }
+
+ [Test]
+ public void Should_return_the_correct_value_for__Inverse()
+ {
+ Inverse.FluentNHibernateNames.Inverse.ShouldBeEqualTo("Inverse");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_an_inverse_relationship
+ {
+ private CodeFileBuilder _builder;
+ private Inverse _inverse;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _inverse = new Inverse(_builder);
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given__true()
+ {
+ _inverse.Add(true);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}()\r\n", Inverse.FluentNHibernateNames.Inverse));
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given__False()
+ {
+ _inverse.Add(false);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}.{1}()\r\n", Inverse.FluentNHibernateNames.Not, Inverse.FluentNHibernateNames.Inverse));
+ }
+ }
+ }
+}
69 ConverterTests/Methods/Join/KeyColumnTests.cs
View
@@ -0,0 +1,69 @@
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods.Join;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods.Join
+{
+ public class KeyColumnTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__ChildKeyColumn()
+ {
+ KeyColumn.FluentNHibernateNames.ChildKeyColumn.ShouldBeEqualTo("ChildKeyColumn");
+ }
+
+ [Test]
+ public void Should_return_the_correct_value_for__ParentKeyColumn()
+ {
+ KeyColumn.FluentNHibernateNames.ParentKeyColumn.ShouldBeEqualTo("ParentKeyColumn");
+ }
+
+ [Test]
+ public void Should_return_the_correct_value_for__KeyColumn()
+ {
+ KeyColumn.FluentNHibernateNames.KeyColumn.ShouldBeEqualTo("KeyColumn");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_a_key_column
+ {
+ private CodeFileBuilder _builder;
+ private KeyColumn _keyColumn;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _keyColumn = new KeyColumn(_builder);
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given__Many_to_Many_if_relationship_is_inversed()
+ {
+ _keyColumn.Add(true, "Name", PropertyMappingType.ManyToMany);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}(\"Name\")\r\n", KeyColumn.FluentNHibernateNames.ChildKeyColumn));
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given__Many_to_Many_if_relationship_is_not_inversed()
+ {
+ _keyColumn.Add(false, "Name", PropertyMappingType.ManyToMany);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}(\"Name\")\r\n", KeyColumn.FluentNHibernateNames.ParentKeyColumn));
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given__One_to_Many()
+ {
+ _keyColumn.Add(false, "Name", PropertyMappingType.OneToMany);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}(\"Name\")\r\n", KeyColumn.FluentNHibernateNames.KeyColumn));
+ }
+ }
+ }
+}
64 ConverterTests/Methods/Join/LazyLoadTests.cs
View
@@ -0,0 +1,64 @@
+using NHibernate.Cfg.MappingSchema;
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods.Join;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods.Join
+{
+ public class LazyLoadTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__LazyLoad()
+ {
+ LazyLoad.FluentNHibernateNames.LazyLoad.ShouldBeEqualTo("LazyLoad");
+ }
+
+ [Test]
+ public void Should_return_the_correct_value_for__Not()
+ {
+ LazyLoad.FluentNHibernateNames.Not.ShouldBeEqualTo("Not");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_lazy_load
+ {
+ private CodeFileBuilder _builder;
+ private LazyLoad _lazyLoad;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _lazyLoad = new LazyLoad(_builder);
+ }
+
+ [Test]
+ public void Should_return_empty_if_lazySpecified_is_false()
+ {
+ _lazyLoad.Add(false, HbmCollectionLazy.False);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given__HbmCollectionLazy_False__and_lazySpecified_is_true()
+ {
+ _lazyLoad.Add(true, HbmCollectionLazy.False);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}.{1}()\r\n", LazyLoad.FluentNHibernateNames.Not, LazyLoad.FluentNHibernateNames.LazyLoad));
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given__HbmCollectionLazy_True__and_lazySpecified_is_true()
+ {
+ _lazyLoad.Add(true, HbmCollectionLazy.True);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}()\r\n", LazyLoad.FluentNHibernateNames.LazyLoad));
+ }
+ }
+ }
+}
49 ConverterTests/Methods/Join/OrderByTests.cs
View
@@ -0,0 +1,49 @@
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods.Join;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods.Join
+{
+ public class OrderByTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__OrderBy()
+ {
+ OrderBy.FluentNHibernateNames.OrderBy.ShouldBeEqualTo("OrderBy");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_order_by
+ {
+ private CodeFileBuilder _builder;
+ private OrderBy _orderBy;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _orderBy = new OrderBy(_builder);
+ }
+
+ [Test]
+ public void Should_return_empty_if_orderBy_is_null()
+ {
+ _orderBy.Add(null);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_orderBy_is_not_null()
+ {
+ _orderBy.Add("Name DESC");
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}(\"Name DESC\")\r\n", OrderBy.FluentNHibernateNames.OrderBy));
+ }
+ }
+ }
+}
49 ConverterTests/Methods/Join/TableTests.cs
View
@@ -0,0 +1,49 @@
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods.Join;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods.Join
+{
+ public class TableTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__Table()
+ {
+ Table.FluentNHibernateNames.Table.ShouldBeEqualTo("Table");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_a_table
+ {
+ private CodeFileBuilder _builder;
+ private Table _table;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _table = new Table(_builder);
+ }
+
+ [Test]
+ public void Should_return_empty_if_tableName_is_null()
+ {
+ _table.Add(null);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_tableName_is_not_null()
+ {
+ _table.Add("Person");
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}(\"Person\")\r\n", Table.FluentNHibernateNames.Table));
+ }
+ }
+ }
+}
49 ConverterTests/Methods/Join/WhereTests.cs
View
@@ -0,0 +1,49 @@
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods.Join;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods.Join
+{
+ public class WhereTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__Where()
+ {
+ Where.FluentNHibernateNames.Where.ShouldBeEqualTo("Where");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_a_where_clause
+ {
+ private CodeFileBuilder _builder;
+ private Where _where;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _where = new Where(_builder);
+ }
+
+ [Test]
+ public void Should_return_empty_if_sqlWhereClause_is_null()
+ {
+ _where.Add(null);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_sqlWhereClause_is_not_null()
+ {
+ _where.Add("Type = 'New'");
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}(x => x.Type == \"New\")\r\n", Where.FluentNHibernateNames.Where));
+ }
+ }
+ }
+}
65 ConverterTests/Methods/LengthTests.cs
View
@@ -0,0 +1,65 @@
+using NHibernate.Cfg.MappingSchema;
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods
+{
+ public class LengthTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__Length()
+ {
+ Length.FluentNHibernateNames.Length.ShouldBeEqualTo("Length");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_a_length
+ {
+ private CodeFileBuilder _builder;
+ private Length _length;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _length = new Length(_builder);
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_not_Property()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmComponent(), null);
+ _length.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_Property_and_length_is_null()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmProperty(), null);
+ _length.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_MappedPropertyInfo_Type_is_Property_and_length_is_not_null()
+ {
+ const string length = "6";
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmProperty
+ {
+ length = length
+ }, null);
+ _length.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}({1})\r\n", Length.FluentNHibernateNames.Length, length));
+ }
+ }
+ }
+}
68 ConverterTests/Methods/UniqueTests.cs
View
@@ -0,0 +1,68 @@
+using NHibernate.Cfg.MappingSchema;
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods
+{
+ public class UniqueTests
+ {
+ [TestFixture]
+ public class When_asked_for_a_FluentNHibernate_name
+ {
+ [Test]
+ public void Should_return_the_correct_value_for__Unique()
+ {
+ Unique.FluentNHibernateNames.Unique.ShouldBeEqualTo("Unique");
+ }
+ }
+
+ [TestFixture]
+ public class When_asked_to_Add_uniqueness
+ {
+ private CodeFileBuilder _builder;
+ private Unique _unique;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _unique = new Unique(_builder);
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is__Id()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmId(), null);
+ _unique.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_Property_and_unique_is_null()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmProperty
+ {
+ updateSpecified = false
+ }, null);
+ _unique.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_MappedPropertyInfo_Type_is_Property_and_unique_is_not_null()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmProperty
+ {
+ updateSpecified = true,
+ unique = true
+ }, null);
+ _unique.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(string.Format(".{0}()\r\n", Unique.FluentNHibernateNames.Unique));
+ }
+ }
+ }
+}
66 ConverterTests/Methods/UnsavedValueTests.cs
View
@@ -0,0 +1,66 @@
+using NHibernate.Cfg.MappingSchema;
+using NHibernateHbmToFluent.Converter;
+using NHibernateHbmToFluent.Converter.Methods;
+using NUnit.Framework;
+
+namespace ConverterTests.Methods
+{
+ public class UnsavedValueTests
+ {
+ [TestFixture]
+ public class When_asked_to_Add_unsaved_value
+ {
+ private CodeFileBuilder _builder;
+ private UnsavedValue _unsavedValue;
+
+ [SetUp]
+ public void BeforeEachTest()
+ {
+ _builder = new CodeFileBuilder();
+ _unsavedValue = new UnsavedValue(_builder);
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_not_Id()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmSet(), null);
+ _unsavedValue.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_return_empty_given_MappedPropertyInfo_Type_is_Id_and_unsavedvalue_is_null()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmId(), null);
+ _unsavedValue.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo("");
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_MappedPropertyInfo_Type_is_not_Id_and_unsavedvalue_is__null()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmId
+ {
+ unsavedvalue = "null"
+ }, null);
+ _unsavedValue.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(".UnsavedValue(String.Empty)\r\n");
+ }
+
+ [Test]
+ public void Should_generate_correct_code_given_MappedPropertyInfo_Type_is_not_Id_and_unsavedvalue_is_not__null()
+ {
+ MappedPropertyInfo mappedPropertyInfo = new MappedPropertyInfo(new HbmId
+ {
+ unsavedvalue = "6"
+ }, null);
+ _unsavedValue.Add(mappedPropertyInfo);
+ string result = _builder.ToString();
+ result.ShouldBeEqualTo(".UnsavedValue(6)\r\n");
+ }
+ }
+ }
+}
BIN  WinForm/bin/Debug/FluentNHibernate.dll
View
Binary file not shown
BIN  WinForm/bin/Debug/NHibernateHbmToFluent.Converter.dll
View
Binary file not shown
BIN  WinForm/bin/Debug/NHibernateHbmToFluent.Converter.pdb
View
Binary file not shown
BIN  WinForm/bin/Debug/NHibernateHbmToFluent.exe
View
Binary file not shown
BIN  WinForm/bin/Debug/NHibernateHbmToFluent.pdb
View
Binary file not shown
BIN  lib/FluentNHibernate.dll
View
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.