public void Generates_Proxies_From_Single_Assembly() { CrossAppDomainCaller.RunInOtherAppDomain(delegate { Type personType = typeof(Person); Assembly proxyAssembly = _generator.Generate(CreateOptions(_outputAssemblyPath, personType.Assembly.Location)); Assert.IsNotNull(proxyAssembly); Type personProxyType = null; foreach (Type type in proxyAssembly.GetTypes()) { if (type.BaseType == personType) { personProxyType = type; break; } } Assert.IsNotNull(personProxyType); Assert.IsTrue(typeof(INHibernateProxy).IsAssignableFrom(personProxyType)); }); }
public TProxy CreateProxy <TProxy>(TProxy obj, Predicate <MethodInfo> methodIncluder, ILock theLock) where TProxy : class { if (obj == null) { throw new ArgumentNullException("obj"); } if (methodIncluder == null) { throw new ArgumentNullException("methodIncluder"); } if (theLock == null) { throw new ArgumentNullException("theLock"); } if (!_proxyGenerator.CanProxy <TProxy>()) { throw new ArgumentException(string.Format(ExceptionMessages.ObjectNotSupportedByProxyGeneratorFormat, typeof(TProxy).FullName)); } var interceptor = _threadSafeInterceptorFactory.CreateInterceptor(theLock, methodIncluder); return(_proxyGenerator.Generate(obj, interceptor)); }
public int Execute(TextWriter error, params string[] args) { ProxyGeneratorOptions generatorOptions = new ProxyGeneratorOptions(); if (Parser.ParseHelp(args)) { Parser.ParseArguments(args, generatorOptions); } else if (Parser.ParseArguments(args, generatorOptions) == false) { error.WriteLine(Parser.ArgumentsUsage(generatorOptions.GetType())); return(Error.InvalidArguments); } if (_proxyGenerator == null) { try { _proxyGenerator = CreateProxyGenerator(generatorOptions.Generator); } catch (Exception exc) { error.WriteLine(exc.Message); return(Error.CreateProxyGenerator); } } generatorOptions = _proxyGenerator.GetOptions(); if (generatorOptions == null) { error.WriteLine("{0}.GetOptions() returned null. Please use a different Generator.", _proxyGenerator.GetType().FullName); return(Error.InvalidGenerator); } if (Parser.ParseHelp(args)) { error.WriteLine(Parser.ArgumentsUsage(generatorOptions.GetType())); return(Error.None); } if (Parser.ParseArguments(args, generatorOptions) == false) { error.WriteLine(Parser.ArgumentsUsage(generatorOptions.GetType())); return(Error.InvalidArguments); } try { _proxyGenerator.Generate(generatorOptions); } catch (Exception exc) { error.WriteLine(exc.Message); error.WriteLine(exc.StackTrace); return(Error.Unknown); } return(Error.None); }
public void Valid_Options_Generates_Proxies() { SetupResult.For(_generator.Generate(null)) .IgnoreArguments() .Return(null); _mocks.ReplayAll(); int exitCode = _program.Execute(_error, "/o:Output.dll", typeof(string).Assembly.Location); Assert.AreEqual(Error.None, exitCode); _mocks.VerifyAll(); }