Пример #1
0
        private static Attribute[] HasAttributesImpl(Type attributeType, int expectedCount, MemberInfo target, string messageFormat, params object[] messageArgs)
        {
            Attribute[] result = GenericCollectionUtils.ToArray(GetAttributes(attributeType, target));

            AssertionHelper.Verify(() =>
            {
                string message = null;

                if (result.Length == 0)
                {
                    message = "Expected the searched attribute to decorate the target object; but none was found.";
                }
                else if (expectedCount > 0 && result.Length != expectedCount)
                {
                    message = String.Format("Expected to find {0} attribute instance{1} but found {2}.",
                                            expectedCount, expectedCount > 1 ? "s" : String.Empty, result.Length);
                }

                if (message == null)
                {
                    return(null);
                }

                return(new AssertionFailureBuilder(message)
                       .AddRawLabeledValue("Target Object", target)
                       .AddRawLabeledValue("Attribute Type", attributeType)
                       .SetMessage(messageFormat, messageArgs)
                       .ToAssertionFailure());
            });

            return(result);
        }
Пример #2
0
        /// <inheritdoc />
        protected override IEnumerable <IDataItem> GetItemsImpl(ICollection <DataBinding> bindings, bool includeDynamicItems)
        {
            IDataProvider[] providers     = GenericCollectionUtils.ToArray(DataSets);
            int             providerCount = providers.Length;

            var bindingsPerProvider = new List <DataBinding> [providerCount];

            for (int i = 0; i < providerCount; i++)
            {
                bindingsPerProvider[i] = new List <DataBinding>();
            }

            foreach (DataBinding binding in bindings)
            {
                ResolvedBinding resolvedBinding = ResolveBinding(binding);
                if (resolvedBinding != null)
                {
                    bindingsPerProvider[resolvedBinding.DataSetInfo.DataSetIndex].Add(resolvedBinding.Inner);
                }
            }

            foreach (IList <IDataItem> itemList in strategy.Join(providers, bindingsPerProvider, includeDynamicItems))
            {
                yield return(new JoinedDataItem(this, itemList));
            }
        }
Пример #3
0
        private static bool ParseImpl(string value, out ReportArchive reportArchive, bool throwOnFailure)
        {
            if (String.IsNullOrEmpty(value))
            {
                reportArchive = Normal;
                return(true);
            }

            foreach (ReportArchive item in All)
            {
                if (item.Value.ToString().Equals(value, StringComparison.OrdinalIgnoreCase))
                {
                    reportArchive = item;
                    return(true);
                }
            }

            if (throwOnFailure)
            {
                string[] names = GenericCollectionUtils.ToArray(GenericCollectionUtils.Select(All, x => x.Value.ToString()));
                throw new ArgumentException(String.Format("Invalid report archive mode '{0}'. It must be one of the following values: {1}.",
                                                          value, String.Join(", ", names)));
            }

            reportArchive = Normal;
            return(false);
        }
        /// <summary>
        /// Constructs an assertion failure.
        /// </summary>
        /// <param name="native">The native unmanged object describing the failure.</param>
        /// <param name="stringResolver">A service to resolve unmanaged unicode strings.</param>
        public MbUnitCppAssertionFailure(NativeAssertionFailure native, IStringResolver stringResolver)
        {
            description        = stringResolver.GetString(native.DescriptionId);
            message            = stringResolver.GetString(native.MessageId);
            hasActualValue     = native.ActualValue.IsValid;
            hasExpectedValue   = native.ExpectedValue.IsValid;
            hasUnexpectedValue = native.UnexpectedValue.IsValid;
            line = native.Line;

            if (hasActualValue)
            {
                actualValue = NativeValueParser.Parse(stringResolver.GetString(native.ActualValue.ValueId), native.ActualValue.ValueType);
            }

            if (hasExpectedValue)
            {
                expectedValue = NativeValueParser.Parse(stringResolver.GetString(native.ExpectedValue.ValueId), native.ExpectedValue.ValueType);
            }

            if (hasUnexpectedValue)
            {
                unexpectedValue = NativeValueParser.Parse(stringResolver.GetString(native.UnexpectedValue.ValueId), native.UnexpectedValue.ValueType);
            }

            diffing = hasActualValue && (native.ActualValue.ValueType == NativeValueType.String) &&
                      ((hasExpectedValue && (native.ExpectedValue.ValueType == NativeValueType.String)) ||
                       (hasUnexpectedValue && (native.UnexpectedValue.ValueType == NativeValueType.String)));

            extraLabeledValues = GenericCollectionUtils.ToArray(GetExtraLabeledValues(native, stringResolver));
        }
        private void InitializeAvailableReportTypes()
        {
            IReportManager reportManager = RuntimeAccessor.ServiceLocator.Resolve <IReportManager>();

            types     = new List <ReportFormatterTraits>(GenericCollectionUtils.Select(reportManager.FormatterHandles, x => x.GetTraits()));
            typeNames = new List <string>(GenericCollectionUtils.Select(types, x => x.Name));
            comboBoxOutputReportType.Items.AddRange(GenericCollectionUtils.ToArray(types));
        }
