示例#1
0
 public static XElement CreateXError(string message, Exception ex = null)
 {
     return(XConcurrencyNames.CreateXError(message, ex));
 }
示例#2
0
        /// <summary>
        /// Reads the assembly specified in the constructor.
        /// If the file doesn't exist, an empty test assembly element is returned.
        /// </summary>
        /// <returns></returns>
        public XElement Read()
        {
            // Initialize the assembly node
            XElement xtestAssy = CreateXTestAssemblyPlaceholder(_assyLocation);

            // The assembly may not actually exist yet because it hasn't been built
            // so only load the assembly if it exists
            if (File.Exists(_assyLocation))
            {
                try
                {
                    if (_testAssembly == null)
                    {
                        _testAssembly = Assembly.LoadFrom(_assyLocation);
                    }

                    // Add assembly-level attribute representations
                    var assyAttrs = _testAssembly.GetCustomAttributes(true);


                    // Get the explicit and implicit InstrumentAssemblyAttributes
                    var instrumentAssyAttrs = assyAttrs.OfType <ChessInstrumentAssemblyAttribute>();
                    var assysToExclude      = instrumentAssyAttrs
                                              .Where(attr => attr.Exclude)
                                              .Select(attr => attr.Assembly);

                    // Generate the implicit InstrumentAssemblyAttributes
                    var implicitInstrumentAssyAttrs = GetReferencedAssembliesToInstrument(_testAssembly)
                                                      .Where(refAssyName => !assysToExclude.Contains(refAssyName))
                                                      .Select(refAssyName => new ChessInstrumentAssemblyAttribute(refAssyName));
                    instrumentAssyAttrs = implicitInstrumentAssyAttrs.Union(instrumentAssyAttrs);

                    xtestAssy.Add(
                        // TODO: Make this a generic feature so other types of tests properties will be recognized
                        instrumentAssyAttrs
                        .Select(attr => attr.ToTestlistXml())
                        );

                    // Add the rest of the assembly-level setting attributes
                    xtestAssy.Add(
                        assyAttrs.OfType <ChessDefaultPreemptabilityAttribute>()
                        .Select(attr => attr.ToTestlistXml())
                        );
                    xtestAssy.Add(
                        assyAttrs.OfType <ChessTogglePreemptabilityAttribute>()
                        .Select(attr => attr.ToTestlistXml())
                        );


                    // Add test classes
                    xtestAssy.Add(
                        from t in _testAssembly.GetTypes()
                        where !t.IsAbstract
                        // I'm deciding to let this error propagate up to the user as an error
                        // rather than the user not knowing why it's not showing up.
                        //where t.IsVisible
                        //let ctor = t.GetConstructor(Type.EmptyTypes)
                        //where ctor != null && ctor.IsPublic
                        let attributes = t.GetCustomAttributes(false)
                                         where !attributes.OfType <IgnoreAttribute>().Any()
                                         let xtestClass = ReadTestClass(t)
                                                          where xtestClass.Descendants(XNames.TestMethod).Any() // Where the class had some test methods defined
                                                          orderby t.FullName
                                                          select xtestClass
                        );
                }
                catch (Exception ex)
                {
                    xtestAssy.Add(XConcurrencyNames.CreateXError(ex));
                }
            }

            return(xtestAssy);
        }
示例#3
0
        // helpers

        public static XElement CreateXError(Exception ex)
        {
            return(XConcurrencyNames.CreateXError(ex));
        }