Exemplo n.º 1
0
 private void PrepareToRegisterAttachment(string attachmentName)
 {
     if (attachmentNames != null && attachmentNames.Contains(attachmentName))
     {
         throw new InvalidOperationException(String.Format("There is already an attachment named '{0}'.", attachmentName));
     }
 }
Exemplo n.º 2
0
        private void Add(int hash)
        {
            if (one.Contains(hash))
            {
                one.Remove(hash);
                two.Add(hash);
            }
            else if (two.Contains(hash))
            {
                two.Remove(hash);
                more.Add(hash, 3);
            }
            else
            {
                int n;

                if (more.TryGetValue(hash, out n))
                {
                    more[hash] = 1 + n;
                }
                else
                {
                    one.Add(hash);
                }
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        protected override void Initialize()
        {
            var testCaseSteps = new GallioHashSet <string>();

            Events.AnnotationDiscovered += delegate(object sender, AnnotationDiscoveredEventArgs e)
            {
                LogAnnotation(e.Annotation);
            };

            Events.TestStepStarted += delegate(object sender, TestStepStartedEventArgs e)
            {
                if (e.TestStepRun.Step.IsTestCase)
                {
                    testCaseSteps.Add(e.TestStepRun.Step.Id);

                    LogTestCaseStarted(e);
                }
                else
                {
                    string parentId = e.TestStepRun.Step.ParentId;
                    if (parentId != null && testCaseSteps.Contains(parentId))
                    {
                        testCaseSteps.Add(e.TestStepRun.Step.Id);
                    }
                }
            };

            Events.TestStepFinished += delegate(object sender, TestStepFinishedEventArgs e)
            {
                if (e.TestStepRun.Step.IsTestCase)
                {
                    testCaseSteps.Remove(e.TestStepRun.Step.Id);

                    LogTestCaseFinished(e);
                }
                else
                {
                    if (!testCaseSteps.Contains(e.TestStepRun.Step.Id))
                    {
                        if (e.TestStepRun.Result.Outcome.Status != TestStatus.Passed &&
                            (e.TestStepRun.TestLog.GetStream(MarkupStreamNames.Warnings) != null ||
                             e.TestStepRun.TestLog.GetStream(MarkupStreamNames.Failures) != null))
                        {
                            LogNonTestCaseProblem(e);
                        }
                    }
                    else
                    {
                        testCaseSteps.Remove(e.TestStepRun.Step.Id);
                    }
                }
            };
        }
Exemplo n.º 4
0
        /// <summary>
        /// Obtains a unique local id for a child of this test.
        /// </summary>
        /// <param name="localIdHint">A suggested id which will be used if no conflicts occur.</param>
        /// <returns>The unique local id to use.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="localIdHint"/> is null.</exception>
        public string GetUniqueLocalIdForChild(string localIdHint)
        {
            if (localIdHint == null)
            {
                throw new ArgumentNullException("localIdHint");
            }

            string candidateLocalId = localIdHint;

            if (assignedChildLocalIds == null)
            {
                assignedChildLocalIds = new GallioHashSet <string>();
            }
            else
            {
                int index = 2;
                while (assignedChildLocalIds.Contains(candidateLocalId))
                {
                    candidateLocalId = localIdHint + index;
                    index           += 1;
                }
            }

            assignedChildLocalIds.Add(candidateLocalId);
            return(candidateLocalId);
        }
Exemplo n.º 5
0
        /// <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);
                }
            }
        }
        /// <inheritdoc />
        public override IList <IEventInfo> GetEvents(BindingFlags bindingFlags)
        {
            List <IEventInfo> result = new List <IEventInfo>();

            AddAll(result, EnumerateEvents(bindingFlags, this));

            BindingFlags inheritanceBindingFlags = GetInheritanceBindingFlags(bindingFlags);

            if (inheritanceBindingFlags != BindingFlags.Default)
            {
                GallioHashSet <StaticEventWrapper> overrides = new GallioHashSet <StaticEventWrapper>();
                foreach (StaticEventWrapper @event in result)
                {
                    AddAll(overrides, @event.GetOverridenOrHiddenEvents(false));
                }

                foreach (StaticDeclaredTypeWrapper baseType in GetAllBaseTypes())
                {
                    foreach (StaticEventWrapper inheritedEvent in baseType.EnumerateEvents(inheritanceBindingFlags, this))
                    {
                        if (!overrides.Contains(inheritedEvent))
                        {
                            result.Add(inheritedEvent);
                            AddAll(overrides, inheritedEvent.GetOverridenOrHiddenEvents(false));
                        }
                    }
                }
            }

            return(result);
        }
        private IList <IMethodInfo> GetMethods(BindingFlags bindingFlags, bool excludeOverridesOnly)
        {
            List <IMethodInfo> result = new List <IMethodInfo>();

            AddAll(result, EnumerateDeclaredMethods(bindingFlags, this));

            BindingFlags inheritanceBindingFlags = GetInheritanceBindingFlags(bindingFlags);

            if (inheritanceBindingFlags != BindingFlags.Default)
            {
                GallioHashSet <StaticMethodWrapper> overrides = new GallioHashSet <StaticMethodWrapper>();
                foreach (StaticMethodWrapper method in result)
                {
                    AddAll(overrides, method.GetOverridenOrHiddenMethods(excludeOverridesOnly));
                }

                foreach (StaticDeclaredTypeWrapper baseType in GetAllBaseTypes())
                {
                    foreach (StaticMethodWrapper inheritedMethod in baseType.EnumerateDeclaredMethods(inheritanceBindingFlags, this))
                    {
                        if (!overrides.Contains(inheritedMethod) && !IsSpecialNonInheritedMethod(inheritedMethod))
                        {
                            result.Add(inheritedMethod);
                            AddAll(overrides, inheritedMethod.GetOverridenOrHiddenMethods(excludeOverridesOnly));
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns true if the specified preprocessor constant is defined.
        /// </summary>
        /// <param name="constant">The constant.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="constant"/>
        /// is null.</exception>
        /// <returns>True if the constant is defined.</returns>
        public bool IsDefined(string constant)
        {
            if (constant == null)
            {
                throw new ArgumentNullException("constant");
            }

            return(constants.Contains(constant));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Prepares to populate the children of the assembly test on demand by
        /// adding a deferred populator with <see cref="IPatternScope.AddDeferredComponentPopulator" />.
        /// </summary>
        /// <param name="assemblyScope">The assembly scope.</param>
        /// <param name="assembly">The assembly.</param>
        protected virtual void PrepareToPopulateChildrenOnDemand(IPatternScope assemblyScope, IAssemblyInfo assembly)
        {
            var populatedTypes = new GallioHashSet <ITypeInfo>();

            assemblyScope.AddDeferredComponentPopulator(childCodeElementHint =>
            {
                ITypeInfo type = childCodeElementHint as ITypeInfo;
                if (type != null && !type.IsNested && !populatedTypes.Contains(type) && assembly.Equals(type.Assembly))
                {
                    populatedTypes.Add(type);
                    assemblyScope.Consume(type, false, DefaultTypePattern);
                }
            });
        }
Exemplo n.º 10
0
        public bool Contains(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (type.IsEnum || typeof(Delegate).IsAssignableFrom(type))
            {
                return(true);
            }

            if (type.IsGenericType)
            {
                type = type.GetGenericTypeDefinition();
            }

            return(types.Contains(type));
        }