Exemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="pageIndex">The index of the current page.</param>
 /// <param name="pageCount">The number of pages.</param>
 /// <param name="visiblePages">The number of visible pages shown near the current page.</param>
 /// <param name="linkMaker">A function that creates a link reference to a particular page.</param>
 public PagerRenderer(int pageIndex, int pageCount, int visiblePages, GallioFunc <int, string> linkMaker)
 {
     this.pageIndex    = pageIndex;
     this.pageCount    = pageCount;
     this.visiblePages = visiblePages;
     this.linkMaker    = linkMaker;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Counts the number of elements in a collection, an array, or any other enumerable type, by
        /// using the most appropriate strategies.
        /// </summary>
        /// <returns>An enumeration of counting strategies applicable to the specified enumerable values.</returns>
        public IEnumerable <ICountingStrategy> Count()
        {
            var methods = new GallioFunc <IEnumerable <ICountingStrategy> >[]
            {
                ForArray,
                ForGenericCollection,
                ForNonGenericCollection,
                ForSimpleEnumerable,
            };

            foreach (var method in methods)
            {
                bool found = false;

                foreach (var strategy in method())
                {
                    found = true;
                    yield return(strategy);
                }

                if (found)
                {
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private TMemberInfo GetMemberInfo <TMemberInfo>(GallioFunc <Type, TMemberInfo> finder) where TMemberInfo : MemberInfo
        {
            var fixtureTypeProviders = new GallioFunc <Type>[]
            {
                () => GetCurrentTestInstanceState().FixtureType,
                () => ReflectionUtils.GetType(scope.CodeElement).Resolve(true) // Another way to find the test fixture type (http://code.google.com/p/mb-unit/issues/detail?id=559)
            };

            foreach (var provider in fixtureTypeProviders)
            {
                var fixtureType = provider();

                if (fixtureType != null)
                {
                    TMemberInfo info = finder(fixtureType);

                    if (info != null)
                    {
                        return(info);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 4
0
        private void AddMenuItem(string menuId, GallioFunc <MenuCommand> commandFactory)
        {
            var menuList    = GetMenu(menuId);
            var menuCommand = commandFactory();

            menuList.Add(menuCommand);
        }
Exemplo n.º 5
0
 private ParsingInfo(Options options, char initiator, char terminator, GallioFunc <string, Quantifier, IElement> parseToken)
 {
     this.options    = options;
     this.initiator  = initiator;
     this.terminator = terminator;
     this.parseToken = parseToken;
 }
Exemplo n.º 6
0
 private void QueueMenuItem(string menuId, GallioFunc <MenuCommand> commandFactory)
 {
     if (commandFactories.ContainsKey(menuId) == false)
     {
         commandFactories.Add(menuId, new List <GallioFunc <MenuCommand> >());
     }
     commandFactories[menuId].Add(commandFactory);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Adds a tab.
        /// </summary>
        /// <param name="name">The tab name.</param>
        /// <param name="tabFactory">The tab factory.</param>
        public void AddTab(string name, GallioFunc <ControlPanelTab> tabFactory)
        {
            TabPage tabPage = new TabPage(name);

            tabPage.Tag = tabFactory;

            controlPanelTabControl.TabPages.Add(tabPage);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a function chain.
        /// </summary>
        /// <param name="func">The initial function.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="func"/> is null.</exception>
        public FuncChain(GallioFunc <T, TResult> func)
        {
            if (func == null)
            {
                throw new ArgumentNullException("func");
            }

            this.func = func;
        }
Exemplo n.º 9
0
            public void Until(GallioFunc <bool> condition)
            {
                if (condition == null)
                {
                    throw new ArgumentNullException("condition");
                }

                Run(condition);
            }
Exemplo n.º 10
0
            private void Run(GallioFunc <bool> condition)
            {
                var runner = new RetryRunner(
                    repeat ?? Retry.DefaultRepeat,
                    polling ?? Retry.DefaultPolling,
                    timeout ?? Retry.DefaultTimeout,
                    action, condition, messageFormat, messageArgs, clock);

                runner.Run();
            }
Exemplo n.º 11
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="func">A function which computes the value on first request.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="func"/> is null.</exception>
        public Lazy(GallioFunc <T> func)
        {
            if (func == null)
            {
                throw new ArgumentNullException("func");
            }

            this.func = func;
            hasValue  = false;
        }
Exemplo n.º 12
0
        /// <inheritdoc cref="IHostService.Do" />
        public TResult Do <TArg, TResult>(GallioFunc <TArg, TResult> func, TArg arg)
        {
            if (func == null)
            {
                throw new ArgumentNullException("func");
            }

            ThrowIfDisposed();
            return(DoImpl(func, arg));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a CSV data set.
        /// </summary>
        /// <param name="documentReaderProvider">A delegate that provides the text reader for reading the CSV document on demand.</param>
        /// <param name="isDynamic">True if the data set should be considered dynamic.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="documentReaderProvider"/> is null.</exception>
        public CsvDataSet(GallioFunc <TextReader> documentReaderProvider, bool isDynamic)
        {
            if (documentReaderProvider == null)
            {
                throw new ArgumentNullException("documentReaderProvider");
            }

            this.documentReaderProvider = documentReaderProvider;
            this.isDynamic = isDynamic;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a task that will execute code within a new locally running thread.
        /// When the task terminates successfully, its result will contain the value
        /// returned by <paramref name="func"/>.
        /// </summary>
        /// <param name="name">The name of the task.</param>
        /// <param name="func">The function to perform within the thread.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/>
        /// or <paramref name="func"/> is null.</exception>
        public ThreadTask(string name, GallioFunc <object> func)
            : base(name)
        {
            if (func == null)
            {
                throw new ArgumentNullException("func");
            }

            invoker = new Invoker(func);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Creates a cache with the specified populator function.
        /// </summary>
        /// <param name="populator">A function that provides a value given a key.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="populator"/> is null.</exception>
        public LazyCache(GallioFunc <TKey, TValue> populator)
        {
            if (populator == null)
            {
                throw new ArgumentNullException("populator");
            }

            this.populator = populator;

            contents = new Dictionary <TKey, TValue>();
        }
 public State(ITestEnvironment[] environments, GallioFunc <ITestEnvironment, IDisposable> setUp)
 {
     foreach (ITestEnvironment environment in environments)
     {
         IDisposable innerState = setUp(environment);
         if (innerState != null)
         {
             innerStates.Add(innerState);
         }
     }
 }
Exemplo n.º 17
0
 public void Add(string menuId, GallioFunc <MenuCommand> commandFactory)
 {
     if (items == null)
     {
         QueueMenuItem(menuId, commandFactory);
     }
     else
     {
         AddMenuItem(menuId, commandFactory);
     }
 }
Exemplo n.º 18
0
 private static Stream Swallow(GallioFunc <Stream> func)
 {
     try
     {
         return(func());
     }
     catch (FileNotFoundException)
     {
         return(null);
     }
 }
Exemplo n.º 19
0
 private static KeyValuePair <Exception, T> InvokeAndCaptureException <T>(GallioFunc <T> func)
 {
     try
     {
         T result = func();
         return(new KeyValuePair <Exception, T>(null, result));
     }
     catch (Exception ex)
     {
         return(new KeyValuePair <Exception, T>(ex, default(T)));
     }
 }
Exemplo n.º 20
0
        private void ApplyPathConversion(string basePath, GallioFunc <string, string, string> converter)
        {
            if (basePath == null)
            {
                throw new ArgumentNullException("basePath");
            }

            if (reportDirectory != null)
            {
                reportDirectory = converter(reportDirectory, basePath);
            }
        }
Exemplo n.º 21
0
 public RetryRunner(int repeat, TimeSpan polling, TimeSpan timeout, GallioAction action,
                    GallioFunc <bool> condition, string messageFormat, object[] messageArgs, IClock clock)
 {
     this.repeat        = repeat;
     this.polling       = polling;
     this.timeout       = timeout;
     this.condition     = condition;
     this.action        = action;
     this.messageFormat = messageFormat;
     this.messageArgs   = messageArgs;
     this.clock         = clock;
 }
Exemplo n.º 22
0
            protected override TResult DoImpl <TArg, TResult>(GallioFunc <TArg, TResult> func, TArg arg)
            {
                ThrowIfNotConnected();

                try
                {
                    return(hostService.Do(func, arg));
                }
                catch (Exception ex)
                {
                    throw new HostException(Resources.RemoteHost_RemoteException, ex);
                }
            }
Exemplo n.º 23
0
        private static T RunImpl <T, TClosed, TOpen>(string input, TOpen root, GallioFunc <TOpen, string, TOpen> extendElement, GallioFunc <TOpen, string, TClosed> extendAttribute)
            where T : IXmlPath
            where TClosed : T
            where TOpen : TClosed
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (!input.StartsWith(XmlPathRoot.ElementSeparator))
            {
                throw new ArgumentException("Missing root separator.", "input");
            }

            TOpen result = root;

            if (input.Length > 1)
            {
                string[] tokens = input.Substring(1).Split(new[] { XmlPathRoot.ElementSeparator }, StringSplitOptions.None);

                for (int i = 0; i < tokens.Length; i++)
                {
                    if (tokens[i].Length == 0)
                    {
                        throw new ArgumentException("Invalid path.", "input");
                    }

                    string[] subTokens = tokens[i].Split(new[] { XmlPathRoot.AttributeSeparator }, StringSplitOptions.None);

                    if ((subTokens.Length != 1) && (subTokens.Length != 2))
                    {
                        throw new ArgumentException("Invalid path.", "input");
                    }

                    result = extendElement(result, subTokens[0]);

                    if (subTokens.Length == 2)
                    {
                        if (i != tokens.Length - 1)
                        {
                            throw new ArgumentException("Invalid path.", "input");
                        }

                        return(extendAttribute(result, subTokens[1]));
                    }
                }
            }

            return(result);
        }
        private static TestFrameworkSelection GetOrCreateSelectionIfAbsent(
            Dictionary <object, TestFrameworkSelection> selections,
            object key, GallioFunc <TestFrameworkSelection> factory)
        {
            TestFrameworkSelection selection;

            if (!selections.TryGetValue(key, out selection))
            {
                selection = factory();
                selections.Add(key, selection);
            }

            return(selection);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Registers a function decorator to perform around all other actions
        /// currently in the chain.  The contained part of the chain
        /// is passed in as a function to the decorator that the decorator
        /// can choose to run (or not) as needed.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The value of <see cref="Func" /> will be set to a new instance
        /// that performs the specified <paramref name="decorator"/> around
        /// the current <see cref="Func" />.
        /// </para>
        /// </remarks>
        /// <param name="decorator">The decorator to register.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="decorator"/> is null.</exception>
        public void Around(FuncDecorator <T, TResult> decorator)
        {
            if (decorator == null)
            {
                throw new ArgumentNullException("decorator");
            }

            GallioFunc <T, TResult> innerFunc = func;

            func = delegate(T obj)
            {
                return(decorator(obj, innerFunc));
            };
        }
Exemplo n.º 26
0
        /// <summary>
        /// Creates an XML data set.
        /// </summary>
        /// <param name="documentProvider">A delegate that produces the XML document on demand.</param>
        /// <param name="itemPath">The XPath expression used to select items within the document.</param>
        /// <param name="isDynamic">True if the data set should be considered dynamic.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="documentProvider"/> or <paramref name="itemPath"/> is null.</exception>
        public XmlDataSet(GallioFunc <IXPathNavigable> documentProvider, string itemPath, bool isDynamic)
        {
            if (documentProvider == null)
            {
                throw new ArgumentNullException("documentProvider");
            }
            if (itemPath == null)
            {
                throw new ArgumentNullException("itemPath");
            }

            this.documentProvider = documentProvider;
            this.itemPath         = itemPath;
            this.isDynamic        = isDynamic;
        }
Exemplo n.º 27
0
        public void DoActionAtInvalidIndex(GallioFunc <TList, int> getInvalidIndex, Action <TList, int> action, string actionName)
        {
            int invalidIndex = getInvalidIndex(List);

            AssertionHelper.Explain(() =>
                                    Assert.Throws <ArgumentOutOfRangeException>(() => action(List, invalidIndex)),
                                    innerFailures => new AssertionFailureBuilder(
                                        "Expected a method of the list to throw an particular exception when called with a invalid argument.")
                                    .AddLabeledValue("Method", actionName)
                                    .AddLabeledValue("Invalid Argument Name", "index")
                                    .AddRawLabeledValue("Invalid Argument Value", invalidIndex)
                                    .AddRawLabeledValue("Expected Exception", typeof(ArgumentOutOfRangeException))
                                    .SetStackTrace(Context.GetStackTraceData())
                                    .AddInnerFailures(innerFailures)
                                    .ToAssertionFailure());
        }
Exemplo n.º 28
0
 /// <summary>
 /// Try-function which executes the specified action and catch any file-related exception.
 /// </summary>
 /// <typeparam name="T">The type of the result returned by the function.</typeparam>
 /// <param name="getErrorMessage">The error message to log.</param>
 /// <param name="func"></param>
 /// <returns></returns>
 protected T CaptureFileException <T>(GallioFunc <string> getErrorMessage, GallioFunc <T> func)
 {
     try
     {
         return(func());
     }
     catch (FileNotFoundException exception)
     {
         context.Logger.Log(LogSeverity.Error, getErrorMessage(), exception);
         return(default(T));
     }
     catch (DirectoryNotFoundException exception)
     {
         context.Logger.Log(LogSeverity.Error, getErrorMessage(), exception);
         return(default(T));
     }
 }
Exemplo n.º 29
0
        /// <summary>
        /// Adds a preference pane.
        /// </summary>
        /// <param name="path">The preference pane path consisting of slash-delimited name segments
        /// specifying tree nodes.</param>
        /// <param name="icon">The preference pane icon, or null if none.</param>
        /// <param name="scope">The preference pane scope, or null if none.</param>
        /// <param name="paneFactory">The preference pane factory.</param>
        public void AddPane(string path, Icon icon, PreferencePaneScope scope, GallioFunc <PreferencePane> paneFactory)
        {
            string[] pathSegments = path.Split('/');
            if (pathSegments.Length == 0)
            {
                throw new ArgumentException("Preference pane path must not be empty.", "path");
            }

            TreeNode treeNode = null;

            foreach (string pathSegment in pathSegments)
            {
                TreeNodeCollection treeNodeCollection = treeNode != null
                    ? treeNode.Nodes
                    : preferencePaneTree.Nodes;

                TreeNode childTreeNode = FindTreeNodeByName(treeNodeCollection, pathSegment);
                if (childTreeNode == null)
                {
                    childTreeNode     = new TreeNode(pathSegment);
                    childTreeNode.Tag = new PaneInfo(CreatePlaceholderPreferencePane, pathSegment);
                    treeNodeCollection.Add(childTreeNode);
                }

                treeNode = childTreeNode;
            }

            string title = pathSegments[pathSegments.Length - 1];

            if (scope == PreferencePaneScope.Machine)
            {
                title += " (machine setting)";
            }

            treeNode.Tag = new PaneInfo(paneFactory, title);

            if (icon != null)
            {
                int imageIndex = preferencePaneIconImageList.Images.Count;
                preferencePaneIconImageList.Images.Add(icon);

                treeNode.ImageIndex         = imageIndex;
                treeNode.SelectedImageIndex = imageIndex;
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Synchronizes a function that returns a value.
        /// </summary>
        /// <param name="invoker">The invoker, such as a WinForms control.</param>
        /// <param name="func">The function.</param>
        /// <returns>The value returned by the function.</returns>
        /// <typeparam name="T">The function return type.</typeparam>
        /// <exception cref="Exception">The exception thrown by the function.</exception>
        public static T Invoke <T>(ISynchronizeInvoke invoker, GallioFunc <T> func)
        {
            if (invoker.InvokeRequired)
            {
                KeyValuePair <Exception, T> pair = (KeyValuePair <Exception, T>)invoker.Invoke(
                    new GallioFunc <GallioFunc <T>, KeyValuePair <Exception, T> >(InvokeAndCaptureException), new object[] { func });

                if (pair.Key != null)
                {
                    ExceptionUtils.RethrowWithNoStackTraceLoss(pair.Key);
                }
                return(pair.Value);
            }
            else
            {
                return(func());
            }
        }