예제 #1
0
		public void VerifyFieldInterceptorProxyWithAdditionalInterface()
		{
			var factory = new StaticProxyFactory();
			factory.PostInstantiate(
				typeof(PublicInterfaceTestClass).FullName,
				typeof(PublicInterfaceTestClass),
				// By way of the "proxy" attribute on the "class" mapping, an interface to use for the
				// lazy entity load proxy instead of the persistentClass can be specified. This is "translated" into
				// having an additional interface in the interface list, instead of just having INHibernateProxy.
				// (Quite a loosy semantic...)
				// The field interceptor proxy ignores this setting, as it does not delegate its implementation
				// to an instance of the persistentClass, and so cannot implement interface methods if it does not
				// inherit the persitentClass.
				new HashSet<System.Type> {typeof(INHibernateProxy), typeof(IPublic)},
				null, null, null);
#if NETFX
			VerifyGeneratedAssembly(
				() =>
				{
#endif
					var fieldProxy = factory.GetFieldInterceptionProxy(new PublicInterfaceTestClass());
					Assert.That(fieldProxy, Is.InstanceOf<PublicInterfaceTestClass>());
#if NETFX
				});
#endif
		}
예제 #2
0
		public void VerifyFieldInterceptorProxyWithISerializableEntity()
		{
			var factory = new StaticProxyFactory();
			factory.PostInstantiate(typeof(CustomSerializationClass).FullName, typeof(CustomSerializationClass), new HashSet<System.Type> {typeof(INHibernateProxy)}, null, null, null);
#if NETFX
			VerifyGeneratedAssembly(
				() =>
				{
#endif
					var fieldProxy = factory.GetFieldInterceptionProxy(new CustomSerializationClass());
					Assert.That(fieldProxy, Is.InstanceOf<CustomSerializationClass>());
#if NETFX
				});
#endif
		}
		public void VerifyFieldInterceptorProxy()
		{
			var factory = new StaticProxyFactory();
			factory.PostInstantiate(typeof(InternalInterfaceTestClass).FullName, typeof(InternalInterfaceTestClass), new HashSet<System.Type> {typeof(INHibernateProxy)}, null, null, null, true);
#if NETFX
			VerifyGeneratedAssembly(
				() =>
				{
#endif
					var fieldProxy = factory.GetFieldInterceptionProxy();
					Assert.That(fieldProxy, Is.InstanceOf<InternalInterfaceTestClass>());
#if NETFX
				});
#endif
		}
예제 #4
0
		public void CanSerializeFieldInterceptorProxyWithExplicitISerializableEntity()
		{
			var factory = new StaticProxyFactory();
			factory.PostInstantiate(typeof(CustomExplicitSerializationClass).FullName, typeof(CustomExplicitSerializationClass), new HashSet<System.Type> {typeof(INHibernateProxy)}, null, null, null);
			var proxy = (CustomExplicitSerializationClass) factory.GetFieldInterceptionProxy(new CustomExplicitSerializationClass());
			proxy.Id = 2;

			var serializer = GetFormatter();
			using (var memoryStream = new MemoryStream())
			{
				serializer.Serialize(memoryStream, proxy);
				memoryStream.Seek(0L, SeekOrigin.Begin);
				proxy = (CustomExplicitSerializationClass) serializer.Deserialize(memoryStream);
				Assert.That(proxy.Id, Is.EqualTo(2));
			}
		}
		public void CanSerializeFieldInterceptorProxy()
		{
			var factory = new StaticProxyFactory();
			factory.PostInstantiate(typeof(PublicInterfaceTestClass).FullName, typeof(PublicInterfaceTestClass), new HashSet<System.Type> {typeof(INHibernateProxy)}, null, null, null, true);
			var proxy = (PublicInterfaceTestClass) factory.GetFieldInterceptionProxy();
			proxy.Id = 1;

			var serializer = GetFormatter();
			using (var memoryStream = new MemoryStream())
			{
				serializer.Serialize(memoryStream, proxy);
				memoryStream.Seek(0L, SeekOrigin.Begin);
				proxy = (PublicInterfaceTestClass) serializer.Deserialize(memoryStream);
				Assert.That(proxy.Id, Is.EqualTo(1));
			}
		}
		public void VerifyProxyForClassWithGenericNonVirtualMethod()
		{
			var factory = new StaticProxyFactory();
			factory.PostInstantiate(
				typeof(ClassWithGenericNonVirtualMethod).FullName,
				typeof(ClassWithGenericNonVirtualMethod),
				new HashSet<System.Type> { typeof(INHibernateProxy) },
				null, null, null, true);

#if NETFX
			VerifyGeneratedAssembly(
				() =>
				{
#endif
					var proxy = factory.GetProxy(1, null);
					Assert.That(proxy, Is.Not.Null);
					Assert.That(proxy, Is.InstanceOf<ClassWithGenericNonVirtualMethod>());

					Assert.That(factory.GetFieldInterceptionProxy(), Is.InstanceOf<ClassWithGenericNonVirtualMethod>());

#if NETFX
				});
#endif
		}