forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomObjectsFactoryTest.cs
66 lines (59 loc) · 2.16 KB
/
CustomObjectsFactoryTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using NHibernate.Bytecode;
using NUnit.Framework;
using Environment = NHibernate.Cfg.Environment;
namespace NHibernate.Test.CfgTest
{
[TestFixture]
public class CustomObjectsFactoryTest
{
private class MyObjectsFactory : IObjectsFactory
{
public object CreateInstance(System.Type type)
{
throw new NotImplementedException();
}
public object CreateInstance(System.Type type, bool nonPublic)
{
throw new NotImplementedException();
}
public object CreateInstance(System.Type type, params object[] ctorArgs)
{
throw new NotImplementedException();
}
}
private class InvalidObjectsFactory
{
}
private class InvalidNoCtorObjectsFactory : MyObjectsFactory
{
public InvalidNoCtorObjectsFactory(string pizza) {}
}
[Test]
public void WhenNoShortCutUsedThenCanBuildObjectsFactory()
{
var properties = new Dictionary<string, string> { { Environment.PropertyBytecodeProvider, typeof(MyObjectsFactory).AssemblyQualifiedName } };
Assert.That(() => Environment.BuildObjectsFactory(properties), Throws.Nothing);
}
[Test]
public void WhenNoShortCutUsedThenCanBuildInstanceOfConfiguredObjectsFactory()
{
var properties = new Dictionary<string, string> { { Environment.PropertyObjectsFactory, typeof(MyObjectsFactory).AssemblyQualifiedName } };
Assert.That(Environment.BuildObjectsFactory(properties), Is.InstanceOf<MyObjectsFactory>());
}
[Test]
public void WhenInvalidThenThrow()
{
var properties = new Dictionary<string, string> { { Environment.PropertyObjectsFactory, typeof(InvalidObjectsFactory).AssemblyQualifiedName } };
Assert.That(() => Environment.BuildObjectsFactory(properties), Throws.TypeOf<HibernateObjectsFactoryException>());
}
[Test]
public void WhenNoDefaultCtorThenThrow()
{
var properties = new Dictionary<string, string> { { Environment.PropertyObjectsFactory, typeof(InvalidNoCtorObjectsFactory).AssemblyQualifiedName } };
Assert.That(() => Environment.BuildObjectsFactory(properties), Throws.TypeOf<HibernateObjectsFactoryException>()
.And.InnerException.Message.Contains("constructor was not found"));
}
}
}