Пример #6
0
        /// <summary>
        /// Creates a filter set consisting of a collection of rules.
        /// </summary>
        /// <param name="rules">The filter rules.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="rules"/> is null.</exception>
        public FilterSet(ICollection <FilterRule <T> > rules)
        {
            if (rules == null || rules.Contains(null))
            {
                throw new ArgumentNullException("rules");
            }

            this.rules = GenericCollectionUtils.ToArray(rules);
        }
Пример #7
0
        /// <summary>
        /// Creates an AND-filter.
        /// </summary>
        /// <param name="filters">The filters that must all jointly be matched.
        /// If the list is empty, the filter matches everything.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="filters"/> is null.</exception>
        public AndFilter(ICollection <Filter <T> > filters)
        {
            if (filters == null || filters.Contains(null))
            {
                throw new ArgumentNullException("filters");
            }

            this.filters = GenericCollectionUtils.ToArray(filters);
        }
Пример #8
0
        public IList <IPluginDescriptor> GetPlugins()
        {
            if (plugins == null)
            {
                plugins = new ReadOnlyCollection <IPluginDescriptor>(GenericCollectionUtils.ToArray(pluginsByPluginId.Values));
            }

            return(plugins);
        }
Пример #9
0
        public IList <IServiceDescriptor> GetServices()
        {
            if (services == null)
            {
                services = new ReadOnlyCollection <IServiceDescriptor>(GenericCollectionUtils.ToArray(servicesByServiceId.Values));
            }

            return(services);
        }
Пример #10
0
        public IList <IComponentDescriptor> GetComponents()
        {
            if (components == null)
            {
                components = new ReadOnlyCollection <IComponentDescriptor>(GenericCollectionUtils.ToArray(componentsByComponentId.Values));
            }

            return(components);
        }
Пример #11
0
        public KeyValuePair <string, string>[] GetMetadata(IStringResolver resolver)
        {
            if (metadata == null)
            {
                metadata = GenericCollectionUtils.ToArray(EnumerateMetadata(resolver));
            }

            return(metadata);
        }
Пример #12
0
 public PluginDescriptor(Registry registry, PluginRegistration pluginRegistration, IList <IPluginDescriptor> completePluginDependenciesCopy)
 {
     this.registry               = registry;
     pluginId                    = pluginRegistration.PluginId;
     pluginTypeName              = pluginRegistration.PluginTypeName;
     baseDirectory               = pluginRegistration.BaseDirectory;
     pluginProperties            = pluginRegistration.PluginProperties.Copy().AsReadOnly();
     traitsProperties            = pluginRegistration.TraitsProperties.Copy().AsReadOnly();
     pluginHandlerFactory        = pluginRegistration.PluginHandlerFactory;
     assemblyBindings            = new ReadOnlyCollection <AssemblyBinding>(GenericCollectionUtils.ToArray(pluginRegistration.AssemblyBindings));
     pluginDependencies          = new ReadOnlyCollection <IPluginDescriptor>(completePluginDependenciesCopy);
     probingPaths                = new ReadOnlyCollection <string>(GenericCollectionUtils.ToArray(pluginRegistration.ProbingPaths));
     enableCondition             = pluginRegistration.EnableCondition;
     recommendedInstallationPath = pluginRegistration.RecommendedInstallationPath;
     filePaths                   = new ReadOnlyCollection <string>(GenericCollectionUtils.ToArray(pluginRegistration.FilePaths));
 }
Пример #13
0
        private void ShowRegisteredComponents <T>(string heading, ICollection <T> handles, GallioFunc <T, string> getName, GallioFunc <T, string> getDescription)
        {
            Console.WriteLine(heading);
            Console.WriteLine();
            T[] sortedHandles = GenericCollectionUtils.ToArray(handles);
            Array.Sort(sortedHandles, (x, y) => getName(x).CompareTo(getName(y)));

            if (sortedHandles.Length == 0)
            {
                CommandLineOutput.PrintArgumentHelp("", "<none>", null, null, null, null);
            }
            else
            {
                foreach (T handle in sortedHandles)
                {
                    CommandLineOutput.PrintArgumentHelp("", getName(handle), null, getDescription(handle), null, null);
                    Console.WriteLine();
                }
            }
        }
