/// <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); }
/// <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); }
/// <summary> /// Store KeyValue and return success result /// </summary> private CommandResult Create(string key, string value) { try { if (key is null || key.Trim().Length == 0) { throw new ArgumentNullException("key"); } if (value is null) { throw new ArgumentNullException("value"); } _store.SetValue(key, value); return(new SuccessResult()); } catch (ArgumentNullException e) { return(new FailureResult { ErrorMessage = e.ParamName + " is required" }); } }