Example #1
0
        static RewriteTest()
        {
            // Get the original assembly
            _asmOriginal = typeof(RewriteOriginal.MyClass).Assembly;
            var originalAssembly = _asmOriginal.Location;

            // Generate the cloned assembly
            // NB: putting it in the "cloned" sub directory prevents an
            //     issue with someone (VisStudio perhaps) having the file open
            //     and preventing rewrite on subsequent run.
            var outDir = Path.Join(Path.GetDirectoryName(originalAssembly), "cloned");

            Directory.CreateDirectory(outDir);
            var clonedAssembly = Path.Join(outDir, "RewriteClone.dll");

            // Rewrite it (renaming the assembly and namespaces in the process)
            var generator = new AssemblyGenerator();

            generator.RenameForTesting("RewriteOriginal", "RewriteClone");
            generator.GenerateAssembly(_asmOriginal, clonedAssembly);

            _namespaceName = "RewriteClone";
            _assembly      = clonedAssembly;

            // Uncomment these two lines to run with the original uncloned assembly
            // (handy to check if test case is wrong)
            //_namespaceName = "RewriteOriginal";
            //_assembly = originalAssembly;

            _asmCloned = Assembly.LoadFrom(_assembly);
        }
Example #2
0
        static RewriteTest()
        {
            // Get the original assembly
            _asmOriginal = typeof(TestSubject.MyClass).Assembly;
            _asmCloned   = typeof(TestSubject.MyClass).Assembly;
            var originalAssembly = _asmOriginal.Location;


#if USE_ORIGINAL_TESTSUBJECT
            _namespaceName = "TestSubject";
            _assembly      = originalAssembly;
#else
            // Generate the cloned assembly
            // NB: putting it in the "cloned" sub directory prevents an
            //     issue with someone (VisStudio perhaps) having the file open
            //     and preventing rewrite on subsequent run.
            var outDir = Path.Combine(Path.GetDirectoryName(originalAssembly), "cloned");
            Directory.CreateDirectory(outDir);
            var clonedAssembly = Path.Combine(outDir, "ClonedTestSubject.dll");

            // Rewrite it (renaming the assembly and namespaces in the process)
            var generator = new AssemblyGenerator();
            generator.RenameForTesting("TestSubject", "ClonedTestSubject");
            generator.GenerateAssembly(_asmOriginal, clonedAssembly);

            _namespaceName = "ClonedTestSubject";
            _assembly      = clonedAssembly;

            _asmCloned = Assembly.LoadFrom(_assembly);
#endif
        }
Example #3
0
        async Task Run()
        {
            // Get the original assembly
            _asmOriginal = typeof(SandboxSubject.MyClass).Assembly;
            _asmCloned   = typeof(SandboxSubject.MyClass).Assembly;
            var originalAssembly = _asmOriginal.Location;


#if USE_ORIGINAL_SANDBOXSUBJECT
            _namespaceName = "SandboxSubject";
            _assembly      = originalAssembly;
#else
            // Generate the cloned assembly
            // NB: putting it in the "cloned" sub directory prevents an
            //     issue with someone (VisStudio perhaps) having the file open
            //     and preventing rewrite on subsequent run.
            var outDir = Path.Join(Path.GetDirectoryName(originalAssembly), "cloned");
            Directory.CreateDirectory(outDir);
            var clonedAssembly = Path.Join(outDir, "ClonedSandboxSubject.dll");

            // Rewrite it (renaming the assembly and namespaces in the process)
            var generator = new AssemblyGenerator();
            generator.RenameForTesting("SandboxSubject", "ClonedSandboxSubject");
            generator.GenerateAssembly(_asmOriginal, clonedAssembly);

            _namespaceName = "ClonedSandboxSubject";
            _assembly      = clonedAssembly;

            _asmCloned = Assembly.LoadFrom(_assembly);
#endif


            // Invoke the cloned assembly...

            var result = await Invoke(
                $"var r = x.Test();",
                "r"
                );

            Console.WriteLine(result);
        }