User: roelofb
Date: 2010/01/15 09:04 AM
Added:
/MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport.Tests/ARDataBinderTests/
MR536.cs
/MonoRail/trunk/src/TestSiteARSupport/Model/
Tag.cs
Modified:
/MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport.Tests/
ARFetcherTestCase.cs, Castle.MonoRail.ActiveRecordSupport.Tests-vs2008.csproj
/MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport/
ARDataBindAttribute.cs, ARDataBinder.cs
/MonoRail/trunk/src/TestSiteARSupport/
TestSiteARSupport-vs2008.csproj
Log:
Applied path by Gareth Farrington fixing MR-ISSUE-536
File Changes:
Directory:
/MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport.Tests/ARDataBinderTests/
===========================================================================================
File [added]: MR536.cs
Delta lines: +27 -0
===================================================================
---
MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport.Tests/ARFetcherTestCase.cs
2010-01-15 15:56:48 UTC (rev 6685)
+++
MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport.Tests/ARFetcherTestCase.cs
2010-01-15 16:03:40 UTC (rev 6686)
@@ -1,5 +1,6 @@
namespace Castle.MonoRail.ActiveRecordSupport.Tests
{
+ using System;
using System.Collections.Generic;
using System.Reflection;
using Castle.Components.Binder;
@@ -78,6 +79,27 @@
Assert.AreEqual(account2.Id, records[1].Id);
}
+ [Test]
+ public void CanFetchWithEmptyGuid()
+ {
+ Tag tag = new Tag() { Id = Guid.Empty, Name =
"TopMovie" };
+ tag.Create();
+
+ ARFetcher fetcher = new ARFetcher(new
DefaultConverter());
+
+ ParameterInfo parameter =
typeof(MyController).GetMethod("MyAction3").GetParameters()[0];
+
+ ARFetchAttribute attribute =
(ARFetchAttribute)parameter.GetCustomAttributes(typeof(ARFetchAttribute),
true)[0];
+
+ Dictionary<string, object> customActionParameters = new
Dictionary<string, object>();
+ customActionParameters["id"] = Guid.Empty;
+
+ Tag record = (Tag)fetcher.FetchActiveRecord(
+ parameter, attribute, new StubRequest(),
customActionParameters);
+
+ Assert.AreEqual(tag.Id, record.Id);
+ }
+
public class MyController
{
public void MyAction([ARFetch("id")]Account account)
@@ -89,6 +111,11 @@
{
}
+
+ public void MyAction3([ARFetch("id")]Tag tag)
+ {
+
+ }
}
}
}
Directory: /MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport/
===================================================================
File [modified]: ARDataBindAttribute.cs
Delta lines: +18 -2
===================================================================
--- MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport/ARDataBinder.cs
2010-01-15 15:56:48 UTC (rev 6685)
+++ MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport/ARDataBinder.cs
2010-01-15 16:03:40 UTC (rev 6686)
@@ -42,6 +42,7 @@
private bool persistchanges;
private string[] expectCollPropertiesList;
private Stack<ActiveRecordModel> modelStack = new
Stack<ActiveRecordModel>();
+ private bool treatEmptyGuidAsNull = true;
/// <summary>
/// Gets or sets a value indicating if the changes should be
persisted.
@@ -63,8 +64,20 @@
set { autoLoad = value; }
}
- protected override void PushInstance(object instance, string
prefix)
+ /// <summary>
+ /// Determines if an empty Guid (<see cref="Guid.Empty"/>)
should be treated as a Guid or as <c>null</c>
+ /// Defaults to <c>true</c>, in which case an empty Guid is not
a valid
+ /// value for a primary key.
+ /// If this property is <c>false</c> an empty Guid is a valid
value for a primary key.
+ /// </summary>
+ public bool TreatEmptyGuidAsNull
{
+ get { return treatEmptyGuidAsNull; }
+ set { treatEmptyGuidAsNull = value; }
+ }
+
+ protected override void PushInstance(object instance, string prefix)
+ {
ActiveRecordModel model =
ActiveRecordModel.GetModel(instance.GetType());
if (model == null && modelStack.Count != 0)
@@ -526,7 +539,10 @@
}
else if (id.GetType() == typeof(Guid))
{
- return Guid.Empty != ((Guid) id);
+ if (this.treatEmptyGuidAsNull)
+ return Guid.Empty != ((Guid)id);
+ else
+ return true;
}
else
File [modified]: ARDataBinder.cs
Delta lines: +41 -0
===================================================================
---
MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport.Tests/ARDataBinderTests/MR536.cs
(rev 0)
+++
MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport.Tests/ARDataBinderTests/MR536.cs
2010-01-15 16:03:40 UTC (rev 6686)
@@ -0,0 +1,41 @@
+// Copyright 2004-2010 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.MonoRail.ActiveRecordSupport.Tests.ARDataBinderTests
+{
+ using System;
+ using Framework.Test;
+ using NUnit.Framework;
+ using TestSiteARSupport.Model;
+
+ [TestFixture]
+ public class MR536 : BaseARTestCase
+ {
+ [Test]
+ public void CanBindPrimaryKeyToEmptyGuid()
+ {
+ Tag tag = new Tag() { Id = Guid.Empty, Name =
"TopMovie" };
+ tag.Create();
+
+ var request = new StubRequest();
+ request.Params["tag.id"] = Guid.Empty.ToString();
+
+ var binder = new ARDataBinder { AutoLoad =
AutoLoadBehavior.Always, TreatEmptyGuidAsNull = false};
+
+ var record = (Tag)binder.BindObject(typeof(Tag), "tag",
request.ParamsNode);
+
+ Assert.AreEqual(tag.Id, record.Id);
+ }
+ }
+}
Directory: /MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport.Tests/
=========================================================================
File [modified]: ARFetcherTestCase.cs
Delta lines: +5 -0
===================================================================
---
MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport.Tests/Castle.MonoRail.ActiveRecordSupport.Tests-vs2008.csproj
2010-01-15 15:56:48 UTC (rev 6685)
+++
MonoRail/trunk/src/Castle.MonoRail.ActiveRecordSupport.Tests/Castle.MonoRail.ActiveRecordSupport.Tests-vs2008.csproj
2010-01-15 16:03:40 UTC (rev 6686)
@@ -48,6 +48,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\net-3.5\Castle.Components.Binder.dll</HintPath>
</Reference>
+ <Reference Include="Castle.Core, Version=1.2.0.0, Culture=neutral,
PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\net-3.5\Castle.Core.dll</HintPath>
+ </Reference>
<Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral,
PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Iesi.Collections.dll</HintPath>
@@ -78,6 +82,7 @@
<ItemGroup>
<Compile Include="ARDataBinderTests\AccountControllerTestCase.cs" />
<Compile Include="ARDataBinderTests\MR296.cs" />
+ <Compile Include="ARDataBinderTests\MR536.cs" />
<Compile Include="ARFetcherTestCase.cs" />
<Compile Include="BaseAcceptanceTestCase.cs" />
File [modified]: Castle.MonoRail.ActiveRecordSupport.Tests-vs2008.csproj
Delta lines: +50 -0
===================================================================
--- MonoRail/trunk/src/TestSiteARSupport/Model/Tag.cs
(rev 0)
+++ MonoRail/trunk/src/TestSiteARSupport/Model/Tag.cs 2010-01-15 16:03:40 UTC
(rev 6686)
@@ -0,0 +1,50 @@
+// Copyright 2004-2010 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 TestSiteARSupport.Model
+{
+ using System;
+ using Castle.ActiveRecord;
+ using Castle.Components.Validator;
+
+ [ActiveRecord("TSAS_Tags")]
+ public class Tag : ActiveRecordBase
+ {
+ private Guid id;
+ private String name;
+
+ public Tag()
+ {
+ }
+
+ public Tag(String name)
+ {
+ this.name = name;
+ }
+
+ [PrimaryKey(PrimaryKeyType.Assigned)]
+ public Guid Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ [Property, ValidateNonEmpty]
+ public String Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
+ }
+}
Directory: /MonoRail/trunk/src/TestSiteARSupport/Model/
=======================================================
File [added]: Tag.cs
Delta lines: +1 -0
===================================================================
--- MonoRail/trunk/src/TestSiteARSupport/TestSiteARSupport-vs2008.csproj
2010-01-15 15:56:48 UTC (rev 6685)
+++ MonoRail/trunk/src/TestSiteARSupport/TestSiteARSupport-vs2008.csproj
2010-01-15 16:03:40 UTC (rev 6686)
@@ -97,6 +97,7 @@
<Compile Include="Controllers\CustomerController.cs" />
<Compile Include="Controllers\MR296.cs" />
<Compile Include="Model\Customer.cs" />
+ <Compile Include="Model\Tag.cs" />
<Compile Include="Scaffolds\AccountPermissionScaffoldController.cs" />
<Compile Include="Scaffolds\AccountScaffoldController.cs" />
Directory: /MonoRail/trunk/src/TestSiteARSupport/
=================================================
File [modified]: TestSiteARSupport-vs2008.csproj
Delta lines: +0 -0
===================================================================
--
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.