Пример #1
0
        // Tries adding an unsuppirted type to the store,
        // and ensures the correct exception is being thrown because of that.
        public void TestUnsupportedType()
        {
            var store = new ObjectStore();

            string key = "MyObject1";
            var    obj = InvalidObjectFactory(1);

            // This should throw an InvalidOperationException
            store.AddOrUpdate <IStoredType>(key, obj);
        }
Пример #2
0
        public static void CheckedAddToStore(ObjectStore store, string key, IStoredType obj)
        {
            bool added = store.AddOrUpdate(key, obj);

            Assert.IsTrue(added, "Failed to add object to the object store");

            bool exists = store.Exists(key);

            Assert.IsTrue(exists, "Object was not found in the object store");

            IStoredObject <IStoredType> retrievedObj = null;
            bool retrievedSuccess = store.GetByName <IStoredType>(key, out retrievedObj);

            Assert.IsTrue(retrievedSuccess, "Object could not be retrieved from the object store");

            bool retrievedObjectEqualsOriginal = retrievedObj.Object.Equals(obj);

            Assert.IsTrue(retrievedObjectEqualsOriginal, "Retrieved object does not equal original object");
        }
Пример #3
0
        // Adds an object to the store, then removes it again
        public void TestRemove()
        {
            var store = new ObjectStore();

            string key = "MyObject1";
            var    obj = ValidObjectFactory(1);

            bool added = store.AddOrUpdate(key, obj);

            Assert.IsTrue(added, "Failed to add object to the object store");

            bool exists = store.Exists(key);

            Assert.IsTrue(exists, "Object was not found in the object store");

            bool removed = store.Remove(key);

            Assert.IsTrue(removed, "Object could not be removed from the object store");

            bool doesNotExist = !store.Exists(key);

            Assert.IsTrue(doesNotExist, "Object was still found in the object store, even though it should have been removed");
        }