Example #1
0
            public object Clone()
            {
                TestComponentInfo copy = new TestComponentInfo();

                copy.assembly = this.assembly;
                copy.type     = this.type;
                return(copy);
            }
    private TestComponentInfo[] CreateTestComponentInfos(string line)
    {
        string[]            strings = line.Split(TestFixtureBase.TEST_COMPONENT_DELIMITER);
        TestComponentInfo[] infos   = new TestComponentInfo[strings.Length - 2];

        for (int i = 0; i <= strings.Length - 1; i++)
        {
            string[]          strings2 = strings[i].Split(TestFixtureBase.ELEMENT_DELIMITER);
            TestComponentInfo info;
            info.Component = (TestComponent)this.CreateType(strings2[0]);
            info.Args      = strings2[1].Split(TestFixtureBase.ARG_DELIMITER);
            infos[i]       = info;
        }

        return(infos);
    }
Example #3
0
        public static List <Type> ParseTypeList(string fileName, Type superClassType)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(fileName + " does not exist.");
            }
            List <Type> foundTypes = new List <Type>();

            // Read full file...
            StringReader  xmlReader         = new StringReader(File.ReadAllText(fileName));
            XmlTextReader readerForTypeList = new XmlTextReader(xmlReader);
            // Holds default object to base other objects from
            TestComponentInfo defaultTestComponentInfo = new TestComponentInfo();

            while (readerForTypeList.Read())
            {
                if (readerForTypeList.NodeType == XmlNodeType.Element)
                {
                    switch (readerForTypeList.Name)
                    {
                    // Loading the default...
                    case "DefaultTestComponentInfo":
                    {
                        ParseTestComponentInfo(readerForTypeList, defaultTestComponentInfo, superClassType);
                        break;
                    }

                    // Loading a regular type
                    case "TestComponentInfo":
                    {
                        TestComponentInfo testComponentInfo = (TestComponentInfo)defaultTestComponentInfo.Clone();
                        Type newlyFoundType = ParseTestComponentInfo(readerForTypeList, testComponentInfo, superClassType);
                        if (newlyFoundType == null)
                        {
                            throw new InvalidOperationException("The testInfo for type: " + testComponentInfo.Type + " could not be successfully loaded.");
                        }
                        AddToList(foundTypes, newlyFoundType, superClassType);
                        break;
                    }

                    // Loading a list of types from a file
                    case "LoadFile":
                    {
                        string      fileToLoad       = DetermineFilePath(readerForTypeList, fileName);
                        List <Type> typesFoundInFile = ParseTypeList(fileToLoad, superClassType);
                        AddToList(foundTypes, typesFoundInFile, superClassType);
                        break;
                    }

                    // Loading all matching types from an assembly file
                    case "LoadAllTypesFromAssembly":
                    {
                        string      fileToLoad       = readerForTypeList.GetAttribute("FileName");
                        List <Type> typesFoundInFile = GatherTypesFromAssembly(fileToLoad, superClassType);
                        AddToList(foundTypes, typesFoundInFile, superClassType);
                        break;
                    }

                    default:
                        break;
                    }
                }
            }
            xmlReader.Close();
            return(foundTypes);
        }
Example #4
0
        private static Type ParseTestComponentInfo(XmlTextReader componentXmlTextReader, TestComponentInfo testInfo, Type mustDeriveFromType)
        {
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(TestComponentInfo));

            // Parse all the attributes as properties of TestComponentInfo
            // Largely "borrowed" from XTCAdapter :)
            if (componentXmlTextReader.MoveToFirstAttribute())
            {
                do
                {
                    PropertyDescriptor prop = properties[componentXmlTextReader.Name];
                    if (prop == null)
                    {
                        throw new InvalidOperationException("The property " + componentXmlTextReader.Name + " does not exist on TestComponentInfo.");
                    }
                    componentXmlTextReader.ReadAttributeValue();
                    TypeConverter converter = prop.Converter;
                    object        value     = converter.ConvertFromInvariantString(componentXmlTextReader.Value);
                    prop.SetValue(testInfo, value);
                }while (componentXmlTextReader.MoveToNextAttribute());
            }

            if (!String.IsNullOrEmpty(testInfo.Type))
            {
                Assembly moduleToCheckForType = Load(testInfo.Assembly);

                return(Type.GetType(testInfo.Type + "," + moduleToCheckForType.FullName));
            }
            return(null);
        }