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(); }
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); }