Ejemplo n.º 1
0
        public void CacheHit_Dispose_VerifyCacheRefCountDecremented()
        {
            // Arrange
            FunctionDataCacheKey        key = CreateFunctionDataCacheKey();
            Mock <SharedMemoryMetadata> sharedMemMetaMock = CreateMockSharedMemoryMetadata();
            SharedMemoryMetadata        sharedMemMeta     = sharedMemMetaMock.Object;
            Mock <IFunctionDataCache>   cacheMock         = CreateMockFunctionDataCache();

            cacheMock
            .Setup(c => c.DecrementActiveReference(key))
            .Verifiable();
            IFunctionDataCache cache             = cacheMock.Object;
            CacheableReadBlob  cacheableReadBlob = CreateProductUnderTest(key, sharedMemMeta, cache);

            // Act
            cacheableReadBlob.Dispose();

            // Assert
            // This will ensure that the appropriate method was called on the cache
            cacheMock.Verify();
        }
Ejemplo n.º 2
0
        public void CacheMiss_Dispose_VerifyBlobStreamDisposed()
        {
            // Arrange
            FunctionDataCacheKey        key               = CreateFunctionDataCacheKey();
            Mock <IFunctionDataCache>   cacheMock         = CreateMockFunctionDataCache();
            IFunctionDataCache          cache             = cacheMock.Object;
            Mock <SharedMemoryMetadata> sharedMemMetaMock = CreateMockSharedMemoryMetadata();
            SharedMemoryMetadata        sharedMemMeta     = sharedMemMetaMock.Object;
            Mock <Stream> blobStreamMock = CreateMockBlobStream();

            blobStreamMock
            .Setup(s => s.Close())     // Close is called internally when Stream is Disposed
            .Verifiable();
            Stream            blobStream        = blobStreamMock.Object;
            CacheableReadBlob cacheableReadBlob = CreateProductUnderTest(key, blobStream, cache);

            // Act
            cacheableReadBlob.Dispose();

            // Assert
            // This will ensure that the appropriate method was called on the stream
            blobStreamMock.Verify();
        }
Ejemplo n.º 3
0
        public void CacheMiss_Dispose_VerifyCacheRefCountNotDecremented()
        {
            // Arrange
            FunctionDataCacheKey      key       = CreateFunctionDataCacheKey();
            Mock <IFunctionDataCache> cacheMock = CreateMockFunctionDataCache();

            cacheMock
            .Setup(c => c.DecrementActiveReference(key))
            .Throws(new Exception("This should not be called"));
            IFunctionDataCache cache          = cacheMock.Object;
            Mock <Stream>      blobStreamMock = CreateMockBlobStream();

            blobStreamMock
            .Setup(s => s.Close())
            .Verifiable();
            Stream            blobStream        = blobStreamMock.Object;
            CacheableReadBlob cacheableReadBlob = CreateProductUnderTest(key, blobStream, cache);

            // Act
            cacheableReadBlob.Dispose();

            // Assert
            // If the wrong method was called, an exception would have been thrown
        }