/// <summary>
 /// Delete existed KeyValue. If key is not found return error message.
 /// </summary>
 private CommandResult Delete(string key)
 {
     try
     {
         if (key is null)
         {
             throw new ArgumentNullException("key");
         }
         _store.DeleteValue(key);
     }
     catch (KeyNotFoundInRepositoryException)
     {
         return(new FailureResult
         {
             ErrorMessage = "key not found"
         });
     }
     catch (ArgumentNullException e)
     {
         return(new FailureResult
         {
             ErrorMessage = e.ParamName + " is required"
         });
     }
     return(new SuccessResult());
 }
Beispiel #2
0
            /// <summary>
            /// Generate sequence of actions that set then delete then expected throw on attempt to get KeyValue in provided repository.
            /// </summary>
            private static Action[] GenerateTestSeqSetDelete(int elementsCount, IKeyValueRepository store)
            {
                var actions = new Action[elementsCount];

                for (var i = 0; i < elementsCount; i++)
                {
                    var indx = i;
                    actions[i] = () => {
                        store.SetValue(indx.ToString(), indx.ToString());
                        store.DeleteValue(indx.ToString());
                        Assert.Throws(typeof(KeyNotFoundInRepositoryException), () => store.GetValue(indx.ToString()));
                    };
                }

                return(actions);
            }