Esempio n. 1
0
 public void FromBytes_ArgumentErrors()
 {
     Assert.Throws <ArgumentNullException>("filePath", () => EmbeddedText.FromBytes(null, default(ArraySegment <byte>)));
     Assert.Throws <ArgumentException>("filePath", () => EmbeddedText.FromBytes("", default(ArraySegment <byte>)));
     Assert.Throws <ArgumentNullException>("bytes", () => EmbeddedText.FromBytes("path", default(ArraySegment <byte>)));
     Assert.Throws <ArgumentException>("checksumAlgorithm", () => EmbeddedText.FromBytes("path", new ArraySegment <byte>(new byte[0], 0, 0), SourceHashAlgorithm.None));
 }
Esempio n. 2
0
        public void FromBytes_Empty()
        {
            var text = EmbeddedText.FromBytes("pathToEmpty", new ArraySegment <byte>(new byte[0], 0, 0), SourceHashAlgorithm.Sha1);

            Assert.Equal("pathToEmpty", text.FilePath);
            Assert.Equal(text.ChecksumAlgorithm, SourceHashAlgorithm.Sha1);
            AssertEx.Equal(SourceText.CalculateChecksum(new byte[0], 0, 0, SourceHashAlgorithm.Sha1), text.Checksum);
            AssertEx.Equal(new byte[] { 0, 0, 0, 0 }, text.Blob);
        }
Esempio n. 3
0
        public void FromBytes_Large()
        {
            var bytes    = Encoding.Unicode.GetBytes(LargeSource);
            var checksum = SourceText.CalculateChecksum(bytes, 0, bytes.Length, SourceHashAlgorithm.Sha256);
            var text     = EmbeddedText.FromBytes("pathToLarge", new ArraySegment <byte>(bytes, 0, bytes.Length), SourceHashAlgorithm.Sha256);

            Assert.Equal("pathToLarge", text.FilePath);
            Assert.Equal(SourceHashAlgorithm.Sha256, text.ChecksumAlgorithm);
            AssertEx.Equal(checksum, text.Checksum);
            AssertEx.Equal(BitConverter.GetBytes(bytes.Length), text.Blob.Take(4));
            AssertEx.Equal(bytes, Decompress(text.Blob.Skip(4)));
        }
Esempio n. 4
0
        public void FromBytes_Small()
        {
            var bytes    = Encoding.UTF8.GetBytes(SmallSource);
            var checksum = SourceText.CalculateChecksum(bytes, 0, bytes.Length, SourceHashAlgorithm.Sha1);
            var text     = EmbeddedText.FromBytes("pathToSmall", new ArraySegment <byte>(bytes, 0, bytes.Length));

            Assert.Equal("pathToSmall", text.FilePath);
            Assert.Equal(text.ChecksumAlgorithm, SourceHashAlgorithm.Sha1);
            AssertEx.Equal(checksum, text.Checksum);
            AssertEx.Equal(new byte[] { 0, 0, 0, 0 }, text.Blob.Take(4));
            AssertEx.Equal(bytes, text.Blob.Skip(4));
        }