Esempio n. 1
0
        public void SimpleNonStaticMethod()
        {
            // Create assembly
            var stringCompiler = new StringCompiler();
            var assembly       = stringCompiler.Compile(SIMPLE_NONSTATIC_METHOD);

            Assert.IsNotNull(assembly);

            // Verify that the class exists
            var exportedType = assembly.ExportedTypes.FirstOrDefault();

            Assert.IsNotNull(exportedType);
            Assert.AreEqual("SimpleNonStatic", exportedType.Name);

            // Get the contructor info and call it
            var constructor = exportedType.GetConstructors().FirstOrDefault();

            Assert.IsNotNull(constructor);
            var instance = constructor.Invoke(new object[] { "My String!" });

            Assert.IsNotNull(instance);

            // Verify that the method exists & returns the injected string
            var constructorStringMethod = exportedType.GetMethods().FirstOrDefault(m => m.Name == "GetAString" && !m.GetParameters().Any());

            Assert.IsNotNull(constructorStringMethod);
            Assert.AreEqual("My String!", constructorStringMethod.Invoke(instance, null));

            // Verify that the overloaded method works as well
            var parameterStringMethod = exportedType.GetMethods().FirstOrDefault(m => m.Name == "GetAString" && m.GetParameters().Count() == 1);

            Assert.IsNotNull(parameterStringMethod);
            Assert.AreEqual("Injected String!", parameterStringMethod.Invoke(instance, new object[] { "Injected String!" }));
        }
Esempio n. 2
0
        public void SimpleStaticFailureMethod()
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            // Create class assembly
            var stringCompiler = new StringCompiler();
            var bytes          = stringCompiler.CompileToByteArray(SIMPLE_STATIC_FAILURE_METHOD);

            Assert.IsNotNull(bytes);

            var codeAssembly = Assembly.Load(bytes);

            _assemblies[codeAssembly.FullName] = codeAssembly;

            var testAssembly = stringCompiler.Compile(SIMPLE_STATIC_METHOD_TEST, new[] { bytes });

            Assert.IsNotNull(testAssembly);

            // Verify that the class exists
            var exportedType = testAssembly.ExportedTypes.FirstOrDefault();

            Assert.IsNotNull(exportedType);
            Assert.AreEqual("SimpleStaticTests", exportedType.Name);

            // Get the contructor info and call it
            var constructor = exportedType.GetConstructors().FirstOrDefault();

            Assert.IsNotNull(constructor);
            var instance = constructor.Invoke(new object[] { });

            Assert.IsNotNull(instance);

            // Verify that the method exists & returns the appropriate response
            var getAStringMethod = exportedType.GetMethod("SimpleStatic_GetAString");

            Assert.IsNotNull(getAStringMethod);
            try
            {
                getAStringMethod.Invoke(instance, null);
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                Assert.AreEqual("Assert.AreEqual failed. Expected:<A String>. Actual:<A Failure>. ", ex.Message);
            }
        }
Esempio n. 3
0
        public void SimpleStaticMethod()
        {
            // Create assembly
            var stringCompiler = new StringCompiler();
            var assembly       = stringCompiler.Compile(SIMPLE_STATIC_METHOD);

            Assert.IsNotNull(assembly);

            // Verify that the class exists
            var exportedType = assembly.ExportedTypes.FirstOrDefault();

            Assert.IsNotNull(exportedType);
            Assert.AreEqual("SimpleStatic", exportedType.Name);

            // Verify that the method exists & returns the appropriate response
            var getAStringMethod = exportedType.GetMethod("GetAString");

            Assert.IsNotNull(getAStringMethod);
            Assert.AreEqual("A String", getAStringMethod.Invoke(null, null));
        }
