示例#1
0
        private async Task TestSuccessfulPutStreamAndGet(IContentStoreInternal store, byte[] content)
        {
            ContentHash actualContentHash = content.CalculateHash(ContentHashType);

            using (var contentStream = new MemoryStream(content))
            {
                var context = new Context(Logger);
                var result  = await store.PutStreamAsync(context, contentStream, actualContentHash);

                ContentHash hashFromPut = result.ContentHash;
                long        sizeFromPut = result.ContentSize;

                Assert.True(actualContentHash.Equals(hashFromPut));
                Assert.Equal(content.Length, sizeFromPut);

                // Get the content from the store
                using (var pinContext = store.CreatePinContext())
                {
                    var r2 = await store.PinAsync(context, hashFromPut, pinContext);

                    r2.ShouldBeSuccess();
                    var r3 = await store.OpenStreamAsync(context, hashFromPut);

                    r3.ShouldBeSuccess();
                    byte[] bytes = await r3.Stream.GetBytes();

                    Assert.True(content.SequenceEqual(bytes));
                }
            }
        }
示例#2
0
        private async Task TestSuccessfulPutAbsolutePathAndGet(IContentStoreInternal store, byte[] content, FileRealizationMode ingressModes)
        {
            using (var tempDirectory = new DisposableDirectory(FileSystem))
            {
                AbsolutePath pathToFile = CreateRandomFile(tempDirectory.Path, content);

                using (var contentStream = new MemoryStream(content))
                {
                    ContentHash actualContentHash = await contentStream.HasLength().CalculateHashAsync(ContentHashType);

                    var context = new Context(Logger);
                    var result  = await store.PutFileAsync(context, pathToFile, ingressModes, ContentHashType);

                    ContentHash hashFromPut = result.ContentHash;
                    long        sizeFromPut = result.ContentSize;

                    Assert.True(actualContentHash.Equals(hashFromPut));
                    Assert.Equal(content.Length, sizeFromPut);

                    // Get the content from the store
                    using (var pinContext = store.CreatePinContext())
                    {
                        var r2 = await store.PinAsync(context, hashFromPut, pinContext);

                        r2.ShouldBeSuccess();
                        var r3 = await store.OpenStreamAsync(context, hashFromPut);

                        var bytes = await r3.Stream.GetBytes();

                        Assert.True(content.SequenceEqual(bytes));
                    }
                }
            }
        }
示例#3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ReadOnlyFileSystemContentSession" /> class.
 /// </summary>
 public ReadOnlyFileSystemContentSession(string name, IContentStoreInternal store, ImplicitPin implicitPin)
     : base(name)
 {
     Store        = store;
     _pinContext  = Store.CreatePinContext();
     _implicitPin = implicitPin;
 }