コード例 #1
0
        /// <summary>
        /// Adds a new test environment.
        /// </summary>
        /// <param name="environment">The test environment.</param>
        public void Add(TestEnvironment environment)
        {
            VerifySchemaVersion();

            var result = StoredTestEnvironments.Add(environment);
            Patch(result);
        }
コード例 #2
0
        private TestEnvironment Patch(TestEnvironment testEnvironment)
        {
            var result = StoredTestEnvironments.Find(testEnvironment.Id) ?? StoredTestEnvironments.Add(testEnvironment);
            if (!result.IsPatched && !result.IsPatching)
            {
                result.IsPatching = true;
                try
                {
                    if (result.SelectedMachineId != null)
                    {
                        var selectedMachine = Machine(result.SelectedMachineId);
                        result.Machine = selectedMachine;
                    }

                    var selectedOperatingSystem = GetOperatingSystemsById(result.DesiredOperatingSystemId)
                        .Select(Patch)
                        .FirstOrDefault();
                    result.OperatingSystem = selectedOperatingSystem;

                    var selectedTest = GetTestsById(result.TestId)
                        .Select(Patch)
                        .FirstOrDefault();
                    result.Test = selectedTest;

                    var selectedApplications = GetTestApplicationsByTestEnvironmentId(result.Id)
                        .Select(id => TestApplication(id.Value))
                        .ToList();
                    result.TestApplications = selectedApplications;

                    var selectedTestSteps = GetTestStepsByTestEnvironmentId(result.Id)
                        .Select(id => TestStep(id.Value))
                        .ToList();
                    result.TestSteps = selectedTestSteps;

                    result.IsPatched = true;
                }
                finally
                {
                    result.IsPatching = false;
                }
            }

            return result;
        }
コード例 #3
0
        /// <summary>
        /// Updates the test environment with the data from the given object.
        /// </summary>
        /// <param name="environment">The test environment.</param>
        public void Update(TestEnvironment environment)
        {
            VerifySchemaVersion();

            var storedEnvironment = TestEnvironment(environment.Id);
            if (storedEnvironment != null)
            {
                bool shouldPatch = false;
                if (!ReferenceEquals(storedEnvironment, environment))
                {
                    storedEnvironment.EnvironmentName = environment.EnvironmentName;
                    if (storedEnvironment.fk_DesiredOperatingSystemId != environment.fk_DesiredOperatingSystemId)
                    {
                        storedEnvironment.fk_DesiredOperatingSystemId = environment.fk_DesiredOperatingSystemId;
                        shouldPatch = true;
                    }

                    if (storedEnvironment.fk_TestId != environment.fk_TestId)
                    {
                        storedEnvironment.fk_TestId = environment.fk_TestId;
                        shouldPatch = true;
                    }
                }

                if (shouldPatch)
                {
                    storedEnvironment.IsPatched = false;
                    Patch(storedEnvironment);
                }

                var entry = Entry(storedEnvironment);
                entry.State = EntityState.Modified;
            }
        }
コード例 #4
0
        private static Shared.DataAccess.Test CreateFakeTestSpecification(TestEnvironment environment)
        {
            var test = new Shared.DataAccess.Test
                {
                    pk_TestId = 1,
                    ProductName = "tda",
                    ProductVersion = "tdb",
                    Owner = "tdc",
                    TestDescription = "tdd",
                    ReportPath = @"c:\d\e\f",
                    TestEnvironments = new List<TestEnvironment>
                        {
                            environment
                        }
                };

            return test;
        }
コード例 #5
0
        private static TestEnvironment CreateFakeTestEnvironment(string name)
        {
            var environment = new TestEnvironment
                {
                    Name = name,
                    OperatingSystem = new OperatingSystemDescription(),
                    TestApplications = new List<TestApplication>(),
                };

            return environment;
        }
コード例 #6
0
        /// <summary>
        /// Activates the given machine and returns an object that can be used to manipulate
        /// the machine.
        /// </summary>
        /// <param name="currentContext">The current data storage context.</param>
        /// <param name="machine">The description of the machine.</param>
        /// <param name="environment">The description of the environment.</param>
        /// <param name="sectionBuilder">
        ///     The object used to write information to the report about the starting and stopping of the machine.
        /// </param>
        /// <returns>An object that is used to manipulate the active machine.</returns>
        private IActiveEnvironment ActivateMachineForEnvironment(
            IProvideTestingContext currentContext,
            MachineDescription machine,
            TestEnvironment environment,
            ITestSectionBuilder sectionBuilder)
        {
            lock (m_Lock)
            {
                {
                    Lokad.Enforce.Argument(() => machine);
                    Lokad.Enforce.With<ArgumentException>(
                        m_Activators.Any(a => a.EnvironmentTypeToLoad == machine.GetType()),
                        Resources.Exceptions_Messages_NoActivatorHasBeenRegisteredForTheEnvironment);
                }

                var activator = m_Activators.Find(a => a.EnvironmentTypeToLoad == machine.GetType());
                Debug.Assert(activator != null, "We should have found an activator.");

                var activeEnvironment = activator.Load(machine, sectionBuilder, OnEnvironmentUnloaded);

                currentContext.MarkMachineAsActive(machine.Id);
                currentContext.TestEnvironmentSupportedByMachine(environment.Id, machine.Id);

                return activeEnvironment;
            }
        }
コード例 #7
0
        public int Register(string name, int test)
        {
            try
            {
                var content = Request.Content;
                var textContent = content.ReadAsStringAsync().Result;
                var xmlContent = XDocument.Parse(textContent);

                var operatingSystem = ExtractOperatingSystem(xmlContent);
                var operatingSystemId = m_Context.OperatingSystems()
                    .Where(
                        o => string.Equals(o.Name, operatingSystem.Name, StringComparison.OrdinalIgnoreCase)
                            && string.Equals(o.ServicePack, operatingSystem.ServicePack, StringComparison.OrdinalIgnoreCase)
                            && o.CultureInfo.Equals(operatingSystem.CultureInfo)
                            && (o.PointerSize == operatingSystem.PointerSize))
                    .Select(o => o.Id)
                    .First();

                var environment = new TestEnvironment
                    {
                        Name = name,
                        DesiredOperatingSystemId = operatingSystemId,
                        TestId = test,
                    };

                m_Context.Add(environment);
                m_Context.StoreChanges();

                SetApplicationsForEnvironment(xmlContent, environment.Id);

                return environment.Id;
            }
            catch (Exception e)
            {
                m_Diagnostics.Log(
                    LevelToLog.Error,
                    WebApiConstants.LogPrefix,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Registering the test environment failed with error: {0}",
                        e));

                throw;
            }
        }