Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dbroudy/Castle.Core into …
Browse files Browse the repository at this point in the history
…dbroudy-master

Conflicts:
	src/Castle.Core.Tests/Castle.Core.Tests.csproj
  • Loading branch information
kkozmic committed Aug 14, 2011
2 parents fd196d1 + 2796dda commit 6f19e52
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
81 changes: 81 additions & 0 deletions src/Castle.Core.Tests/BugsReported/DynProxy159.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2004-2011 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.DynamicProxy.Tests.BugsReported
{
using System;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

using NUnit.Framework;

[TestFixture]
public class DynProxy159 : BasePEVerifyTestCase
{
// this test will only fail the first time it is run in a given VM

private void FakeSerialize(object o)
{
using (var ms = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(ms, o);
}
}

[Test]
public void ShouldNotChangeOrderOfSerializeableMembers()
{
var fromSystem = FormatterServices.GetSerializableMembers(typeof(MySerialClass));
var beforeProxySerialization = new MemberInfo[fromSystem.Length];
Array.Copy(fromSystem, beforeProxySerialization, fromSystem.Length);
fromSystem = null;

FakeSerialize(generator.CreateClassProxy(typeof(MySerialClass)));

fromSystem = FormatterServices.GetSerializableMembers(typeof(MySerialClass));

Assert.AreEqual(beforeProxySerialization, fromSystem);
}

[Test]
public void ShouldSerializedMixofProxiedAndUnproxiedInstances()
{
var o = new[]
{
new MySerialClass(),
(MySerialClass)generator.CreateClassProxy(typeof(MySerialClass)),
new MySerialClass(),
};

o[2].yyy = 3.1415;
o[2].zzz = 100;

FakeSerialize(o);

Assert.AreEqual(3.1415, o[2].yyy);
Assert.AreEqual(100, o[2].zzz);
}
}

[Serializable]
public class MySerialClass
{
public string xxx { get; set; }
public double? yyy { get; set; }
public int? zzz { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/Castle.Core.Tests/Castle.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
<Compile Include="BasicInterfaceProxyTestCase.cs" />
<Compile Include="BugAttribute.cs" />
<Compile Include="BugsReported\Core40.cs" />
<Compile Include="BugsReported\DynProxy159.cs" />
<Compile Include="BugsReported\DynProxy145_SynchronizationContext.cs" />
<Compile Include="Components.DictionaryAdapter.Tests\AdaptingGenericDictionaryTestCase.cs" />
<Compile Include="Components.DictionaryAdapter.Tests\Address.cs" />
Expand Down Expand Up @@ -543,4 +544,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
6 changes: 4 additions & 2 deletions src/Castle.Core/DynamicProxy/Generators/Emitters/TypeUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ public static void SetStaticField(this Type type, string fieldName, BindingFlags

public static MemberInfo[] Sort(MemberInfo[] members)
{
Array.Sort(members, (l, r) => string.Compare(l.Name, r.Name));
return members;
var sortedMembers = new MemberInfo[members.Length];
Array.Copy(members, sortedMembers, members.Length);
Array.Sort(sortedMembers, (l, r) => string.Compare(l.Name, r.Name));
return sortedMembers;
}

private static bool CloseGenericParametersIfAny(AbstractTypeEmitter emitter, Type[] arguments)
Expand Down

0 comments on commit 6f19e52

Please sign in to comment.