/// <summary> /// Create a fingerprint from a content hash. /// </summary> public static Hash ToFingerprint(this CasHash casHash) { var hex = casHash.ToString(); var fingerprint = FingerprintUtilities.Hash(hex); return(new Hash(fingerprint)); }
public void PinResultMissFromMemoization() { PinResult pinResult = PinResult.ContentNotFound; CasHash hash = RandomHelpers.CreateRandomCasHash(); Possible <string, Failure> maybe = pinResult.FromMemoization(hash, CacheId); Assert.False(maybe.Succeeded); NoCasEntryFailure failure = maybe.Failure as NoCasEntryFailure; Assert.False(failure == null); string failureMessage = failure.Describe(); Assert.Contains(hash.ToString(), failureMessage); Assert.Contains(CacheId, failureMessage); }
/// <summary> /// Check the fake build via the session given /// </summary> /// <param name="session">Session to use for the check</param> /// <param name="index">The "index" CasHash</param> /// <param name="entries">The CasHash entries that should match the index</param> /// <param name="accessMethod">Method (File or stream) for how files are materialized from the cache</param> /// <returns>An Async Task</returns> public static async Task CheckContentsAsync(ICacheReadOnlySession session, CasHash index, CasEntries entries, CasAccessMethod accessMethod = CasAccessMethod.Stream) { string cacheId = await session.PinToCasAsync(index, CancellationToken.None).SuccessAsync("Cannot pin entry {0} to cache {1}", index.ToString(), session.CacheId); string[] expected = (await GetStreamAsync(index, accessMethod, session)).Success().Stream.AsString().Split(s_splitLines, StringSplitOptions.RemoveEmptyEntries); XAssert.AreEqual(expected.Length, entries.Count, "Counts did not match from cache {0}: {1} != {2}", cacheId, expected.Length, entries.Count); for (int i = 0; i < expected.Length; i++) { string casCacheId = await session.PinToCasAsync(entries[i], CancellationToken.None).SuccessAsync(); string entry = (await GetStreamAsync(entries[i], accessMethod, session)).Success().Stream.AsString(); XAssert.AreEqual(expected[i], entry, "CasEntry {0} mismatch from cache {1}: [{2}] != [{3}]", i, casCacheId, expected[i], entry); } }