/// <summary>
 /// Fetch and return specific key in result
 /// </summary>
 private CommandResult Read(string key)
 {
     try
     {
         if (key is null)
         {
             throw new ArgumentNullException("key");
         }
         return(new SuccessResult <string>
         {
             Result = _store.GetValue(key)
         });
     }
     catch (KeyNotFoundInRepositoryException)
     {
         return(new FailureResult
         {
             ErrorMessage = "key not found"
         });
     }
     catch (ArgumentNullException e)
     {
         return(new FailureResult
         {
             ErrorMessage = e.ParamName + " is required"
         });
     }
 }
Exemplo n.º 2
0
            /// <summary>
            /// Generate sequence of actions that set then get KeyValue in provided repository.
            /// </summary>
            private static Action[] GenerateTestSeqSetRead(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());
                        Assert.Equal(store.GetValue(indx.ToString()), indx.ToString());
                    };
                }

                return(actions);
            }
Exemplo n.º 3
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);
            }