Beispiel #1
0
        public void TryPutToCache_VerifySuccess(bool expected)
        {
            // Arrange
            FunctionDataCacheKey key   = CreateFunctionDataCacheKey();
            bool isIncrementActiveRefs = true;
            Mock <SharedMemoryMetadata> sharedMemMetaMock = CreateMockSharedMemoryMetadata();
            SharedMemoryMetadata        sharedMemMeta     = sharedMemMetaMock.Object;
            Mock <IFunctionDataCache>   cacheMock         = CreateMockFunctionDataCache();

            cacheMock
            .Setup(c => c.TryPut(key, sharedMemMeta, isIncrementActiveRefs, false))
            .Returns(expected)
            .Verifiable();
            IFunctionDataCache cache             = cacheMock.Object;
            Mock <Stream>      blobStreamMock    = CreateMockBlobStream();
            Stream             blobStream        = blobStreamMock.Object;
            CacheableReadBlob  cacheableReadBlob = CreateProductUnderTest(key, blobStream, cache);

            // Act
            bool result = cacheableReadBlob.TryPutToCache(sharedMemMeta, isIncrementActiveRefs);

            // Assert
            Assert.AreEqual(expected, result);
            cacheMock.Verify();
        }
Beispiel #2
0
        public void CreateCacheableReadBlob_IsCacheMiss()
        {
            // Arrange
            FunctionDataCacheKey      key            = CreateFunctionDataCacheKey();
            Mock <IFunctionDataCache> cacheMock      = CreateMockFunctionDataCache();
            IFunctionDataCache        cache          = cacheMock.Object;
            Mock <Stream>             blobStreamMock = CreateMockBlobStream();
            Stream            blobStream             = blobStreamMock.Object;
            CacheableReadBlob cacheableReadBlob      = CreateProductUnderTest(key, blobStream, cache);

            // Act
            bool isCacheHit = cacheableReadBlob.IsCacheHit;

            // Assert
            Assert.False(isCacheHit);
        }
Beispiel #3
0
        public void CreateCacheableReadBlob_IsCacheHit()
        {
            // Arrange
            FunctionDataCacheKey        key               = CreateFunctionDataCacheKey();
            Mock <IFunctionDataCache>   cacheMock         = CreateMockFunctionDataCache();
            IFunctionDataCache          cache             = cacheMock.Object;
            Mock <SharedMemoryMetadata> sharedMemMetaMock = CreateMockSharedMemoryMetadata();
            SharedMemoryMetadata        sharedMemMeta     = sharedMemMetaMock.Object;
            CacheableReadBlob           cacheableReadBlob = CreateProductUnderTest(key, sharedMemMeta, cache);

            // Act
            bool isCacheHit = cacheableReadBlob.IsCacheHit;

            // Assert
            Assert.True(isCacheHit);
        }
Beispiel #4
0
        public void TryPutToCacheAlreadyCached_VerifyFailure()
        {
            // Arrange
            FunctionDataCacheKey key            = CreateFunctionDataCacheKey();
            bool isIncrementActiveRefs          = true;
            Mock <IFunctionDataCache> cacheMock = CreateMockFunctionDataCache();

            cacheMock
            .Setup(c => c.TryPut(key, It.IsAny <SharedMemoryMetadata>(), isIncrementActiveRefs, false))
            .Throws(new Exception("This should not be called"));
            IFunctionDataCache          cache             = cacheMock.Object;
            Mock <SharedMemoryMetadata> sharedMemMetaMock = CreateMockSharedMemoryMetadata();
            SharedMemoryMetadata        sharedMemMeta     = sharedMemMetaMock.Object;
            CacheableReadBlob           cacheableReadBlob = CreateProductUnderTest(key, sharedMemMeta, cache);

            // Act
            bool result = cacheableReadBlob.TryPutToCache(sharedMemMeta, isIncrementActiveRefs);

            // Assert
            Assert.IsFalse(result);
        }
Beispiel #5
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();
        }
Beispiel #6
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();
        }
Beispiel #7
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
        }