/// <summary/> public override bool RunMyTests() { int numTests = scripts.Length + unitTests.Length; skippedTests = new ArrayList(); failedTests = new ArrayList(); foreach (string script in scripts) { string localScript = TrustedPath.GetFileName(script); try { RunATest(tokens, localScript, false); } catch (InvalidScriptFileException) { Logger.Log(string.Format(" {0} is not a valid script file - Skipping...", localScript)); Logger.Log(""); numTests--; skippedTests.Add(localScript); } catch (Exception ex) { Logger.Log(" The test script threw an exception:"); Logger.Log(ex.ToString()); if (RenderingTest.window != null) { RenderingTest.window.Dispose(); RenderingTest.window = null; } failedTests.Add(localScript); } } foreach (string testName in unitTests) { try { RunATest(tokens, testName, true); } catch (Exception ex) { Logger.Log(" The test threw an exception:"); Logger.Log(ex.ToString()); failedTests.Add(testName); } } PrintRunAllResults(); Logger.LogRunAllResults(failedTests.Count, numTests); return(failedTests.Count == 0); }
/// <summary> /// Generate some code that inherits from the class specified by VARIATION. /// If we can't inherit from the class we should see compiler errors. /// </summary> public override void RunTheTest() { // Create the compiler and set necessary options. // We will compile the code as a library so that we don't have to write a Main method. CSharpCodeProvider compiler = new CSharpCodeProvider(); CompilerParameters options = new CompilerParameters(); options.GenerateInMemory = true; options.GenerateExecutable = false; options.IncludeDebugInformation = false; options.OutputAssembly = "inherit.dll"; options.ReferencedAssemblies.Add("System.dll"); options.ReferencedAssemblies.Add(TrustedPath.Combine(dotnetPath, "PresentationCore.dll")); options.ReferencedAssemblies.Add(TrustedPath.Combine(dotnetPath, "PresentationFramework.dll")); options.ReferencedAssemblies.Add(TrustedPath.Combine(dotnetPath, "WindowsBase.dll")); // Compile the generated code CompilerResults results = compiler.CompileAssemblyFromSource(options, GeneratedSource); // Check the results of compilation if (results.Errors.HasErrors) { if (canInherit) { AddFailure("I should be able to inherit from: " + className); Log("Compiler Errors:\n{0}", CompilerErrorsToString(results.Errors)); Log("\r\nGenerated source:\r\n{0}", FormattedSource); } else { // Make sure we have the correct compiler errors string[] expectedText = (type.IsSealed) ? new string[] { "cannot", "derive" } : new string[] { "no", "constructors" }; if (!VerifyCorrectCompilerErrors(results.Errors, expectedText)) { AddFailure("This test is broken and needs to be investigated"); Log("Compiler Errors:\n{0}", CompilerErrorsToString(results.Errors)); Log("\r\nGenerated source:\r\n{0}", FormattedSource); } } } else // compilation succeeded { if (!canInherit) { AddFailure("I should not be able to inherit from: " + className); Log("\r\nGenerated source:\r\n{0}", FormattedSource); } } }
/// <summary/> public override void Init(Variation v) { base.Init(v); v.AssertExistenceOf("ClassName", "Namespace", "CanInherit", "Assembly"); this.className = v["ClassName"]; this.nameSpace = v["Namespace"]; string inherit = v["CanInherit"]; string asm = v["Assembly"]; dotnetPath = v["DotnetPath"]; // We define this for local testing if we don't use avalon.msi if (dotnetPath == null) { try { dotnetPath = EnvironmentWrapper.GetEnvironmentVariable("LAPI"); } catch (System.Security.SecurityException ex) { AddFailure("Could not access the Environment variable: LAPI"); Log("Exception: " + ex); } if (dotnetPath == null) { throw new ApplicationException("LAPI is not defined. I can't find my binaries."); } } Log("DotnetPath = " + dotnetPath); TrustedAssembly assembly = TrustedAssembly.LoadFile(TrustedPath.Combine(dotnetPath, asm)); this.type = assembly.GetType(nameSpace + "." + className); if (type == null) { throw new ApplicationException(nameSpace + "." + className + " was not found in " + asm); } this.classGenerator = new ClassGenerator(type); this.canInherit = StringConverter.ToBool(inherit); }
/// <summary/> public override void Init(Variation v) { base.Init(v); parameters = new XamlTestObjects(v); logPrefix = TrustedPath.GetFileNameWithoutExtension(parameters.Filename) + "_" + TwoDigitVariationID(v.ID); }