public void TestClose() { EncodedImage encodedImage = new EncodedImage(_byteBufferRef); encodedImage.Dispose(); Assert.AreEqual(1, _byteBufferRef.GetUnderlyingReferenceTestOnly().GetRefCountTestOnly()); }
/// <summary> /// Removes item from the StagingArea. /// </summary> /// <param name="key">The cache key.</param> /// <returns>true if item was removed.</returns> public bool Remove(ICacheKey key) { // For unit test ++_removeCallsTestOnly; Preconditions.CheckNotNull(key); EncodedImage encodedImage = default(EncodedImage); lock (_mapGate) { if (!_map.TryGetValue(key, out encodedImage)) { return(false); } _map.Remove(key); } try { return(encodedImage.Valid); } finally { encodedImage.Dispose(); } }
/// <summary> /// Performs key-value loop up in staging area and file cache. /// Any error manifests itself as a miss, i.e. returns false. /// </summary> /// <param name="key">The cache key.</param> /// <returns> /// true if the image is found in staging area or File cache, /// false if not found. /// </returns> private bool CheckInStagingAreaAndFileCache(ICacheKey key) { EncodedImage result = _stagingArea.Get(key); if (result != null) { result.Dispose(); Debug.WriteLine($"Found image for { key.ToString() } in staging area"); _imageCacheStatsTracker.OnStagingAreaHit(); return(true); } else { Debug.WriteLine($"Did not find image for { key.ToString() } in staging area"); _imageCacheStatsTracker.OnStagingAreaMiss(); try { return(_fileCache.HasKey(key)); } catch (Exception) { return(false); } } }
public void TestCloneOrNull_WithInvalidOrNullReferences() { Assert.AreEqual(null, EncodedImage.CloneOrNull(null)); EncodedImage encodedImage = new EncodedImage(_byteBufferRef); encodedImage.Dispose(); Assert.AreEqual(null, EncodedImage.CloneOrNull(encodedImage)); }
public void TestValid() { EncodedImage encodedImage = new EncodedImage(_byteBufferRef); Assert.IsTrue(encodedImage.Valid); encodedImage.Dispose(); Assert.IsFalse(encodedImage.Valid); encodedImage = new EncodedImage(_inputStreamSupplier); Assert.IsTrue(encodedImage.Valid); // Test the static method Assert.IsFalse(EncodedImage.IsValid(null)); }
/// <summary> /// Test cleanup. /// </summary> public void Dispose() { _encodedImage.Dispose(); }
/// <summary> /// Test cleanup. /// </summary> public void Dispose() { _encodedImage.Dispose(); _secondEncodedImage.Dispose(); }