Skip to content

Commit 131830b

Browse files
fixup! Replace IObjectsFactory with IServiceProvider interface
Keep tests for an obsolete class, till it gets dropped
1 parent d72268f commit 131830b

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using NHibernate.Bytecode;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.Bytecode
6+
{
7+
[TestFixture, Obsolete]
8+
public class ActivatorObjectFactoryFixture
9+
{
10+
public class WithOutPublicParameterLessCtor
11+
{
12+
public string Something { get; set; }
13+
protected WithOutPublicParameterLessCtor() { }
14+
15+
public WithOutPublicParameterLessCtor(string something)
16+
{
17+
Something = something;
18+
}
19+
}
20+
21+
public class PublicParameterLessCtor
22+
{
23+
}
24+
25+
public struct ValueType
26+
{
27+
public string Something { get; set; }
28+
}
29+
30+
protected virtual IObjectsFactory GetObjectsFactory()
31+
{
32+
return new ActivatorObjectsFactory();
33+
}
34+
35+
[Test]
36+
public void CreateInstanceDefCtor()
37+
{
38+
IObjectsFactory of = GetObjectsFactory();
39+
Assert.Throws<ArgumentNullException>(() => of.CreateInstance(null));
40+
Assert.Throws<MissingMethodException>(() => of.CreateInstance(typeof(WithOutPublicParameterLessCtor)));
41+
var instance = of.CreateInstance(typeof(PublicParameterLessCtor));
42+
Assert.That(instance, Is.Not.Null);
43+
Assert.That(instance, Is.InstanceOf<PublicParameterLessCtor>());
44+
}
45+
46+
47+
48+
[Test, Obsolete]
49+
public void CreateInstanceWithNoPublicCtor()
50+
{
51+
IObjectsFactory of = GetObjectsFactory();
52+
Assert.Throws<ArgumentNullException>(() => of.CreateInstance(null, false));
53+
var instance = of.CreateInstance(typeof(WithOutPublicParameterLessCtor), true);
54+
Assert.That(instance, Is.Not.Null);
55+
Assert.That(instance, Is.InstanceOf<WithOutPublicParameterLessCtor>());
56+
}
57+
58+
[Test, Obsolete]
59+
public void CreateInstanceOfValueType()
60+
{
61+
IObjectsFactory of = GetObjectsFactory();
62+
var instance = of.CreateInstance(typeof(ValueType), true);
63+
Assert.That(instance, Is.Not.Null);
64+
Assert.That(instance, Is.InstanceOf<ValueType>());
65+
}
66+
67+
[Test, Obsolete]
68+
public void CreateInstanceWithArguments()
69+
{
70+
IObjectsFactory of = GetObjectsFactory();
71+
Assert.Throws<ArgumentNullException>(() => of.CreateInstance(null, new[] {1}));
72+
var value = "a value";
73+
var instance = of.CreateInstance(typeof(WithOutPublicParameterLessCtor), new[]{value});
74+
Assert.That(instance, Is.Not.Null);
75+
Assert.That(instance, Is.InstanceOf<WithOutPublicParameterLessCtor>());
76+
Assert.That(((WithOutPublicParameterLessCtor)instance).Something, Is.EqualTo(value));
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)