Ejemplo n.º 1
0
        /// <summary>
        /// Gets the location of the test ID under an XML element, based on the specified parameters.
        /// This method is needed to parse the parameters sent by the caller of Save and Load.
        /// We need to support different locations for saving the test ID, because previously, TestEntry and TestResult stored the test ID to @testId
        /// (which is now the default location the TestId class' Save and Load methods), but TestElement was storing it to @id.
        /// Since we can't change the location where the ID is stored in XML, we support custom locations in the TestId class.
        /// </summary>
        /// <param name="parameters">The parameters specifying the locations</param>
        /// <param name="idLocation">The test ID location</param>
        private void GetIdLocation(XmlTestStoreParameters parameters, out string idLocation)
        {
            // Initialize to the default ID location
            idLocation = DefaultIdLocation;

            // If any parameters are specified, see if we need to override the defaults
            if (parameters != null)
            {
                object idLocationObj;
                if (parameters.TryGetValue(IdLocationKey, out idLocationObj))
                {
                    idLocation = idLocationObj as string ?? idLocation;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves the class under the XmlElement..
        /// </summary>
        /// <param name="element">
        /// The parent xml.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        public void Save(XmlElement element, XmlTestStoreParameters parameters)
        {
            XmlPersistence helper = new XmlPersistence();

            // Save all fields marked as StoreXmlSimpleField.
            helper.SaveSingleFields(element, this, parameters);

            helper.SaveGuid(element, "@id", this.id.Id);

            // When saving and loading a TRX file, we want to use the run deployment root directory based on where the TRX file
            // is being saved to or loaded from
            object filePersistenceRootObjectType;

            if (parameters.TryGetValue(XmlFilePersistence.RootObjectType, out filePersistenceRootObjectType) &&
                (Type)filePersistenceRootObjectType == typeof(TestRun))
            {
                Debug.Assert(
                    parameters.ContainsKey(XmlFilePersistence.DirectoryPath),
                    "TestRun is the type of the root object being saved to a file, but the DirectoryPath was not specified in the XML test store parameters");

                Debug.Assert(
                    !string.IsNullOrEmpty(this.runDeploymentRoot),
                    "TestRun is the type of the root object being saved to a file, but the run deployment root directory is null or empty");

                // We are saving a TestRun object as the root element in a file (TRX file), so just save the test run directory
                // name (last directory in the run deployment root), which is the relative path to the run deployment root
                // directory from the directory where the TRX file exists
                helper.SaveSimpleField(
                    element,
                    "Deployment/@runDeploymentRoot",
                    FileHelper.MakePathRelative(this.runDeploymentRoot, Path.GetDirectoryName(this.runDeploymentRoot)),
                    string.Empty);
            }
            else
            {
                // We are not saving a TestRun object as the root element in a file (i.e., we're not saving a TRX file), so just
                // save the run deployment root directory as is
                helper.SaveSimpleField(element, "Deployment/@runDeploymentRoot", this.runDeploymentRoot, string.Empty);
            }
        }