private TaskResult Finish(IRemoteTaskServer server, CSUnitTestFixtureTask fixture) { if (myFixtureTearDown != null) { server.TaskProgress(fixture, "Tearing down..."); try { TaskExecutor.Invoke(fixture.Instance, myFixtureTearDown); } catch (TargetInvocationException e) { Exception exception = e.InnerException ?? e; string message; Server.TaskException(fixture, TaskExecutor.ConvertExceptions(exception, out message)); Server.TaskFinished(fixture, message, TaskResult.Exception); return TaskResult.Exception; } } server.TaskProgress(fixture, ""); myTestTearDown = null; myTestSetUp = null; myFixtureSetUp = null; myFixtureTearDown = null; fixture.Instance = null; return TaskResult.Success; }
private static Type GetFixtureType(CSUnitTestFixtureTask fixture, IRemoteTaskServer server) { string assemblyLocation = fixture.AssemblyLocation; if (!File.Exists(assemblyLocation)) { server.TaskError(fixture, string.Format("Cannot load assembly from {0}: file not exists", assemblyLocation)); return null; } AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyLocation); if (assemblyName == null) { server.TaskError(fixture, string.Format("Cannot load assembly from {0}: not an assembly", assemblyLocation)); return null; } Assembly assembly = Assembly.Load(assemblyName); if (assembly == null) { server.TaskError(fixture, string.Format("Cannot load assembly from {0}", assemblyLocation)); return null; } return assembly.GetType(fixture.TypeName); }
private TaskResult Start(IRemoteTaskServer server, TaskExecutionNode node, CSUnitTestFixtureTask fixture) { server.TaskProgress(fixture, "Instantiating..."); Type type = GetFixtureType(fixture, server); if (type == null) return TaskResult.Error; string ignoreReason; if (IsIgnored(type, out ignoreReason)) { // fixture is ignored if (!fixture.Explicitly) { // check that we don't have any explicitly run test bool hasExplicitTest = false; foreach (TaskExecutionNode testNode in node.Children) { if (((CSUnitTestTask) testNode.RemoteTask).Explicitly) { hasExplicitTest = true; break; } } if (!hasExplicitTest) { server.TaskProgress(fixture, ""); server.TaskFinished(fixture, ignoreReason, TaskResult.Skipped); return TaskResult.Skipped; } } } ConstructorInfo ci = type.GetConstructor(Type.EmptyTypes); if (ci == null) { server.TaskError(fixture, string.Format("Cannot find parameterless constructor on type '{0}'", type)); return TaskResult.Error; } if (!BuildTypeInfo(server, fixture, type)) return TaskResult.Error; object instance = ci.Invoke(new object[0]); if (instance == null) { server.TaskError(fixture, string.Format("Cannot create instance of type '{0}'", type)); return TaskResult.Error; } fixture.Instance = instance; if (myFixtureSetUp != null) { server.TaskProgress(fixture, "Setting up..."); try { TaskExecutor.Invoke(fixture.Instance, myFixtureSetUp); } catch (TargetInvocationException e) { Exception exception = e.InnerException ?? e; string message; Server.TaskException(fixture, TaskExecutor.ConvertExceptions(exception, out message)); Server.TaskFinished(fixture, message, TaskResult.Exception); return TaskResult.Exception; } } server.TaskProgress(fixture, ""); return TaskResult.Success; }