Esempio n. 4
0
        public void SimpleStaticMethodUnitTest()
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            // Create class assembly
            var stringCompiler = new StringCompiler();
            var bytes          = stringCompiler.CompileToByteArray(SIMPLE_STATIC_METHOD);

            Assert.IsNotNull(bytes);

            var codeAssembly = Assembly.Load(bytes);

            _assemblies[codeAssembly.FullName] = codeAssembly;

            var testAssembly = stringCompiler.Compile(SIMPLE_STATIC_METHOD_TEST, new [] { bytes });

            Assert.IsNotNull(testAssembly);

            // Verify that the class exists
            var exportedType = testAssembly.ExportedTypes.FirstOrDefault();

            Assert.IsNotNull(exportedType);
            Assert.AreEqual("SimpleStaticTests", exportedType.Name);

            // Get the contructor info and call it
            var constructor = exportedType.GetConstructors().FirstOrDefault();

            Assert.IsNotNull(constructor);
            var instance = constructor.Invoke(new object[] {});

            Assert.IsNotNull(instance);

            // Verify that the method exists & returns the appropriate response
            var getAStringMethod = exportedType.GetMethod("SimpleStatic_GetAString");

            Assert.IsNotNull(getAStringMethod);
            getAStringMethod.Invoke(instance, null);
        }
        public void SimpleStaticMethod()
        {
            // Create assembly
            var stringCompiler = new StringCompiler();
            var assembly = stringCompiler.Compile(SIMPLE_STATIC_METHOD);
            Assert.IsNotNull(assembly);

            // Verify that the class exists
            var exportedType = assembly.ExportedTypes.FirstOrDefault();
            Assert.IsNotNull(exportedType);
            Assert.AreEqual("SimpleStatic", exportedType.Name);

            // Verify that the method exists & returns the appropriate response
            var getAStringMethod = exportedType.GetMethod("GetAString");
            Assert.IsNotNull(getAStringMethod);
            Assert.AreEqual("A String", getAStringMethod.Invoke(null,null));
        }
        public void SimpleStaticFailureMethod()
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            // Create class assembly
            var stringCompiler = new StringCompiler();
            var bytes = stringCompiler.CompileToByteArray(SIMPLE_STATIC_FAILURE_METHOD);
            Assert.IsNotNull(bytes);

            var codeAssembly = Assembly.Load(bytes);
            _assemblies[codeAssembly.FullName] = codeAssembly;

            var testAssembly = stringCompiler.Compile(SIMPLE_STATIC_METHOD_TEST, new[] { bytes });
            Assert.IsNotNull(testAssembly);

            // Verify that the class exists
            var exportedType = testAssembly.ExportedTypes.FirstOrDefault();
            Assert.IsNotNull(exportedType);
            Assert.AreEqual("SimpleStaticTests", exportedType.Name);

            // Get the contructor info and call it
            var constructor = exportedType.GetConstructors().FirstOrDefault();
            Assert.IsNotNull(constructor);
            var instance = constructor.Invoke(new object[] { });
            Assert.IsNotNull(instance);

            // Verify that the method exists & returns the appropriate response
            var getAStringMethod = exportedType.GetMethod("SimpleStatic_GetAString");
            Assert.IsNotNull(getAStringMethod);
            try
            {
                getAStringMethod.Invoke(instance, null);
            }
            catch(Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                Assert.AreEqual("Assert.AreEqual failed. Expected:<A String>. Actual:<A Failure>. ", ex.Message);
            }
        }
        public void SimpleStaticMethodUnitTest()
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            // Create class assembly
            var stringCompiler = new StringCompiler();
            var bytes = stringCompiler.CompileToByteArray(SIMPLE_STATIC_METHOD);
            Assert.IsNotNull(bytes);

            var codeAssembly = Assembly.Load(bytes);
            _assemblies[codeAssembly.FullName] = codeAssembly;

            var testAssembly = stringCompiler.Compile(SIMPLE_STATIC_METHOD_TEST, new [] { bytes });
            Assert.IsNotNull(testAssembly);

            // Verify that the class exists
            var exportedType = testAssembly.ExportedTypes.FirstOrDefault();
            Assert.IsNotNull(exportedType);
            Assert.AreEqual("SimpleStaticTests", exportedType.Name);

            // Get the contructor info and call it
            var constructor = exportedType.GetConstructors().FirstOrDefault();
            Assert.IsNotNull(constructor);
            var instance = constructor.Invoke(new object[] {});
            Assert.IsNotNull(instance);

            // Verify that the method exists & returns the appropriate response
            var getAStringMethod = exportedType.GetMethod("SimpleStatic_GetAString");
            Assert.IsNotNull(getAStringMethod);
            getAStringMethod.Invoke(instance, null);
        }
        public void SimpleNonStaticMethod()
        {
            // Create assembly
            var stringCompiler = new StringCompiler();
            var assembly = stringCompiler.Compile(SIMPLE_NONSTATIC_METHOD);
            Assert.IsNotNull(assembly);

            // Verify that the class exists
            var exportedType = assembly.ExportedTypes.FirstOrDefault();
            Assert.IsNotNull(exportedType);
            Assert.AreEqual("SimpleNonStatic", exportedType.Name);

            // Get the contructor info and call it
            var constructor = exportedType.GetConstructors().FirstOrDefault();
            Assert.IsNotNull(constructor);
            var instance = constructor.Invoke(new object[] {"My String!"});
            Assert.IsNotNull(instance);

            // Verify that the method exists & returns the injected string
            var constructorStringMethod = exportedType.GetMethods().FirstOrDefault(m => m.Name == "GetAString" && !m.GetParameters().Any());
            Assert.IsNotNull(constructorStringMethod);
            Assert.AreEqual("My String!", constructorStringMethod.Invoke(instance, null));

            // Verify that the overloaded method works as well
            var parameterStringMethod = exportedType.GetMethods().FirstOrDefault(m => m.Name == "GetAString" && m.GetParameters().Count() == 1);
            Assert.IsNotNull(parameterStringMethod);
            Assert.AreEqual("Injected String!", parameterStringMethod.Invoke(instance, new object[] {"Injected String!"}));
        }