|
| 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