Beispiel #1
0
            public void AddKeyValues_GetIt(int elementsToAdd)
            {
                var store = new MemoryKeyValueRepository();

                foreach (var kv in GetKeyValues(elementsToAdd))
                {
                    store.SetValue(kv.Key, kv.Value);
                    Assert.Equal(store.GetValue(kv.Key), kv.Value);
                }
            }
Beispiel #2
0
            public void AddKeyValues_DeleteHalf(int elementsToAdd)
            {
                var store = new MemoryKeyValueRepository();
                var i     = 0;

                foreach (var kv in GetKeyValues(elementsToAdd))
                {
                    store.SetValue(kv.Key, kv.Value);
                    if (i % 2 == 0)
                    {
                        store.DeleteValue(kv.Key);
                        Assert.Throws <KeyNotFoundInRepositoryException>(() => store.GetValue(kv.Key));
                    }
                    i += 1;
                }
            }
Beispiel #3
0
            /// <summary>
            /// Generate sequence of actions that set then update then get KeyValue in provided repository.
            /// </summary>
            private static Action[] GenerateTestSeqSetUpdate(int elementsCount, MemoryKeyValueRepository 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.UpdateValue(indx.ToString(), (indx + 15).ToString());
                        Assert.Equal(store.GetValue(indx.ToString()), (indx + 15).ToString());
                    };
                }
                return(actions);
            }
Beispiel #4
0
            public void DeleteNonexistentKey_Throws()
            {
                var store = new MemoryKeyValueRepository();

                Assert.Throws(typeof(KeyNotFoundInRepositoryException), () => store.DeleteValue("NotExistKeyValueThrows"));
            }
Beispiel #5
0
            public void AddKeyValues_DeleteIt(int elementsToAdd)
            {
                var store = new MemoryKeyValueRepository();

                Parallel.Invoke(GenerateTestSeqSetDelete(elementsToAdd, store));
            }
Beispiel #6
0
            public void GetEmptyCollectionKeys_WhenEmpty()
            {
                var store = new MemoryKeyValueRepository();

                Assert.Empty(store.GetAllKeys());
            }