public void CanExportAopProxyToLibrary()
        {
            // NOTE: the method interceptor will return the number of method calls intercepted
            FileInfo assemblyFile               = new FileInfo("ServiceComponentExporterTests.TestServicedComponents.dll");
            XmlApplicationContext      appCtx   = new XmlApplicationContext("ServiceComponentExporterTests.TestServicedComponents.Services.xml");
            EnterpriseServicesExporter exporter = new EnterpriseServicesExporter();

            exporter.ActivationMode = ActivationOption.Library;
            Type serviceType = ExportObject(exporter, assemblyFile, appCtx, "objectTest");

            try
            {
                // ServiceComponent will obtain its target from root context
//                ContextRegistry.RegisterContext(appCtx);

                IComparable testObject;
                testObject = (IComparable)Activator.CreateInstance(serviceType);
                Assert.AreEqual(1, testObject.CompareTo(null));
                testObject = (IComparable)Activator.CreateInstance(serviceType);
                Assert.AreEqual(2, testObject.CompareTo(null));
            }
            finally
            {
                exporter.UnregisterServicedComponents(assemblyFile);
                ContextRegistry.Clear();
            }
        }
        private Type CreateWrapperType(ServicedComponentExporter exporter, Type targetType, bool useSpring)
        {
            AssemblyName an = new AssemblyName();

            an.Name = "Spring.EnterpriseServices.Tests";
            AssemblyBuilder proxyAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave);
            ModuleBuilder   module        = proxyAssembly.DefineDynamicModule(an.Name, an.Name + ".dll", true);

            Type baseType = typeof(ServicedComponent);

            if (useSpring)
            {
                baseType = EnterpriseServicesExporter.CreateSpringServicedComponentType(module, baseType);
            }

            object result = exporter.CreateWrapperType(module, baseType, targetType, useSpring);

            Assert.IsNotNull(result);
            Assert.IsTrue(result is Type);

            return((Type)result);
        }
        private Type ExportObject(EnterpriseServicesExporter exporter, FileInfo assemblyFile, IConfigurableApplicationContext appCtx, string objectName)
        {
            exporter.ObjectFactory   = appCtx.ObjectFactory;
            exporter.Assembly        = Path.GetFileNameWithoutExtension(assemblyFile.Name);
            exporter.ApplicationName = exporter.Assembly;
            exporter.AccessControl   = new ApplicationAccessControlAttribute(false);
            exporter.UseSpring       = true;

            ServicedComponentExporter exp = new ServicedComponentExporter();

            exp.TargetName     = objectName;
            exp.ObjectName     = objectName + "Service";
            exp.TypeAttributes = new ArrayList();
            exp.TypeAttributes.Add(new TransactionAttribute(TransactionOption.RequiresNew));
            exp.AfterPropertiesSet();

            exporter.Components.Add(exp);

            Assembly assembly = exporter.GenerateComponentAssembly(assemblyFile);

            exporter.RegisterServicedComponents(assemblyFile);
            return(assembly.GetType(objectName + "Service"));
        }
        public void CanExportAopProxyToServer()
        {
            FileInfo assemblyFile               = new FileInfo("ServiceComponentExporterTests.TestServicedComponents.exe");
            XmlApplicationContext      appCtx   = new XmlApplicationContext("ServiceComponentExporterTests.TestServicedComponents.Services.xml");
            EnterpriseServicesExporter exporter = new EnterpriseServicesExporter();

            exporter.ActivationMode = ActivationOption.Server;
            Type serviceType = ExportObject(exporter, assemblyFile, appCtx, "objectTest");

            try
            {
                // ServiceComponent will obtain its target from root context
                IComparable testObject;
                testObject = (IComparable)Activator.CreateInstance(serviceType);
                Assert.AreEqual(1, testObject.CompareTo(null));
                testObject = (IComparable)Activator.CreateInstance(serviceType);
                Assert.AreEqual(2, testObject.CompareTo(null));
            }
            finally
            {
                exporter.UnregisterServicedComponents(assemblyFile);
            }
        }
        private Type ExportObject(EnterpriseServicesExporter exporter, FileInfo assemblyFile, IConfigurableApplicationContext appCtx, string objectName)
        {
            exporter.ObjectFactory = appCtx.ObjectFactory;
            exporter.Assembly = Path.GetFileNameWithoutExtension(assemblyFile.Name);
            exporter.ApplicationName = exporter.Assembly;
            exporter.AccessControl = new ApplicationAccessControlAttribute(false);
            exporter.UseSpring = true;

            ServicedComponentExporter exp = new ServicedComponentExporter();
            exp.TargetName = objectName;
            exp.ObjectName = objectName + "Service";
            exp.TypeAttributes = new ArrayList();
            exp.TypeAttributes.Add(new TransactionAttribute(TransactionOption.RequiresNew));
            exp.AfterPropertiesSet();

            exporter.Components.Add(exp);

            Assembly assembly = exporter.GenerateComponentAssembly(assemblyFile);
            exporter.RegisterServicedComponents(assemblyFile);
            return assembly.GetType(objectName + "Service");
        }
 public void CanExportAopProxyToServer()
 {
     FileInfo assemblyFile = new FileInfo("ServiceComponentExporterTests.TestServicedComponents.exe");
     XmlApplicationContext appCtx = new XmlApplicationContext("ServiceComponentExporterTests.TestServicedComponents.Services.xml");
     EnterpriseServicesExporter exporter = new EnterpriseServicesExporter();
     exporter.ActivationMode = ActivationOption.Server;
     Type serviceType = ExportObject(exporter, assemblyFile, appCtx, "objectTest");
     try
     {
         // ServiceComponent will obtain its target from root context
         IComparable testObject;
         testObject = (IComparable)Activator.CreateInstance(serviceType);
         Assert.AreEqual(1, testObject.CompareTo(null));
         testObject = (IComparable)Activator.CreateInstance(serviceType);
         Assert.AreEqual(2, testObject.CompareTo(null));
     }
     finally
     {
         exporter.UnregisterServicedComponents(assemblyFile);
     }
 }
        public void CanExportAopProxyToLibrary()
        {
            // NOTE: the method interceptor will return the number of method calls intercepted
            FileInfo assemblyFile = new FileInfo("ServiceComponentExporterTests.TestServicedComponents.dll");
            XmlApplicationContext appCtx = new XmlApplicationContext("ServiceComponentExporterTests.TestServicedComponents.Services.xml");
            EnterpriseServicesExporter exporter = new EnterpriseServicesExporter();
            exporter.ActivationMode = ActivationOption.Library;
            Type serviceType = ExportObject(exporter, assemblyFile, appCtx, "objectTest");
            try
            {
                // ServiceComponent will obtain its target from root context
//                ContextRegistry.RegisterContext(appCtx);

                IComparable testObject;
                testObject = (IComparable)Activator.CreateInstance(serviceType);
                Assert.AreEqual(1, testObject.CompareTo(null));
                testObject = (IComparable)Activator.CreateInstance(serviceType);
                Assert.AreEqual(2, testObject.CompareTo(null));
            }
            finally
            {
                exporter.UnregisterServicedComponents(assemblyFile);
                ContextRegistry.Clear();
            }
        }