/// <summary>
        /// Adds a new test.
        /// </summary>
        /// <param name="test">The test.</param>
        public void Add(Test test)
        {
            VerifySchemaVersion();

            var result = StoredTests.Add(test);
            Patch(result);
        }
        private Test Patch(Test test)
        {
            var result = StoredTests.Find(test.Id) ?? StoredTests.Add(test);
            if (!result.IsPatched && !result.IsPatching)
            {
                result.IsPatching = true;
                try
                {
                    var selectedEnvironments = GetTestEnvironmentsByTestId(result.Id)
                        .Select(id => TestEnvironment(id.Value))
                        .ToList();
                    result.TestEnvironments = selectedEnvironments;

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

            return result;
        }
        /// <summary>
        /// Updates the test with the data from the given object.
        /// </summary>
        /// <param name="test">The test.</param>
        public void Update(Test test)
        {
            VerifySchemaVersion();

            var storedTest = Test(test.Id);
            if (storedTest != null)
            {
                if (!ReferenceEquals(storedTest, test))
                {
                    storedTest.ProductName = test.ProductName;
                    storedTest.ProductVersion = test.ProductVersion;
                    storedTest.TestDescription = test.TestDescription;
                    storedTest.Owner = test.Owner;
                    storedTest.ReportPath = test.ReportPath;
                    storedTest.RequestTime = test.RequestTime;
                    storedTest.StartTime = test.StartTime;
                    storedTest.EndTime = test.EndTime;
                }

                var entry = Entry(storedTest);
                entry.State = EntityState.Modified;
            }
        }