Ejemplo n.º 1
0
 public void TestBasicCachingFunctionality()
 {
     string objectToStore = "Test Object";
     CacheManager manager = new CacheManager(new MemoryProvider());
     manager.Store(objectToStore);
     Assert.AreEqual(objectToStore, manager.GetMostRecentCacheItem());
 }
Ejemplo n.º 2
0
        public void TestMockingTheExtendableMemoryProvider()
        {
            using (ShimsContext.Create())
            {
                // Arrange.
                ShimExtendableMemoryProvider memoryProviderMock = new ShimExtendableMemoryProvider();
                object objectStored = null;
                long storedAtAddress = -1;
                memoryProviderMock.WriteInt64Object = (address, objToStore) =>
                    {
                        storedAtAddress = address;
                        objectStored = objToStore;
                    };
                memoryProviderMock.ReadInt64 = (address) =>
                    {
                        if (address != storedAtAddress)
                            throw new ArgumentOutOfRangeException();
                        return objectStored;
                    };
                CacheManager manager = new CacheManager(memoryProviderMock.Instance);

                // Act.
                string objectToStore = "Test Object";
                manager.Store(objectToStore);
                object objectRead = manager.GetMostRecentCacheItem();

                // Assert.
                Assert.AreEqual(objectToStore, objectRead);
            }
        }
Ejemplo n.º 3
0
        public void TestToShowPassthruCapabilities()
        {
            using (ShimsContext.Create())
            {
                object objectStored = null;

                // This is setting the behavior to the "default" behavior of fallthru.
                Microsoft.QualityTools.Testing.Fakes.Shims.ShimBehaviors.BehaveAsFallthrough();
                ShimExtendableMemoryProvider.BehaveAsCurrent();

                ShimExtendableMemoryProvider.AllInstances.WriteInt64Object = (instance, address, objToStore) =>
                    {
                        objectStored = objToStore;
                    };
                CacheManager manager = new CacheManager(new ExtendableMemoryProvider());

                // Act.
                manager.Store("Test");
                object mostRecentItem = manager.GetMostRecentCacheItem();
            }
        }
Ejemplo n.º 4
0
        public void TestCachingWithStub()
        {
            using (ShimsContext.Create())
            {
                // Arrange.
                StubIMemoryModule memoryModule = new StubIMemoryModule();
                object objectWritten = null;
                memoryModule.WriteInt64Object = (address, objectToWrite) =>
                    {
                        objectWritten = objectToWrite;
                    };
                memoryModule.ReadInt64 = (address) => objectWritten;
                CacheManager manager = new CacheManager(memoryModule);
                string myObj = "Test Object";

                // Act.
                manager.Store(myObj);
                object retrievedOjbect = manager.GetMostRecentCacheItem();

                // Assert.
                Assert.AreEqual(myObj, retrievedOjbect, "Retrieved object is not the same as stored.");
            }
        }