public void Intercept(IInvocation invocation) { // ensure the thread-static variable is initialized for the current thread if (_invocationInfo == null) { _invocationInfo = new Stack <InvocationInfo>(); } try { var recorderContexts = AttributeUtils.GetAttributes <AuditRecorderAttribute>(invocation.MethodInvocationTarget, true) .Select(a => new RecorderContext(invocation, (IServiceOperationRecorder)Activator.CreateInstance(a.RecorderClass))) .ToList(); _invocationInfo.Push(new InvocationInfo(recorderContexts)); invocation.Proceed(); _invocationInfo.Peek().PostCommit(); } finally { // clear current invocation _invocationInfo.Pop(); } }
private void BuildTestsFromMethod(Test parent, IMethodInfo method, string namePrefix, string nameSuffix) { try { foreach (TestAttribute2 attrib in AttributeUtils.GetAttributes <TestAttribute2>(method, true)) { BuildTest(parent, method, namePrefix, nameSuffix, attrib); } foreach (RowTestAttribute2 attrib in AttributeUtils.GetAttributes <RowTestAttribute2>(method, true)) { BuildRowTest(parent, method, namePrefix, nameSuffix, attrib); } foreach (CombinatorialTestAttribute2 attrib in AttributeUtils.GetAttributes <CombinatorialTestAttribute2>(method, true)) { BuildCombinatorialTest(parent, method, namePrefix, nameSuffix, attrib); } } catch (Exception ex) { testModel.AddAnnotation(new Annotation(AnnotationType.Error, method, "An exception was thrown while exploring an MbUnit v2 test method.", ex)); } }
private void LoadExtensions() { lock (Extensions) { if (!_extensionLoaded) { try { Extensions.Clear(); var attrs = AttributeUtils.GetAttributes <ExtensibleAttribute>(this.GetType(), true); foreach (var attr in attrs) { var xp = Activator.CreateInstance(attr.ExtensionPoint); Extensions.AddRange((xp as ExtensionPoint).CreateExtensions()); } _extensionLoaded = true; } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Unable to load page extension"); } } } }
private static void PopulateMethodMetadata(ICodeElementInfo codeElement, PropertyBag metadata) { foreach (TestAttribute attr in AttributeUtils.GetAttributes <TestAttribute>(codeElement, true)) { // Add timeout if (attr.Timeout > 0) { TimeSpan timeout = TimeSpan.FromMilliseconds(attr.Timeout); metadata.Add("Timeout", timeout.Seconds.ToString("0.000")); } // Add categories string categories = attr.Categories; if (!String.IsNullOrEmpty(categories)) { foreach (string category in categories.Split(',')) { metadata.Add(MetadataKeys.Category, category); } } } // Add expected exception type foreach (ExpectedExceptionAttribute attr in AttributeUtils.GetAttributes <ExpectedExceptionAttribute>(codeElement, true)) { metadata.Add(MetadataKeys.ExpectedException, attr.ExceptionType.FullName); } PopulateCommonMetadata(codeElement, metadata); }
public ChildInfo GetPossibleChildFor(IList <TList> list) { var description = AttributeUtils.GetAttributes <DescriptionAttribute, TElement>().FirstOrDefault(); return(new ChildInfo( name: _name, description: description?.Description, create: () => new AddToCollection <TList>(list, new TElement()))); }
/// <summary> /// Internal method used by the framework to discover extension points and extensions declared in a plugin. /// </summary> /// <param name="asm"></param> /// <param name="points"></param> /// <param name="extensions"></param> internal static void DiscoverExtensionPointsAndExtensions(Assembly asm, List <ExtensionPointInfo> points, List <ExtensionInfo> extensions) { foreach (var type in asm.GetTypes()) { var epAttr = AttributeUtils.GetAttribute <ExtensionPointAttribute>(type, false); if (epAttr != null) { if (IsValidExtensionPointClass(type)) { points.Add(new ExtensionPointInfo(type, GetExtensionInterface(type), epAttr.Name, epAttr.Description)); } else { Platform.Log(LogLevel.Error, SR.ExceptionExtensionPointMustSubclassExtensionPoint, type.FullName); } } var attrs = AttributeUtils.GetAttributes <ExtensionOfAttribute>(type, false); foreach (var a in attrs) { // is the extension a concrete class? if (!IsConcreteClass(type)) { Platform.Log(LogLevel.Error, SR.ExceptionExtensionMustBeConcreteClass, type.FullName); continue; } var extensionPointClass = a.ExtensionPointClass; if (!IsValidExtensionPointClass(extensionPointClass)) { Platform.Log(LogLevel.Error, SR.ExceptionExtensionDoesNotExtendValidExtensionPointClass, type.FullName); continue; } // does the extension implement the required interface? var extensionInterface = GetExtensionInterface(extensionPointClass); if (!extensionInterface.IsAssignableFrom(type)) { Platform.Log(LogLevel.Error, SR.ExceptionExtensionDoesNotImplementRequiredInterface, type.FullName, extensionInterface); continue; } extensions.Add( new ExtensionInfo( type, extensionPointClass, a.Name, a.Description, ExtensionSettings.Default.IsEnabled(type, a.Enabled), a.FeatureToken ) ); } } }
private static bool IsApplicableAction(Type actionClass, ServerRuleTypeEnum ruleType) { var attrs = AttributeUtils.GetAttributes <ActionApplicabilityAttribute>(actionClass); // if no attributes, assume applicable to all rule types if (!attrs.Any()) { return(true); } return(attrs.Any(a => a.RuleType.ToServerRuleTypeEnum().Equals(ruleType))); }
/// <inheritdoc /> public IEnumerable <IPattern> GetPatterns(ICodeElementInfo codeElement) { if (codeElement == null) { throw new ArgumentNullException("codeElement"); } foreach (PatternAttribute attribute in AttributeUtils.GetAttributes <PatternAttribute>(codeElement, true)) { yield return(attribute); } }
public static void PopulateTestMetadata(Test test, IMemberInfo member) { foreach (TestPatternAttribute2 attrib in AttributeUtils.GetAttributes <TestPatternAttribute2>(member, true)) { if (!String.IsNullOrEmpty(attrib.Description)) { test.Metadata.Add(MetadataKeys.Description, attrib.Description); } } PopulateFixtureOrTestMetadata(test, member); }
public override IEnumerable <ChildInfo> GetPossibleChildrenFor(TContainer container) { var description = AttributeUtils.GetAttributes <DescriptionAttribute, TProperty>().FirstOrDefault(); return(new[] { new ChildInfo( name: _name, description: description?.Description, create: () => new SetValueCommand <TProperty>(_getPointer(container), new TProperty())) }); }
/// <summary> /// Finds the imex that supports the specified data-class. /// </summary> /// <param name="dataClass"></param> /// <returns></returns> /// <exception cref="NotSupportedException">Indicates that no imex was found that supports the specified data-class.</exception> public static IXmlDataImex FindImexForDataClass(string dataClass) { return((IXmlDataImex) new XmlDataImexExtensionPoint().CreateExtension( delegate(ExtensionInfo info) { return CollectionUtils.Contains(AttributeUtils.GetAttributes <ImexDataClassAttribute>(info.ExtensionClass), delegate(ImexDataClassAttribute a) { return a != null && a.DataClass.Equals( dataClass, StringComparison.InvariantCultureIgnoreCase); }); })); }
public static void PopulateFixtureMetadata(Test test, ITypeInfo fixtureType) { foreach (AuthorAttribute2 attrib in AttributeUtils.GetAttributes <AuthorAttribute2>(fixtureType, true)) { if (!String.IsNullOrEmpty(attrib.Name)) { test.Metadata.Add(MetadataKeys.AuthorName, attrib.Name); } if (!String.IsNullOrEmpty(attrib.EMail) && attrib.EMail != @"unspecified") { test.Metadata.Add(MetadataKeys.AuthorEmail, attrib.EMail); } if (!String.IsNullOrEmpty(attrib.HomePage) && attrib.HomePage != @"unspecified") { test.Metadata.Add(MetadataKeys.AuthorHomepage, attrib.HomePage); } } foreach (FixtureCategoryAttribute2 attrib in AttributeUtils.GetAttributes <FixtureCategoryAttribute2>(fixtureType, true)) { test.Metadata.Add(MetadataKeys.Category, attrib.Category); } try { foreach (TestsOnAttribute2 attrib in AttributeUtils.GetAttributes <TestsOnAttribute2>(fixtureType, true)) { test.Metadata.Add(MetadataKeys.TestsOn, attrib.TestedType.AssemblyQualifiedName); } } catch (ReflectionResolveException) { // Ignore failures to resolve the tested type. } foreach (ImportanceAttribute2 attrib in AttributeUtils.GetAttributes <ImportanceAttribute2>(fixtureType, true)) { test.Metadata.Add(MetadataKeys.Importance, attrib.Importance.ToString()); } foreach (TestFixturePatternAttribute2 attrib in AttributeUtils.GetAttributes <TestFixturePatternAttribute2>(fixtureType, true)) { if (!String.IsNullOrEmpty(attrib.Description)) { test.Metadata.Add(MetadataKeys.Description, attrib.Description); } } PopulateFixtureOrTestMetadata(test, fixtureType); }
private static void PopulateFixtureOrTestMetadata(Test test, ICodeElementInfo codeElement) { foreach (IgnoreAttribute2 attrib in AttributeUtils.GetAttributes <IgnoreAttribute2>(codeElement, true)) { test.Metadata.Add(MetadataKeys.IgnoreReason, attrib.Description ?? "<unknown>"); } string xmlDocumentation = codeElement.GetXmlDocumentation(); if (xmlDocumentation != null) { test.Metadata.Add(MetadataKeys.XmlDocumentation, xmlDocumentation); } }
private static XmlQualifiedName[] GetQualifiedNames <T>() { var namespaceAttributes = AttributeUtils.GetAttributes <XmlNamespaceAttribute, T>(); var qualifiedNames = namespaceAttributes.Select(attr => attr.QualifiedName); var rootAttribute = AttributeUtils.GetAttributes <XmlRootAttribute, T>().FirstOrDefault(); if (rootAttribute != null) { qualifiedNames = qualifiedNames.Concat(new[] { new XmlQualifiedName("", rootAttribute.Namespace) }); } return(qualifiedNames.ToArray()); }
private Test BuildAssemblyTest(Test parent, ICollection <KeyValuePair <Test, string> > unresolvedDependencies) { Test assemblyTest = new Test(assembly.Name, assembly); PopulateAssemblyTestMetadata(assemblyTest, assembly); foreach (AssemblyDependsOnAttribute2 attrib in AttributeUtils.GetAttributes <AssemblyDependsOnAttribute2>(assembly, false)) { unresolvedDependencies.Add(new KeyValuePair <Test, string>(assemblyTest, attrib.AssemblyName)); } parent.AddChild(assemblyTest); return(assemblyTest); }
private static void InitializeAssembly(IPatternScope rootScope, IAssemblyInfo assembly) { foreach (TestAssemblyInitializationAttribute attrib in AttributeUtils.GetAttributes <TestAssemblyInitializationAttribute>(assembly, false)) { try { attrib.Initialize(rootScope, assembly); } catch (Exception ex) { rootScope.TestModelBuilder.PublishExceptionAsAnnotation(assembly, ex); } } }
private void BuildFixturesFromType(Test parent, ITypeInfo type) { try { foreach (TestFixturePatternAttribute2 attrib in AttributeUtils.GetAttributes <TestFixturePatternAttribute2>(type, true)) { BuildTestFixtureFromPatternAttribute(parent, type, attrib); } } catch (Exception ex) { testModel.AddAnnotation(new Annotation(AnnotationType.Error, type, "An exception was thrown while exploring an MbUnit v2 test type.", ex)); } }
private static void PopulateCommonMetadata(ICodeElementInfo codeElement, PropertyBag metadata) { // Add ignore reason. foreach (IgnoreAttribute attr in AttributeUtils.GetAttributes <IgnoreAttribute>(codeElement, true)) { metadata.Add(MetadataKeys.IgnoreReason, attr.Reason ?? "<unknown>"); } // Add documentation. string xmlDocumentation = codeElement.GetXmlDocumentation(); if (!String.IsNullOrEmpty(xmlDocumentation)) { metadata.Add(MetadataKeys.XmlDocumentation, xmlDocumentation); } }
private static void PopulateFixtureMetadata(ICodeElementInfo codeElement, PropertyBag metadata) { foreach (TestFixtureAttribute attr in AttributeUtils.GetAttributes <TestFixtureAttribute>(codeElement, true)) { // Add categories string categories = attr.Categories; if (!String.IsNullOrEmpty(categories)) { foreach (string category in categories.Split(',')) { metadata.Add(MetadataKeys.Category, category); } } } PopulateCommonMetadata(codeElement, metadata); }
public override IEnumerable <EntryInfo> GetEntriesIn(TContainer container) { var pointer = _getPointer(container); if (pointer.Value != null) { var description = AttributeUtils.GetAttributes <DescriptionAttribute, TProperty>().FirstOrDefault(); yield return(new EntryInfo( name: _name, description: description?.Description, target: pointer.Value, getEditorControl: executor => CreateEditor(container, pointer.Value, executor), toXmlString: () => pointer.Value.ToXmlString(), fromXmlString: xmlString => { var newValue = XmlStorage.FromXmlString <TProperty>(xmlString); return newValue.Equals(pointer.Value) ? null : new SetValueCommand <TProperty>(pointer, newValue); }, removeCommand: new SetValueCommand <TProperty>(pointer, null))); } }
private static void BuildRowTest(Test parent, IMethodInfo method, string namePrefix, string nameSuffix, RowTestAttribute2 attrib) { foreach (RowAttribute2 rowAttrib in AttributeUtils.GetAttributes <RowAttribute2>(method, true)) { // Note: The way the name is formatted must be identical to that which MbUnit v2 natively produces. object[] row = rowAttrib.GetRow(); StringWriter rowName = new StringWriter(CultureInfo.InvariantCulture); rowName.Write('('); for (int i = 0; i < row.Length; i++) { if (i != 0) { rowName.Write(','); } rowName.Write(row[i]); } rowName.Write(')'); AddChildTest(parent, method, namePrefix, rowName + nameSuffix); } }
public EntryInfo TryGetEntry(TContainer container, IList <TList> list, TList candidate) { if (!(candidate is TElement element)) { return(null); } var description = AttributeUtils.GetAttributes <DescriptionAttribute, TElement>().FirstOrDefault(); return(new EntryInfo( name: _name, description: description?.Description, target: element, getEditorControl: executor => CreateEditor(container, element, executor), toXmlString: () => element.ToXmlString(), fromXmlString: xmlString => { var newValue = XmlStorage.FromXmlString <TElement>(xmlString); return newValue.Equals(element) ? null : new ReplaceInList <TList>(list, element, newValue); }, removeCommand: new RemoveFromCollection <TList>(list, element))); }