Skip to content

Commit 41782de

Browse files
Test ref and out methods with static proxy
Follow up to #1451 for still testing NH-2622, NH-2628 and #1389
1 parent f8485f6 commit 41782de

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/NHibernate.Test/StaticProxyTest/StaticProxyFactoryFixture.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,39 @@ public class SimpleTestClass
4848
public virtual int Id { get; set; }
4949
}
5050

51+
[Serializable]
52+
public class RefOutTestClass
53+
{
54+
public virtual int Id { get; set; }
55+
56+
public virtual void Method1(out int x)
57+
{
58+
x = 3;
59+
}
60+
61+
public virtual void Method2(ref int x)
62+
{
63+
x++;
64+
}
65+
66+
public virtual void Method3(out int? y)
67+
{
68+
y = 4;
69+
}
70+
71+
public virtual void Method4(ref int? y)
72+
{
73+
y++;
74+
}
75+
76+
public virtual void Method(ref Dictionary<string, string> dictionary)
77+
{
78+
dictionary = dictionary == null
79+
? new Dictionary<string, string>()
80+
: new Dictionary<string, string>(dictionary);
81+
}
82+
}
83+
5184
[Serializable]
5285
public class CustomSerializationClass : ISerializable
5386
{
@@ -141,6 +174,51 @@ public void VerifyProxyForClassWithAdditionalInterface()
141174
#endif
142175
}
143176

177+
[Test]
178+
public void VerifyProxyForRefOutClass()
179+
{
180+
var factory = new StaticProxyFactory();
181+
factory.PostInstantiate(
182+
typeof(RefOutTestClass).FullName,
183+
typeof(RefOutTestClass),
184+
new HashSet<System.Type> { typeof(INHibernateProxy) },
185+
null,
186+
null,
187+
null);
188+
189+
#if NETFX
190+
VerifyGeneratedAssembly(
191+
() =>
192+
{
193+
#endif
194+
var proxy = factory.GetProxy(1, null);
195+
Assert.That(proxy, Is.Not.Null);
196+
197+
var state = new RefOutTestClass();
198+
proxy.HibernateLazyInitializer.SetImplementation(state);
199+
200+
var entity = (RefOutTestClass) proxy;
201+
entity.Method1(out var x);
202+
Assert.That(x, Is.EqualTo(3));
203+
204+
entity.Method2(ref x);
205+
Assert.That(x, Is.EqualTo(4));
206+
207+
entity.Method3(out var y);
208+
Assert.That(y, Is.EqualTo(4));
209+
210+
entity.Method4(ref y);
211+
Assert.That(y, Is.EqualTo(5));
212+
213+
var dictionary = new Dictionary<string, string>();
214+
var param = dictionary;
215+
entity.Method(ref param);
216+
Assert.That(param, Is.Not.SameAs(dictionary));
217+
#if NETFX
218+
});
219+
#endif
220+
}
221+
144222
[Test]
145223
public void InitializedProxyStaysInitializedAfterDeserialization()
146224
{

0 commit comments

Comments
 (0)