public void BindValues(string document, char fieldDelimiter, char commentPrefix, bool hasHeader, int?bindingIndex, string bindingPath, string[] expectedValues) { Gallio.Common.GallioFunc <TextReader> documentReaderProvider = delegate { return(new StringReader(document)); }; CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false); dataSet.FieldDelimiter = fieldDelimiter; Assert.AreEqual(fieldDelimiter, dataSet.FieldDelimiter); dataSet.CommentPrefix = commentPrefix; Assert.AreEqual(commentPrefix, dataSet.CommentPrefix); dataSet.HasHeader = hasHeader; Assert.AreEqual(hasHeader, dataSet.HasHeader); DataBinding binding = new DataBinding(bindingIndex, bindingPath); List <IDataItem> items = new List <IDataItem>(dataSet.GetItems(new DataBinding[] { binding }, true)); string[] actualValues = GenericCollectionUtils.ConvertAllToArray <IDataItem, string>(items, delegate(IDataItem item) { return((string)item.GetValue(binding)); }); Assert.AreEqual(expectedValues, actualValues); }
/// <inheritdoc /> public IEnumerable <IDataItem> Merge(IList <IDataProvider> providers, ICollection <DataBinding> bindings, bool includeDynamicItems) { var previousValues = new GallioHashSet <object[]>(new ArrayEqualityComparer <object>()); foreach (IDataProvider provider in providers) { foreach (IDataItem item in provider.GetItems(bindings, includeDynamicItems)) { try { object[] values = GenericCollectionUtils.ConvertAllToArray <DataBinding, object>(bindings, delegate(DataBinding binding) { return(item.GetValue(binding)); }); if (previousValues.Contains(values)) { continue; } previousValues.Add(values); } catch { // Always consider items whose bindings cannot be evaluated correctly as distinct. } yield return(item); } } }
private void AssertContainsStaticVersionsOfDeclaredMethods(Type sourceType, params string[] excludedMethodNames) { foreach (MethodInfo sourceMethod in sourceType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { if (Array.IndexOf(excludedMethodNames, sourceMethod.Name) >= 0) { continue; } Type[] parameterTypes = GenericCollectionUtils.ConvertAllToArray <ParameterInfo, Type>(sourceMethod.GetParameters(), delegate(ParameterInfo parameter) { return(parameter.ParameterType); }); MethodInfo targetMethod = typeof(TestLog).GetMethod(sourceMethod.Name, BindingFlags.Static | BindingFlags.Public, null, parameterTypes, null); Assert.IsNotNull(targetMethod, "Log is missing a static method '{0}({1})' corresponding to those defined by type {2}", sourceMethod.Name, string.Join(", ", Array.ConvertAll <Type, string>(parameterTypes, delegate(Type type) { return(type.Name); })), sourceType.FullName); Assert.AreEqual(sourceMethod.ReturnType, targetMethod.ReturnType); TestLog.WriteLine("Found method '{0}'", sourceMethod.Name); } }
private static Type[] ResolveTypesWithMethodContext(ICollection <ITypeInfo> types, MethodInfo methodContext) { return(GenericCollectionUtils.ConvertAllToArray <ITypeInfo, Type>(types, delegate(ITypeInfo argument) { return ResolveTypeWithMethodContext(argument, methodContext); })); }
private static Type[] ResolveParameterTypes(ICollection <IParameterInfo> parameters) { return(GenericCollectionUtils.ConvertAllToArray <IParameterInfo, Type>(parameters, delegate(IParameterInfo parameter) { return parameter.ValueType.Resolve(true); })); }
private static ComponentHandle <IFileTypeRecognizer, FileTypeRecognizerTraits>[] CreateRecognizerHandles( params RecognizerInfo[] recognizerInfos) { return(GenericCollectionUtils.ConvertAllToArray(recognizerInfos, recognizerInfo => ComponentHandle.CreateStub("component", recognizerInfo.Recognizer ?? MockRepository.GenerateStub <IFileTypeRecognizer>(), recognizerInfo.Traits ?? new FileTypeRecognizerTraits("Dummy", "Dummy")))); }
private IEnumerable <IDataItem> GetItemsImplTranslated(ICollection <DataBinding> bindings, bool includeDynamicItems) { DataBinding[] translatedBindings = GenericCollectionUtils.ConvertAllToArray <DataBinding, DataBinding>(bindings, TranslateBinding); foreach (IDataItem item in GetItemsImplBase(translatedBindings, includeDynamicItems)) { yield return(new TranslatedDataItem(this, item)); } }
public void IsMatchCombinations(bool expectedMatch, bool[] states) { Filter <object>[] filters = GenericCollectionUtils.ConvertAllToArray <bool, Filter <object> >(states, delegate(bool state) { return(state ? (Filter <object>) new AnyFilter <object>() : new NoneFilter <object>()); }); AndFilter <object> combinator = new AndFilter <object>(filters); Assert.AreEqual(expectedMatch, combinator.IsMatch(0)); }
public IList <IComponentDescriptor> FindComponentsByServiceId(string serviceId) { IList <ComponentDescriptor> components; if (componentsByServiceId.TryGetValue(serviceId, out components)) { return(new ReadOnlyCollection <IComponentDescriptor>(GenericCollectionUtils.ConvertAllToArray(components, d => d))); } return(EmptyArray <IComponentDescriptor> .Instance); }
private bool Load() { bool succeeded = true; inputReports = GenericCollectionUtils.ConvertAllToArray(inputFileNames, x => { Report report; succeeded &= LoadReport(x.First, x.Second, out report); return(report); }); return(succeeded); }
protected override object GetValueImpl(IDataItem item) { KeyValuePair <ISlotInfo, object>[] slotValues = GenericCollectionUtils.ConvertAllToArray < KeyValuePair <ISlotInfo, IDataAccessor>, KeyValuePair <ISlotInfo, object> >(slotAccessors, delegate(KeyValuePair <ISlotInfo, IDataAccessor> slotAccessor) { object value = slotAccessor.Value.GetValue(item); return(new KeyValuePair <ISlotInfo, object>(slotAccessor.Key, value)); }); ObjectCreationSpec spec = new ObjectCreationSpec(type, slotValues, converter); return(spec.CreateInstance()); }
private static object[] GetValues(IDataItem item, ICollection <DataBinding> bindings) { try { return(GenericCollectionUtils.ConvertAllToArray <DataBinding, object>(bindings, delegate(DataBinding binding) { return item.GetValue(binding); })); } catch { return(null); } }
private void InstallActions() { if (commandPresentations != null) { return; } commandPresentations = new Dictionary <string, CommandPresentation>(); foreach (var commandHandle in commandHandles) { CommandTraits traits = commandHandle.GetTraits(); Commands2 commands = (Commands2)shell.DTE.Commands; Command command; try { command = commands.Item(traits.CommandName, 0); } catch { object[] contextGuids = null; command = commands.AddNamedCommand2(shell.ShellAddIn, traits.CommandName, traits.Caption, traits.Tooltip, true, 59, ref contextGuids, (int)ToVsCommandStatus(traits.Status), (int)ToVsCommandStyle(traits.Style), ToVsCommandControlType(traits.ControlType)); } CommandBarButton[] controls = GenericCollectionUtils.ConvertAllToArray(traits.CommandBarPaths, commandBarPath => { CommandBar commandBar = GetCommandBar(commandBarPath); CommandBarButton commandBarButton = GetOrCreateCommandBarButton(commandBar, command, commands); return(commandBarButton); }); CommandPresentation presentation = new CommandPresentation(commandHandle, command, controls); presentation.Icon = traits.Icon; presentation.Caption = traits.Caption; presentation.Tooltip = traits.Tooltip; presentation.Status = traits.Status; commandPresentations.Add(traits.CommandName, presentation); } }
public TestRunnerFactoryPane(IOptionsController optionsController) { this.optionsController = optionsController; InitializeComponent(); // retrieve list of possible factories var testRunnerManager = RuntimeAccessor.ServiceLocator.Resolve <ITestRunnerManager>(); string[] factories = GenericCollectionUtils.ConvertAllToArray(testRunnerManager.TestRunnerFactoryHandles, h => h.GetTraits().Name); testRunnerFactories.Items.AddRange(factories); testRunnerFactories.Text = optionsController.TestRunnerFactory; }
private bool Prepare() { outputPath = Args.ReportOutput ?? Environment.CurrentDirectory; try { inputFileNames = GenericCollectionUtils.ConvertAllToArray(Args.ReportPaths, path => new Pair <string, string>(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path))); } catch (ArgumentException exception) { Context.Logger.Log(LogSeverity.Error, "One or several of the specified reports are not valid file paths.", exception); return(false); } return(ReportArchive.TryParse(Args.ReportArchive, out reportArchive)); }
public void GetPreOrderTraversal() { Node root = new Node(1, new Node(2, new Node(3), new Node(4), new Node(5)), new Node(6, new Node(7, new Node(8))), new Node(9)); List <Node> nodes = new List <Node>(TreeUtils.GetPreOrderTraversal(root, delegate(Node node) { return(node.Children); })); IList <int> ids = GenericCollectionUtils.ConvertAllToArray <Node, int>(nodes, delegate(Node node) { return(node.Id); }); Assert.AreElementsEqual(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ids); }
private static ITestDriver CreateTestDriver( IList <ComponentHandle <ITestFramework, TestFrameworkTraits> > testFrameworkHandles, TestFrameworkOptions testFrameworkOptions, ILogger logger) { string[] testFrameworkIds = GenericCollectionUtils.ConvertAllToArray(testFrameworkHandles, x => x.Id); StringBuilder testFrameworkName = new StringBuilder(); foreach (var testFrameworkHandle in testFrameworkHandles) { if (testFrameworkName.Length != 0) { testFrameworkName.Append(" and "); } testFrameworkName.Append(testFrameworkHandle.GetTraits().Name); } return(new PatternTestDriver(testFrameworkIds, testFrameworkName.ToString())); }
private void Abort(TestOutcome outcome, string message, bool throwIfDisposed) { EventHandler cachedHandler; ThreadAbortScope[] cachedScopes; lock (syncRoot) { if (throwIfDisposed) { ThrowIfDisposed(); } if (abortOutcome.HasValue) { return; } abortOutcome = outcome; abortMessage = message; cachedScopes = scopesAndThreads != null ? GenericCollectionUtils.ConvertAllToArray(scopesAndThreads, pair => pair.First) : null; scopesAndThreads = null; cachedHandler = aborted; aborted = null; } if (cachedScopes != null) { foreach (ThreadAbortScope scope in cachedScopes) { scope.Abort(); } } EventHandlerPolicy.SafeInvoke(cachedHandler, this, EventArgs.Empty); }
protected ITypeInfo GetType(Type type) { IAssemblyInfo assembly = GetAssembly(type.Assembly); ITypeInfo wrapper; if (type.IsGenericType && !type.IsGenericTypeDefinition) { wrapper = assembly.GetType(type.GetGenericTypeDefinition().FullName); if (wrapper != null) { ITypeInfo[] genericArguments = GenericCollectionUtils.ConvertAllToArray <Type, ITypeInfo>(type.GetGenericArguments(), Reflector.Wrap); wrapper = wrapper.MakeGenericType(genericArguments); } } else { wrapper = assembly.GetType(type.FullName); } Assert.IsNotNull(wrapper, "Could not find type '{0}'.", type); return(wrapper); }
public static ParameterInfo[] ResolveParameters(IList <IParameterInfo> parameters) { return(GenericCollectionUtils.ConvertAllToArray <IParameterInfo, ParameterInfo>(parameters, delegate(IParameterInfo parameter) { return parameter.Resolve(false); })); }
public override Type[] GetGenericArguments() { return(GenericCollectionUtils.ConvertAllToArray <ITypeInfo, Type>(adapter.GenericArguments, delegate(ITypeInfo parameter) { return parameter.Resolve(false); })); }
/// <summary> /// Obtains a reflection wrapper for a list of types. /// </summary> /// <param name="targets">The types, or null if none.</param> /// <returns>The reflection wrappers, or null original list was null.</returns> public static IList <ITypeInfo> Wrap(IList <Type> targets) { return(targets != null?GenericCollectionUtils.ConvertAllToArray <Type, ITypeInfo>(targets, Wrap) : null); }
private object[] ResolveRequiredDependencies(ConstructorInfo constructor) { object[] values = GenericCollectionUtils.ConvertAllToArray(constructor.GetParameters(), parameter => ResolveDependency(parameter.Name, parameter.ParameterType, false).Value); return(values); }
public void Run() { var test = (PatternTest)testCommand.Test; TestContextCookie?parentContextCookie = null; try { if (parentContext != null) { parentContextCookie = parentContext.Enter(); } // The first time we call Run, we check whether the ApartmentState of the // Thread is correct. If it is not, then we start a new thread and reenter // with a flag set to skip initial processing. if (!reentered) { if (executor.progressMonitor.IsCanceled) { result = new TestResult(TestOutcome.Canceled); return; } if (!testCommand.AreDependenciesSatisfied()) { ITestContext context = testCommand.StartPrimaryChildStep(parentTestStep); context.LogWriter.Warnings.WriteLine("Skipped due to an unsatisfied test dependency."); result = context.FinishStep(TestOutcome.Skipped, null); return; } executor.progressMonitor.SetStatus(test.Name); if (test.ApartmentState != ApartmentState.Unknown && Thread.CurrentThread.GetApartmentState() != test.ApartmentState) { reentered = true; ThreadTask task = new TestEnvironmentAwareThreadTask("Test Runner " + test.ApartmentState, (GallioAction)Run, executor.environmentManager); task.ApartmentState = test.ApartmentState; task.Run(null); if (!task.Result.HasValue) { throw new ModelException( String.Format("Failed to perform action in thread with overridden apartment state {0}.", test.ApartmentState), task.Result.Exception); } return; } } // Actually run the test. // Yes, this is a monstrously long method due to the inlining optimzation to minimize stack depth. using (Sandbox sandbox = parentSandbox.CreateChild()) { using (new ProcessIsolation()) { using (sandbox.StartTimer(test.TimeoutFunc())) { TestOutcome outcome; PatternTestActions testActions = test.TestActions; if (testActionsDecorator != null) { outcome = testActionsDecorator(sandbox, ref testActions); } else { outcome = TestOutcome.Passed; } if (outcome.Status == TestStatus.Passed) { PatternTestStep primaryTestStep = new PatternTestStep(test, parentTestStep); PatternTestState testState = new PatternTestState(primaryTestStep, testActions, executor.converter, executor.formatter, testCommand.IsExplicit); bool invisibleTest = true; outcome = outcome.CombineWith(sandbox.Run(TestLog.Writer, new BeforeTestAction(testState).Run, "Before Test")); if (outcome.Status == TestStatus.Passed) { bool reusePrimaryTestStep = !testState.BindingContext.HasBindings; if (!reusePrimaryTestStep) { primaryTestStep.IsTestCase = false; } invisibleTest = false; TestContext primaryContext = TestContext.PrepareContext( testCommand.StartStep(primaryTestStep), sandbox); testState.SetInContext(primaryContext); using (primaryContext.Enter()) { primaryContext.LifecyclePhase = LifecyclePhases.Initialize; outcome = outcome.CombineWith(primaryContext.Sandbox.Run(TestLog.Writer, new InitializeTestAction(testState).Run, "Initialize")); } if (outcome.Status == TestStatus.Passed) { var actions = new List <RunTestDataItemAction>(); try { foreach (IDataItem bindingItem in testState.BindingContext.GetItems(!executor.options.SkipDynamicTests)) { actions.Add(new RunTestDataItemAction(executor, testCommand, testState, primaryContext, reusePrimaryTestStep, bindingItem)); } if (actions.Count == 0) { TestLog.Warnings.WriteLine("Test skipped because it is parameterized but no data was provided."); outcome = TestOutcome.Skipped; } else { if (actions.Count == 1 || !test.IsParallelizable) { foreach (var action in actions) { action.Run(); } } else { executor.scheduler.Run(GenericCollectionUtils.ConvertAllToArray <RunTestDataItemAction, GallioAction>( actions, action => action.Run)); } TestOutcome combinedOutcome = TestOutcome.Passed; foreach (var action in actions) { combinedOutcome = combinedOutcome.CombineWith(action.Outcome); } outcome = outcome.CombineWith(reusePrimaryTestStep ? combinedOutcome : combinedOutcome.Generalize()); } } catch (TestException ex) { if (ex.Outcome.Status == TestStatus.Failed) { TestLog.Failures.WriteException(ex, String.Format("An exception occurred while getting data items for test '{0}'.", testState.Test.FullName)); } else { TestLog.Warnings.WriteException(ex); } outcome = ex.Outcome; } catch (Exception ex) { TestLog.Failures.WriteException(ex, String.Format("An exception occurred while getting data items for test '{0}'.", testState.Test.FullName)); outcome = TestOutcome.Error; } } primaryContext.SetInterimOutcome(outcome); using (primaryContext.Enter()) { primaryContext.LifecyclePhase = LifecyclePhases.Dispose; outcome = outcome.CombineWith(primaryContext.Sandbox.Run(TestLog.Writer, new DisposeTestAction(testState).Run, "Dispose")); } result = primaryContext.FinishStep(outcome); } outcome = outcome.CombineWith(sandbox.Run(TestLog.Writer, new AfterTestAction(testState).Run, "After Test")); if (invisibleTest) { result = PublishOutcomeFromInvisibleTest(testCommand, primaryTestStep, outcome); } } } } } } catch (Exception ex) { result = ReportTestError(testCommand, parentTestStep, ex, String.Format("An exception occurred while preparing to run test '{0}'.", test.FullName)); } finally { if (parentContextCookie.HasValue) { parentContextCookie.Value.ExitContext(); } executor.progressMonitor.SetStatus(""); executor.progressMonitor.Worked(1); } }
public TestOutcome Run() { TestContext context = TestContext.CurrentContext; using (skipProtect ? null : context.Sandbox.Protect()) { try { if (executor.progressMonitor.IsCanceled) { return(TestOutcome.Canceled); } var outcome = TestOutcome.Passed; if (!executor.options.SkipTestExecution) { context.LifecyclePhase = LifecyclePhases.Initialize; UpdateInterimOutcome(context, ref outcome, context.Sandbox.Run(TestLog.Writer, new InitializeTestInstanceAction(testInstanceState).Run, "Initialize")); } if (outcome.Status == TestStatus.Passed) { if (!executor.options.SkipTestExecution) { context.LifecyclePhase = LifecyclePhases.SetUp; UpdateInterimOutcome(context, ref outcome, context.Sandbox.Run(TestLog.Writer, new SetUpTestInstanceAction(testInstanceState).Run, "Set Up")); } if (outcome.Status == TestStatus.Passed) { if (!executor.options.SkipTestExecution) { context.LifecyclePhase = LifecyclePhases.Execute; UpdateInterimOutcome(context, ref outcome, context.Sandbox.Run(TestLog.Writer, new ExecuteTestInstanceAction(testInstanceState).Run, "Execute")); } if (outcome.Status == TestStatus.Passed) { // Run all test children. PatternTestActionsDecorator testActionsDecorator = delegate(Sandbox childSandbox, ref PatternTestActions childTestActions) { childTestActions = childTestActions.Copy(); return(childSandbox.Run(TestLog.Writer, new DecorateChildTestAction(testInstanceState, childTestActions).Run, "Decorate Child Test")); }; foreach (TestBatch batch in GenerateTestBatches(testCommand.Children)) { if (batch.Commands.Count == 1) { // Special case to reduce effective stack depth and cost since there is no // need to use the scheduler if nothing is running in parallel. RunTestAction action = new RunTestAction(executor, batch.Commands[0], context, testActionsDecorator); action.Run(); UpdateInterimOutcome(context, ref outcome, action.Result.Outcome.Generalize()); } else { RunTestAction[] actions = GenericCollectionUtils.ConvertAllToArray(batch.Commands, childTestCommand => new RunTestAction(executor, childTestCommand, context, testActionsDecorator)); executor.scheduler.Run(Array.ConvertAll <RunTestAction, GallioAction>(actions, action => action.Run)); TestOutcome combinedChildOutcome = TestOutcome.Passed; foreach (var action in actions) { combinedChildOutcome = combinedChildOutcome.CombineWith(action.Result.Outcome); } UpdateInterimOutcome(context, ref outcome, combinedChildOutcome.Generalize()); } } } } if (!executor.options.SkipTestExecution) { context.LifecyclePhase = LifecyclePhases.TearDown; UpdateInterimOutcome(context, ref outcome, context.Sandbox.Run(TestLog.Writer, new TearDownTestInstanceAction(testInstanceState).Run, "Tear Down")); } } if (!executor.options.SkipTestExecution) { context.LifecyclePhase = LifecyclePhases.Dispose; UpdateInterimOutcome(context, ref outcome, context.Sandbox.Run(TestLog.Writer, new DisposeTestInstanceAction(testInstanceState).Run, "Dispose")); } return(outcome); } catch (Exception ex) { TestLog.Failures.WriteException(ex, String.Format("An exception occurred while running test instance '{0}'.", testInstanceState.TestStep.Name)); return(TestOutcome.Error); } } }
public void AttributeWrapper(Type type, int index) { SampleAttribute target = (SampleAttribute)type.GetCustomAttributes(typeof(SampleAttribute), true)[index]; IAttributeInfo info = GenericCollectionUtils.ToArray(GetType(type).GetAttributeInfos(Reflector.Wrap(typeof(SampleAttribute)), true))[index]; WrapperAssert.AreEquivalent(target, info, false); SampleAttribute resolvedAttrib = (SampleAttribute)info.Resolve(true); Assert.AreEqual(target.param, resolvedAttrib.param); Assert.AreEqual(target.Field, resolvedAttrib.Field); Assert.AreEqual(target.Property, resolvedAttrib.Property); try { WrapperAssert.AreEquivalent(typeof(SampleAttribute).GetConstructors()[0], info.Constructor, false); } catch (NotSupportedException) { // This is also acceptable behavior. } Dictionary <IFieldInfo, object> fieldValues = new Dictionary <IFieldInfo, object>(); foreach (KeyValuePair <IFieldInfo, ConstantValue> entry in info.InitializedFieldValues) { fieldValues.Add(entry.Key, entry.Value.Resolve(true)); } Dictionary <IPropertyInfo, object> propertyValues = new Dictionary <IPropertyInfo, object>(); foreach (KeyValuePair <IPropertyInfo, ConstantValue> entry in info.InitializedPropertyValues) { propertyValues.Add(entry.Key, entry.Value.Resolve(true)); } if (target.param == typeof(int)) { try { object[] values = GenericCollectionUtils.ConvertAllToArray <ConstantValue, object>(info.InitializedArgumentValues, delegate(ConstantValue constantValue) { return(constantValue.Resolve(true)); }); Assert.AreElementsEqual(new object[] { typeof(int) }, values); } catch (NotSupportedException) { // This is also acceptable behavior. } if (fieldValues.Count != 0) { Assert.AreEqual(1, fieldValues.Count, "The implementation may return values for uninitialized fields, but there is only one such field."); Assert.AreEqual(0, fieldValues[GetField(typeof(SampleAttribute).GetField("Field"))]); } if (propertyValues.Count != 0) { Assert.AreEqual(1, propertyValues.Count, "The implementation may return values uninitialized properties, but there is only one such field."); Assert.AreEqual(null, propertyValues[GetProperty(typeof(SampleAttribute).GetProperty("Property"))]); } } else { try { object[] values = GenericCollectionUtils.ConvertAllToArray <ConstantValue, object>(info.InitializedArgumentValues, delegate(ConstantValue constantValue) { return(constantValue.Resolve(true)); }); Assert.AreElementsEqual(new object[] { typeof(string[]) }, values); } catch (NotSupportedException) { // This is also acceptable behavior. } Assert.AreElementsEqual(new KeyValuePair <IFieldInfo, object>[] { new KeyValuePair <IFieldInfo, object>(GetField(typeof(SampleAttribute).GetField("Field")), 2) }, fieldValues); Assert.AreElementsEqual(new KeyValuePair <IPropertyInfo, object>[] { new KeyValuePair <IPropertyInfo, object>(GetProperty(typeof(SampleAttribute).GetProperty("Property")), "foo") }, propertyValues); } }
public IMethodInfo MakeGenericMethod(IList <ITypeInfo> genericArguments) { Type[] resolvedGenericArguments = GenericCollectionUtils.ConvertAllToArray <ITypeInfo, Type>(genericArguments, delegate(ITypeInfo genericArgument) { return(genericArgument.Resolve(true)); }); return(Reflector.Wrap(Target.MakeGenericMethod(resolvedGenericArguments))); }
private void DisplayPaths <T>(ICollection <T> paths, string name) where T : FileSystemInfo { DisplayPaths(GenericCollectionUtils.ConvertAllToArray(paths, path => path.ToString()), name); }
/// <summary> /// Creates a state object with the specified annotations. /// </summary> /// <param name="annotations">The annotations.</param> public static ProjectFileState CreateFromAnnotations(IList <AnnotationData> annotations) { return(new ProjectFileState( GenericCollectionUtils.ConvertAllToArray <AnnotationData, AnnotationState>( annotations, AnnotationState.CreateFromAnnotation))); }
private FacadeTaskResult RunTests() { var logger = new FacadeLoggerWrapper(facadeLogger); var runner = TestRunnerUtils.CreateTestRunnerByName(StandardTestRunnerFactoryNames.IsolatedAppDomain); // Set parameters. var testPackage = new TestPackage(); foreach (var assemblyLocation in assemblyLocations) { testPackage.AddFile(new FileInfo(assemblyLocation)); } testPackage.ShadowCopy = facadeTaskExecutorConfiguration.ShadowCopy; if (facadeTaskExecutorConfiguration.AssemblyFolder != null) { testPackage.ApplicationBaseDirectory = new DirectoryInfo(facadeTaskExecutorConfiguration.AssemblyFolder); testPackage.WorkingDirectory = new DirectoryInfo(facadeTaskExecutorConfiguration.AssemblyFolder); } var testRunnerOptions = new TestRunnerOptions(); var testExplorationOptions = new TestExplorationOptions(); var filters = GenericCollectionUtils.ConvertAllToArray <string, Filter <string> >(explicitTestIds, testId => new EqualityFilter <string>(testId)); var filterSet = new FilterSet <ITestDescriptor>(new IdFilter <ITestDescriptor>(new OrFilter <string>(filters))); var testExecutionOptions = new TestExecutionOptions { FilterSet = filterSet }; // Install the listeners. runner.Events.TestStepStarted += TestStepStarted; runner.Events.TestStepFinished += TestStepFinished; runner.Events.TestStepLifecyclePhaseChanged += TestStepLifecyclePhaseChanged; // Run the tests. try { try { runner.Initialize(testRunnerOptions, logger, CreateProgressMonitor()); Report report = runner.Run(testPackage, testExplorationOptions, testExecutionOptions, CreateProgressMonitor()); if (sessionId != null) { SessionCache.SaveSerializedReport(sessionId, report); } return(FacadeTaskResult.Success); } catch (Exception ex) { if (sessionId != null) { SessionCache.ClearSerializedReport(sessionId); } logger.Log(LogSeverity.Error, "A fatal exception occurred during test execution.", ex); return(FacadeTaskResult.Exception); } finally { SubmitFailureForRemainingPendingTasks(); } } finally { runner.Dispose(CreateProgressMonitor()); } }