Beispiel #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));
                }
            }
        }
Beispiel #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));
                    }
                }
            }
        }
Beispiel #3
0
        public void EqualsOtherHashType(HashType left, HashType right)
        {
            var h1 = new ContentHash(left, Zeros);
            var h2 = new ContentHash(right, Zeros);

            Assert.False(h1.Equals(h2));
        }
Beispiel #4
0
        public bool Equals(ContentHashWithSizeAndLocations other)
        {
            if (other is null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(Locations.SequenceEqual(other.Locations) && ContentHash.Equals(other.ContentHash) && Size == other.Size);
        }
Beispiel #5
0
 /// <inheritdoc />
 public bool Equals(Selector other)
 {
     return(ContentHash.Equals(other.ContentHash) && ByteArrayComparer.ArraysEqual(Output, other.Output));
 }
Beispiel #6
0
 /// <summary>
 /// Tests if the <paramref name="other" /> fingerprint represents the same hash.
 /// </summary>
 public bool Equals(DirectoryFingerprint other)
 {
     return(m_hash.Equals(other.m_hash));
 }
 /// <summary>
 /// Indicates whether the current object is equal to another object by comparing <see cref="ContentHash"/>
 /// </summary>
 /// <param name="other">An object to compare with this object.</param>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other">other</paramref> parameter; otherwise, false.
 /// </returns>
 public Boolean Equals(LeafNodeDictionaryEntry other)
 {
     return(ContentHash.Equals(other.ContentHash));
 }