Пример #14
0
 /// <inheritdoc />
 protected override IEnumerable <IDataItem> GetItemsImpl(ICollection <DataBinding> bindings, bool includeDynamicItems)
 {
     IDataProvider[] providers = GenericCollectionUtils.ToArray(DataSets);
     return(strategy.Merge(providers, bindings, includeDynamicItems));
 }
Пример #15
0
        private void SortChildren(ManagedTestCommand parent, MultiMap <ManagedTestCommand, ManagedTestCommand> siblingDependencies)
        {
            ManagedTestCommand[] children = parent.ChildrenToArray();
            if (children.Length == 0)
            {
                return;
            }

            // Clear the array of children since we are about to reshuffle them.
            parent.ClearChildren();

            // Sort the children by order.  Because the topological sort emits vertices precisely
            // in the ordert that it visits them (depth-first) it will preserve the relative ordering
            // of independent vertices.  So we influence test execution order by pre-sorting.
            // Dependencies will of course interfere with the ordering slightly.  However, if the
            // user explicitly specifies orderings in dependency order then they'll indeed run in
            // that specified order.  -- Jeff.
            SortCommandsByOrder(children);

            // Perform a topological sort of the children using depth-first search.
            // Because at this stage a command only has dependencies on its siblings the depth-first search
            // actually proceeds down the chain of sibling dependencies only; it does not
            // traverse the whole test hierarchy.  -- Jeff.
            Dictionary <ManagedTestCommand, bool> visitedSet = new Dictionary <ManagedTestCommand, bool>();
            Stack <DepthFirstEntry> stack = new Stack <DepthFirstEntry>();

            stack.Push(new DepthFirstEntry(null, children));
            for (;;)
            {
                DepthFirstEntry top = stack.Peek();
                if (top.DependencyEnumerator.MoveNext())
                {
                    ManagedTestCommand current = top.DependencyEnumerator.Current;

                    bool inProgressFlag;
                    if (visitedSet.TryGetValue(current, out inProgressFlag))
                    {
                        if (inProgressFlag)
                        {
                            throw new ModelException(String.Format("Found a test dependency cycle involving test '{0}'.",
                                                                   current.Test.FullName));
                        }
                    }
                    else
                    {
                        IList <ManagedTestCommand> unorderedDependencies = siblingDependencies[current];
                        if (unorderedDependencies.Count != 0)
                        {
                            visitedSet[current] = true;

                            // We need to sort all visited children so that dependencies run in relative order.
                            ManagedTestCommand[] dependencies = GenericCollectionUtils.ToArray(unorderedDependencies);
                            SortCommandsByOrder(dependencies);

                            stack.Push(new DepthFirstEntry(current, dependencies));
                        }
                        else
                        {
                            parent.AddChild(current);
                            visitedSet[current] = false;
                        }
                    }
                }
                else
                {
                    ManagedTestCommand current = top.Source;
                    if (current == null)
                    {
                        break;
                    }

                    parent.AddChild(current);
                    visitedSet[current] = false;
                    stack.Pop();
                }
            }

            // Recursively sort the children of this command.
            foreach (ManagedTestCommand child in children)
            {
                SortChildren(child, siblingDependencies);
            }
        }
Пример #16
0
 /// <summary>
 /// Reads the null-terminated ASCII string at the specified offset.
 /// </summary>
 /// <param name="offset">The offset from the beginning of the file.</param>
 /// <returns>The string read at the specified position.</returns>
 public string ReadAsciiString(long offset)
 {
     Seek(offset);
     byte[] bytes = GenericCollectionUtils.ToArray(ReadBytes());
     return(Encoding.ASCII.GetString(bytes));
 }
Пример #17
0
 private static void SetIronRubyLibraryPaths(LanguageSetup languageSetup, IList <string> libraryPaths)
 {
     languageSetup.Options["LibraryPaths"] = string.Join(";", GenericCollectionUtils.ToArray(libraryPaths));
 }
Пример #18
0
        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);
            }
        }
Пример #19
0
 public void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.AddValue(ContentsKey, GenericCollectionUtils.ToArray(this));
 }
 public static object[] GetCustomAttributes(ICodeElementInfo adapter, bool inherit)
 {
     return(GenericCollectionUtils.ToArray(adapter.GetAttributes(null, inherit)));
 }
Пример #21
0
 private static TAttribute[] ToAttributeArray <TAttribute>(Attribute[] attributes)
     where TAttribute : Attribute
 {
     return(GenericCollectionUtils.ToArray(GenericCollectionUtils.Select(attributes, x => (TAttribute)x)));
 }
 public static object[] GetCustomAttributes(ICodeElementInfo adapter, Type attributeType, bool inherit)
 {
     return(GenericCollectionUtils.ToArray(adapter.GetAttributes(Reflector.Wrap(attributeType), inherit)));
 }