Esempio n. 1
0
        public void Crc24_OfNullFile_ThrowsArgumentNullException()
        {
            var storageAcces = new Crc24TestStorageAccess();

            StreamUtilities.Initialize(storageAcces);
            Assert.Throws <System.ArgumentNullException>(() => Crc24.OfFile(null));
        }
Esempio n. 2
0
        public void Crc32_OfNullFile_ThrowsArgumentNullException()
        {
            // We use a privately defined type for the storage access to check initialize and remove, which will
            // hopefully guarantee that we use the expected storage during this test.
            var storageAcces = new Crc32TestStorageAccess();

            StreamUtilities.Initialize(storageAcces);
            var ignoreRanges = new[] { new Range <int>(10, 200) };

            Assert.Throws <System.ArgumentNullException>(() => Crc32.OfFile(null));
            Assert.Throws <System.ArgumentNullException>(() => Crc32.OfFile(null, ignoreRanges));
            Assert.Throws <System.ArgumentNullException>(() => Crc32.OfFile(null, replaceFirstByte: true, alternateFirstByte: 0x42));
        }
Esempio n. 3
0
        public void StreamUtilities_InitializeCheckDefaultAndRemoveStorage_Succeeds()
        {
            var storageAcces = new MyPrivateStorageAccess();

            // We use a privately defined type for the storage access to check initialize and remove, which will
            // also guarantee that there is a default storage access at least for the duration of this test.
            Assert.True(StreamUtilities.Initialize(storageAcces));
            Assert.False(StreamUtilities.Initialize(storageAcces));
            Assert.NotNull(StreamUtilities.DefaultStorageAccess);
            Assert.False(StreamUtilities.FileExists(@"~-=</.\/_\/.\>=-~"));
            Assert.True(StreamUtilities.Remove(storageAcces));
            Assert.False(StreamUtilities.Remove(storageAcces));
        }
Esempio n. 4
0
        public void Crc32_OfFileWithAlternateFirstByte_IsCorrect()
        {
            // We use a privately defined type for the storage access to check initialize and remove, which will
            // hopefully guarantee that we use the expected storage during this test.
            var storageAcces = new Crc32TestStorageAccess();
            var testFileName = "~/Crc32_OfFileWithAlternateFirstByte_IsCorrect.dat";

            StreamUtilities.Initialize(storageAcces);
            using (var fileStream = StreamUtilities.OpenFileStream(testFileName))
            {
                var testData = new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
                fileStream.Write(testData, 0, testData.Length);
                var crc32 = Crc32.OfFile(testFileName, replaceFirstByte: true, alternateFirstByte: 0x42);
                Assert.Equal(0x066F5C62u, crc32);
            }
        }
Esempio n. 5
0
        private static T InitializeCore(Type typeForLocatingResources, string resourcePath, IEnumerable <string> additionalResourcePaths)
        {
            var storageAccess = new T();

            storageAccess._self = storageAccess;
            StreamUtilities.Initialize(storageAccess);
            storageAccess.AddCachedResource(resourcePath, resourcePath, typeForLocatingResources);

            if (additionalResourcePaths != null)
            {
                foreach (var additionalResourcePath in additionalResourcePaths)
                {
                    storageAccess.AddCachedResource(additionalResourcePath, additionalResourcePath, typeForLocatingResources);
                }
            }
            return(storageAccess);
        }
Esempio n. 6
0
        public void Crc24_OfFile_IsCorrect()
        {
            // We use a privately defined type for the storage access to check initialize and remove, which will
            // hopefully guarantee that we use the expected storage during this test.
            var storageAcces = new Crc24TestStorageAccess();

            StreamUtilities.Initialize(storageAcces);
            var testFileName = "~/Crc24_OfFile_IsCorrect.dat";

            using (var fileStream = StreamUtilities.OpenFileStream(testFileName))
            {
                var testData = new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
                fileStream.Write(testData, 0, testData.Length);
                var crc24 = Crc24.OfFile(testFileName);
                Assert.Equal(0x004F40DAu, crc24);
            }
        }
Esempio n. 7
0
        public void Crc32_OfFileWithIgnoreRange_IsCorrect()
        {
            // We use a privately defined type for the storage access to check initialize and remove, which will
            // hopefully guarantee that we use the expected storage during this test.
            var storageAcces = new Crc32TestStorageAccess();

            StreamUtilities.Initialize(storageAcces);
            var testFileName = "~/Crc32_OfFileWithIgnoreRange_IsCorrect.dat";

            using (var fileStream = StreamUtilities.OpenFileStream(testFileName))
            {
                var testData = new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
                fileStream.Write(testData, 0, testData.Length);
                var ignoreRanges = new[] { new Range <int>(1, 2) };
                var crc32        = Crc32.OfFile(testFileName, ignoreRanges);
                Assert.Equal(0xB4DA8CCAu, crc32);
            }
        }
Esempio n. 8
0
 public void StreamUtilities_RegisterNull_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => StreamUtilities.Initialize(null));
 }