Exemple #1
0
        public async Task TryLoadContentWithSomeButNotAllAvailable()
        {
            ContentHash availableHash = await AddContent("Very useful data");

            ContentHash unavailableHash   = HashContent("If only we had this");
            ContentHash alsoAvailableHash = await AddContent("Even more very useful data");

            XAssert.AreNotEqual(availableHash, unavailableHash);
            XAssert.AreNotEqual(availableHash, alsoAvailableHash);
            XAssert.AreNotEqual(alsoAvailableHash, unavailableHash);

            Possible <ContentAvailabilityBatchResult> possiblyLoaded =
                await ContentCache.TryLoadAvailableContentAsync(new List <ContentHash>()
            {
                availableHash,
                unavailableHash,
                alsoAvailableHash
            });

            XAssert.IsTrue(possiblyLoaded.Succeeded);
            ContentAvailabilityBatchResult result = possiblyLoaded.Result;

            XAssert.IsFalse(result.AllContentAvailable);
            XAssert.AreEqual(3, result.Results.Length);

            XAssert.IsTrue(result.Results[0].IsAvailable);
            XAssert.AreEqual(availableHash, result.Results[0].Hash);

            XAssert.IsFalse(result.Results[1].IsAvailable);
            XAssert.AreEqual(unavailableHash, result.Results[1].Hash);

            XAssert.IsTrue(result.Results[2].IsAvailable);
            XAssert.AreEqual(alsoAvailableHash, result.Results[2].Hash);
        }
Exemple #2
0
        public async Task TryLoadExistentContent()
        {
            ContentHash unrelatedHash = await AddContent("Unrelated data");

            ContentHash desiredHash = await AddContent("Very useful data");

            XAssert.AreNotEqual(desiredHash, unrelatedHash);

            Possible <ContentAvailabilityBatchResult> possiblyLoaded =
                await ContentCache.TryLoadAvailableContentAsync(new List <ContentHash>() { desiredHash });

            XAssert.IsTrue(possiblyLoaded.Succeeded);
            ContentAvailabilityBatchResult result = possiblyLoaded.Result;

            XAssert.IsTrue(result.AllContentAvailable);
            XAssert.AreEqual(1, result.Results.Length);
            XAssert.IsTrue(result.Results[0].IsAvailable);
            XAssert.AreEqual(desiredHash, result.Results[0].Hash);
        }