/// <summary>
        /// Registers a test step parameter.
        /// </summary>
        /// <param name="testStep">The ID of the test step to which the parameter belongs.</param>
        /// <param name="key">The key of the parameter.</param>
        /// <param name="value">The value of the parameter.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="key"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     Thrown if <paramref name="key"/> is an empty string.
        /// </exception>
        public void Register(int testStep, string key, string value)
        {
            {
                Lokad.Enforce.Argument(() => key);
                Lokad.Enforce.Argument(() => key, Lokad.Rules.StringIs.NotEmpty);
            }

            var parameter = new TestStepParameter
                {
                    Key = key,
                    Value = value,
                    TestStepId = testStep,
                };

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

                throw;
            }
        }
        /// <summary>
        /// Updates the given parameter.
        /// </summary>
        /// <param name="parameter">The parameter that should be updated.</param>
        public void Update(TestStepParameter parameter)
        {
            VerifySchemaVersion();

            var storedParameter = TestStepParameter(parameter.Id);
            if (storedParameter != null)
            {
                if (!ReferenceEquals(storedParameter, parameter))
                {
                    storedParameter.Key = parameter.Key;
                    storedParameter.Value = parameter.Value;

                    if (storedParameter.fk_TestStepId != parameter.fk_TestStepId)
                    {
                        storedParameter.fk_TestStepId = parameter.fk_TestStepId;
                        storedParameter.TestStep = null;
                        Patch(storedParameter);
                    }
                }

                var entry = Entry(storedParameter);
                entry.State = EntityState.Modified;
            }
        }
        private TestStepParameter Patch(TestStepParameter testStepParameter)
        {
            var result = StoredTestStepParameters.Find(testStepParameter.Id) ?? StoredTestStepParameters.Add(testStepParameter);
            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 parameter.
        /// </summary>
        /// <param name="parameter">The new parameter.</param>
        public void Add(TestStepParameter parameter)
        {
            VerifySchemaVersion();

            var result = StoredTestStepParameters.Add(parameter);
            Patch(result);
        }