/// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationInfo"/> class.
        /// </summary>
        /// <param name="test">The test that was stored in the configuration.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="test"/> is <see langword="null" />.
        /// </exception>
        public ConfigurationInfo(TestDescription test)
        {
            {
                Lokad.Enforce.Argument(() => test);
            }

            Test = test;
        }
Beispiel #2
0
        private static void RegisterTest(HttpClient http, Uri serverUrl, TestDescription test)
        {
            WriteToConsole(Resources.Output_Information_RegisteringTest);
            s_Diagnostics.Log(
                LevelToLog.Trace,
                ConsoleConstants.LogPrefix,
                Resources.Log_Trace_RegisteringTest);

            var registerUrl = string.Format(
                CultureInfo.InvariantCulture,
                "{0}/api/Test/Register?product={1}&version={2}&owner={3}&description={4}&reportpath={5}",
                serverUrl.AbsoluteUri,
                Uri.EscapeDataString(test.ProductUnderTest),
                Uri.EscapeDataString(test.VersionOfProductUnderTest),
                Uri.EscapeDataString(test.Owner),
                Uri.EscapeDataString(test.Description),
                Uri.EscapeDataString(test.ReportPath));

            var response = MakePostRequest(http, new Uri(registerUrl), null);
            if (!response.IsSuccessStatusCode)
            {
                s_Diagnostics.Log(
                    LevelToLog.Error,
                    ConsoleConstants.LogPrefix,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.Log_Error_TestRegistrationFailed_WithStatusCodeAndReason,
                        response.StatusCode,
                        response.ReasonPhrase));
                WriteErrorToConsole(Resources.Output_Error_TestRegistrationFailed);

                throw new InvalidServerResponseException();
            }

            var storeTask = GetIdFromReponse(response);
            test.Id = storeTask.Result;

            s_Diagnostics.Log(
                LevelToLog.Trace,
                ConsoleConstants.LogPrefix,
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.Log_Trace_TestRegistrationComplete_WithTestId,
                    test.Id));
        }
        /// <summary>
        /// Reads the configuration from the XML document.
        /// </summary>
        /// <param name="xmlDocument">The XML document.</param>
        /// <returns>A new configuration information object.</returns>
        public ConfigurationInfo Read(XDocument xmlDocument)
        {
            var rootNode = xmlDocument.Element("sherlock");

            var configurationVersion = new Version(rootNode.Attribute("configurationVersion").Value);
            if (!CanReadConfigurationWithVersion(configurationVersion))
            {
                throw new NonMatchingVersionFoundException(configurationVersion.ToString(), SupportedConfigurationVersion.ToString());
            }

            var descriptionNode = rootNode.Element("description");
            if (descriptionNode == null)
            {
                throw new InvalidConfigurationFileException(Resources.Exceptions_Messages_ConfigurationMissingDescriptionElement);
            }

            var productNameNode = descriptionNode.Element("product");
            if (productNameNode == null)
            {
                throw new InvalidConfigurationFileException(Resources.Exceptions_Messages_ConfigurationMissingProductNameElement);
            }

            var productVersionNode = descriptionNode.Element("version");
            if (productVersionNode == null)
            {
                throw new InvalidConfigurationFileException(Resources.Exceptions_Messages_ConfigurationMissingProductVersionElement);
            }

            var testPurposeNode = descriptionNode.Element("testpurpose");
            if (testPurposeNode == null)
            {
                throw new InvalidConfigurationFileException(Resources.Exceptions_Messages_ConfigurationMissingTestPurposeElement);
            }

            var productName = productNameNode.Value;
            var productVersion = productVersionNode.Value;
            var testPurpose = testPurposeNode.Value;
            var owner = string.Format(
                CultureInfo.InvariantCulture,
                @"{0}\{1}",
                Environment.UserDomainName,
                Environment.UserName);

            var constraints = ExtractEnvironmentConstraints(rootNode);
            var testSteps = ExtractTestSteps(rootNode);
            var reportPath = ExtractCompletedNotification(rootNode);

            var description = new TestDescription(productName, productVersion, owner, testPurpose, reportPath, constraints, testSteps);
            return new ConfigurationInfo(description);
        }
Beispiel #4
0
 private static IDictionary<string, int> MapEnvironmentsToTestSteps(TestDescription testCase)
 {
     return testCase.Environments.ToDictionary(s => s.Name, s => s.Id);
 }