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 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); }