Ejemplo n.º 1
0
        public Type FindType(string className)
        {
            //Load();

            if (LoadedAssembly == null)
            {
                return(null);
            }

            return(LoadedAssembly.GetType(className));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a data wrapper from a <see cref="JObject"/>.
        /// </summary>
        /// <typeparam name="T">The source data type as defined in the within the unit test assembly.</typeparam>
        /// <param name="jObject">The <see cref="JObject"/>.</param>
        /// <returns>The new <see cref="DataWrapper"/>.</returns>
        public DataWrapper CreateDataWrapperFrom <T>(JObject jObject)
        {
            var sourceType = typeof(T);
            var targetType = LoadedAssembly.GetType($"{DefaultNamespace}.{sourceType.Name}");

            if (targetType == null)
            {
                throw new TypeLoadException($"Cannot find type: {DefaultNamespace}.{sourceType.Name}");
            }

            return(new DataWrapper(targetType, jObject));
        }
Ejemplo n.º 3
0
        public CommandResult Execute()
        {
            AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (sender, args) =>
            {
                if (Verbose)
                {
                    Console.WriteLine($"Trying to load: {args.Name}");
                }

                var name         = new AssemblyName(args.Name);
                var possiblePath = Path.Combine(
                    Path.GetDirectoryName(AssemblyPath),
                    name.Name + ".dll");

                Assembly assembly;
                if (File.Exists(possiblePath))
                {
                    if (Verbose)
                    {
                        Console.WriteLine($"Loading by path: {possiblePath}");
                    }
                    assembly = Assembly.ReflectionOnlyLoadFrom(possiblePath);
                }
                else
                {
                    assembly = Assembly.ReflectionOnlyLoad(args.Name);
                }

                if (assembly == null)
                {
                    Console.Error.WriteLine($"Error: Failed to load: {args.Name}");
                }

                return(assembly);
            };

            LoadedAssembly = ReflectionOnly ? Assembly.ReflectionOnlyLoadFrom(AssemblyPath) : Assembly.LoadFrom(AssemblyPath);
            LoadedType     = LoadedAssembly.GetType(TypeName);
            if (LoadedType == null)
            {
                Console.Error.WriteLine($"Error: unable to load type: {TypeName}");
                return(CommandResult.RuntimeFailure);
            }

            return(Command.Execute());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a service wrapper>.
        /// </summary>
        /// <typeparam name="T">The source service type as defined in the within the unit test assembly.</typeparam>
        /// <param name="baseAddress">The base address to use for the created client.</param>
        /// <returns>The new <see cref="ServiceWrapper"/>.</returns>
        public ServiceWrapper CreateServiceWrapper <T>(string baseAddress)
        {
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(baseAddress));

            const string controllerSuffix = "Controller";

            var sourceType     = typeof(T);
            var clientTypeName = sourceType.Name;

            if (clientTypeName.EndsWith(controllerSuffix))
            {
                clientTypeName = clientTypeName.Substring(0, clientTypeName.Length - controllerSuffix.Length);
            }

            var targetType = LoadedAssembly.GetType($"{DefaultNamespace}.{clientTypeName}Client");

            if (targetType == null)
            {
                throw new TypeLoadException($"Cannot find type: {DefaultNamespace}.{sourceType.Name}");
            }

            return(new ServiceWrapper(targetType, baseAddress, this));
        }