User: mausch
Date: 2009/10/27 08:22 PM
Added:
/ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Model/CompositeUserType/
BadProduct.cs
Modified:
/ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/
Castle.ActiveRecord.Tests-vs2008.csproj, CompositeUserTypeTestCase.cs
/ActiveRecord/trunk/src/Castle.ActiveRecord/Attributes/
CompositeUserTypeAttribute.cs
/ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/
XmlGenerationVisitor.cs
Log:
fixed exceptions for ill-defined CompositeUserTypes, used to throw NRE
File Changes:
Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord/Attributes/
==================================================================
File [modified]: CompositeUserTypeAttribute.cs
Delta lines: +16 -0
===================================================================
---
ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/XmlGenerationVisitor.cs
2009-10-27 19:38:20 UTC (rev 6279)
+++
ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/XmlGenerationVisitor.cs
2009-10-28 03:22:48 UTC (rev 6280)
@@ -22,6 +22,7 @@
using System.Text;
using Castle.ActiveRecord;
using NHibernate;
+ using NHibernate.UserTypes;
/// <summary>
/// Traverse the tree emitting proper xml configuration
@@ -818,6 +819,21 @@
public override void
VisitCompositeUserType(CompositeUserTypeModel model)
{
CompositeUserTypeAttribute attribute = model.Attribute;
+ if (attribute.CompositeType == null)
+ throw new
ActiveRecordException(string.Format("CompositeType not defined for
CompositeUserTypeAttribute on class '{0}', member '{1}'",
model.Member.DeclaringType, model.Member.Name));
+
+ if
(!typeof(ICompositeUserType).IsAssignableFrom(attribute.CompositeType))
+ throw new
ActiveRecordException(string.Format("The type '{0}' does not implement
ICompositeUserType for CompositeUserTypeAttribute on class '{1}', member
'{2}'", attribute.CompositeType, model.Member.DeclaringType,
model.Member.Name));
+
+ if (attribute.ColumnNames == null)
+ throw new
ActiveRecordException(string.Format("ColumnNames not defined for
CompositeUserTypeAttribute on class '{0}', member '{1}'",
model.Member.DeclaringType, model.Member.Name));
+
+ if (attribute.Length == null)
+ throw new
ActiveRecordException(string.Format("Length not defined for
CompositeUserTypeAttribute on class '{0}', member '{1}'",
model.Member.DeclaringType, model.Member.Name));
+
+ if (attribute.Length.Length !=
attribute.ColumnNames.Length)
+ throw new
ActiveRecordException(string.Format("Length and ColumnNames lengths do not
match for CompositeUserTypeAttribute on class '{0}', member '{1}'",
model.Member.DeclaringType, model.Member.Name));
+
BeginWriteProperty(attribute.AccessString,
MakeTypeName(attribute.CompositeType), null, attribute.Insert,
model.Member.Name, model.MemberType,
attribute.Update);
Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/
=============================================================
File [modified]: Castle.ActiveRecord.Tests-vs2008.csproj
Delta lines: +39 -0
===================================================================
---
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/CompositeUserTypeTestCase.cs
2009-10-27 19:38:20 UTC (rev 6279)
+++
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/CompositeUserTypeTestCase.cs
2009-10-28 03:22:48 UTC (rev 6280)
@@ -12,11 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+
+
namespace Castle.ActiveRecord.Tests
{
using System;
using System.IO;
+ using System.Reflection;
using System.Text.RegularExpressions;
+ using Castle.ActiveRecord.Framework;
using Castle.ActiveRecord.Tests.Model.CompositeUserType;
using NUnit.Framework;
@@ -112,5 +116,40 @@
Assert.AreEqual("Inc", loaded.ManufacturerName[1]);
}
+
+ [Test]
+ [ExpectedException(typeof(ActiveRecordException))]
+ public void BadCompositeUserType_WithNoType()
+ {
+
ActiveRecordStarter.Initialize(GetConfigSource(),
typeof(BadProduct_WithNoType));
+ }
+
+ [Test]
+ [ExpectedException(typeof(CustomAttributeFormatException))]
+ public void BadCompositeUserType_WithBadType() {
+
ActiveRecordStarter.Initialize(GetConfigSource(),
typeof(BadProduct_WithBadType));
+ }
+
+ [Test]
+ [ExpectedException(typeof(ActiveRecordException))]
+ public void BadCompositeUserType_WithNoColumnNames()
+ {
+
ActiveRecordStarter.Initialize(GetConfigSource(),
typeof(BadProduct_WithNoColumnNames));
+ }
+
+ [Test]
+ [ExpectedException(typeof(ActiveRecordException))]
+ public void BadCompositeUserType_WithNoColumnLengths()
+ {
+
ActiveRecordStarter.Initialize(GetConfigSource(),
typeof(BadProduct_WithNoColumnLength));
+ }
+
+ [Test]
+ [ExpectedException(typeof(ActiveRecordException))]
+ public void BadCompositeUserType_WithBadColumnLength()
+ {
+
ActiveRecordStarter.Initialize(GetConfigSource(),
typeof(BadProduct_WithBadColumnLength));
+ }
+
}
File [modified]: CompositeUserTypeTestCase.cs
Delta lines: +71 -0
===================================================================
---
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Model/CompositeUserType/BadProduct.cs
(rev 0)
+++
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Model/CompositeUserType/BadProduct.cs
2009-10-28 03:22:48 UTC (rev 6280)
@@ -0,0 +1,72 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.ActiveRecord.Tests.Model.CompositeUserType
+{
+ [ActiveRecord]
+ public class BadProduct_WithNoType
+ {
+ [PrimaryKey]
+ public int Id { get; set; }
+
+ [CompositeUserType]
+ public string[] ManufacturerName { get; set; }
+ }
+
+ [ActiveRecord]
+ public class BadProduct_WithBadType
+ {
+ [PrimaryKey]
+ public int Id { get; set; }
+
+ [CompositeUserType(CompositeType = typeof(string),
+ ColumnNames = new[] { "Manufacturer_FirstName"
},
+ Length = new[] {1,2,3})]
+ public string[] ManufacturerName { get; set; }
+ }
+
+ [ActiveRecord]
+ public class BadProduct_WithNoColumnNames
+ {
+ [PrimaryKey]
+ public int Id { get; set; }
+
+ [CompositeUserType(CompositeType = typeof(DoubleStringType))]
+ public string[] ManufacturerName { get; set; }
+ }
+
+ [ActiveRecord]
+ public class BadProduct_WithNoColumnLength
+ {
+ [PrimaryKey]
+ public int Id { get; set; }
+
+ [CompositeUserType(CompositeType = typeof(DoubleStringType),
+ ColumnNames = new[] { "Manufacturer_FirstName"
})]
+ public string[] ManufacturerName { get; set; }
+ }
+
+ [ActiveRecord]
+ public class BadProduct_WithBadColumnLength
+ {
+ [PrimaryKey]
+ public int Id { get; set; }
+
+ [CompositeUserType(CompositeType = typeof(DoubleStringType),
+ ColumnNames = new[] { "Manufacturer_FirstName"
},
+ Length = new[] {1,2,3})]
+ public string[] ManufacturerName { get; set; }
+ }
+
Directory:
/ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Model/CompositeUserType/
=====================================================================================
File [added]: BadProduct.cs
Delta lines: +0 -0
===================================================================
Directory:
/ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/Internal/Visitors/
===================================================================================
File [modified]: XmlGenerationVisitor.cs
Delta lines: +1 -0
===================================================================
---
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Castle.ActiveRecord.Tests-vs2008.csproj
2009-10-27 19:38:20 UTC (rev 6279)
+++
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Castle.ActiveRecord.Tests-vs2008.csproj
2009-10-28 03:22:48 UTC (rev 6280)
@@ -330,6 +330,7 @@
<Compile Include="CompositeUserTypeTestCase.cs" />
<Compile Include="Config\ConfigureTests.cs" />
<Compile Include="Config\StorageConfigurationTests.cs" />
+ <Compile Include="Model\CompositeUserType\BadProduct.cs" />
<Compile Include="Model\ProductWithGuid.cs" />
<Compile Include="NHSearchTestCase.cs" />
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/castle-project-commits?hl=en
-~----------~----~----~----~------~----~------~--~---