private TestStepReportFile Patch(TestStepReportFile testStepReportFile)
        {
            var result = StoredTestStepReportFiles.Find(testStepReportFile.Id) ?? StoredTestStepReportFiles.Add(testStepReportFile);
            if (!result.IsPatched && !result.IsPatching)
            {
                result.IsPatching = true;
                try
                {
                    var selectedTestStep = TestStep(result.fk_TestStepId);
                    result.TestStep = selectedTestStep;

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

            return result;
        }
        /// <summary>
        /// Adds a new test step report file.
        /// </summary>
        /// <param name="reportFile">The new report file.</param>
        public void Add(TestStepReportFile reportFile)
        {
            VerifySchemaVersion();

            var result = StoredTestStepReportFiles.Add(reportFile);
            Patch(result);
        }
        /// <summary>
        /// Updates the given report file.
        /// </summary>
        /// <param name="reportFile">The report file that should be updated.</param>
        public void Update(TestStepReportFile reportFile)
        {
            VerifySchemaVersion();

            var storedReportFile = TestStepReportFile(reportFile.Id);
            if (storedReportFile != null)
            {
                if (!ReferenceEquals(storedReportFile, reportFile))
                {
                    storedReportFile.Path = reportFile.Path;

                    if (storedReportFile.fk_TestStepId != reportFile.fk_TestStepId)
                    {
                        storedReportFile.fk_TestStepId = reportFile.fk_TestStepId;
                        storedReportFile.TestStep = null;
                        Patch(storedReportFile);
                    }
                }

                var entry = Entry(storedReportFile);
                entry.State = EntityState.Modified;
            }
        }
        public void ForFile(int testStep, string path)
        {
            var testStepReportFile = new TestStepReportFile
            {
                TestStepId = testStep,
                Path = path,
            };

            try
            {
                m_Context.Add(testStepReportFile);
                m_Context.StoreChanges();
            }
            catch (Exception e)
            {
                m_Diagnostics.Log(
                    LevelToLog.Error,
                    WebApiConstants.LogPrefix,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Registering the test step report files failed with error: {0}",
                        e));

                throw;
            }
        }