Esempio n. 1
0
        public async Task RoundtripSimpleStructure()
        {
            var context = BuildXLContext.CreateInstanceForTesting();
            var cache   = new InMemoryArtifactContentCache(context);

            var originalEntry = new PipCacheDescriptorV2Metadata()
            {
                Id = 123,
                NumberOfWarnings = 456,
                TraceInfo        = "Good job."
            };

            Possible <ContentHash> maybeStored =
                await cache.TrySerializeAndStoreContent(originalEntry);

            XAssert.IsTrue(maybeStored.Succeeded);

            var maybeDeserialized =
                await cache.TryLoadAndDeserializeContent <PipCacheDescriptorV2Metadata>(maybeStored.Result);

            XAssert.IsTrue(maybeDeserialized.Succeeded);

            PipCacheDescriptorV2Metadata roundtripped = maybeDeserialized.Result;

            XAssert.IsNotNull(roundtripped, "Expected content available");

            XAssert.AreEqual(originalEntry.Id, roundtripped.Id);
            XAssert.AreEqual(originalEntry.NumberOfWarnings, roundtripped.NumberOfWarnings);
            XAssert.AreEqual(originalEntry.TraceInfo, roundtripped.TraceInfo);
        }
Esempio n. 2
0
        public async Task DeserializationReturnsNullIfUnavailable()
        {
            var cache = new InMemoryArtifactContentCache();

            ContentHash imaginaryContent = ContentHashingUtilities.HashBytes(Encoding.UTF8.GetBytes("Imagination"));

            var maybeDeserialized =
                await cache.TryLoadAndDeserializeContent <PipCacheDescriptorV2Metadata>(imaginaryContent);

            XAssert.IsTrue(maybeDeserialized.Succeeded);
            XAssert.IsNull(maybeDeserialized.Result, "Should be a miss (cache empty)");
        }