コード例 #1
0
        public void ShouldThrowExceptionOnMaxLimit()
        {
            using (var jarFileWriter = new JarFile(FileAccessMode.Write, jarFiledata, 2))
            {
                jarFileWriter.AddFile(new JarFileItem(header, file1));

                jarFileWriter.AddFile(new JarFileItem(header, file2));

                Assert.Throws <JarFileReachedMaxLimitException>(() => jarFileWriter.AddFile(new JarFileItem(header, file2)));
            }
        }
コード例 #2
0
        public void ShouldAddFiles2()
        {
            using (var jarFileWriter = new JarFile(FileAccessMode.Write, jarFiledata))
            {
                header["FileName"] = file1;
                jarFileWriter.AddFile(new JarFileItem(header, file1));

                header["FileName"] = file2;
                jarFileWriter.AddFile(new JarFileItem(header, file2));
            }

            using (var jarFileReader = new JarFile(FileAccessMode.Read, jarFiledata))
            {
                Assert.AreEqual(2, jarFileReader.FilesCount);
                var jarItem1 = jarFileReader.GetNextFile();

                var jarItem2 = jarFileReader.GetNextFile();

                Assert.AreEqual("TestData1", System.Text.Encoding.UTF8.GetString(jarItem1.Containt));
                Assert.AreEqual("TestData2", System.Text.Encoding.UTF8.GetString(jarItem2.Containt));
            }
        }
コード例 #3
0
        public void ShouldThrowExceptionForInvalidModeOpretion()
        {
            using (var jarFileWriter = new JarFile(FileAccessMode.Write, jarFiledata))
            {
                jarFileWriter.AddFile(new JarFileItem(header, file1));

                Assert.Throws <InvalidOperationException>(() => jarFileWriter.GetNextFile());
            }

            using (var jarFileReader = new JarFile(FileAccessMode.Read, jarFiledata))
            {
                Assert.Throws <InvalidOperationException>(() => jarFileReader.AddFile(new JarFileItem(header, file1)));
            }
        }
コード例 #4
0
        public void ShouldAllowReadConcurrently()
        {
            using (var jarFileWriter = new JarFile(FileAccessMode.Write, jarFiledata))
            {
                header["FileName"] = file1;
                jarFileWriter.AddFile(new JarFileItem(header, file1));
            }

            using (var sourceStream = new FileStream(
                       jarFiledata,
                       FileMode.Open,
                       FileAccess.Read,
                       FileShare.ReadWrite))
            {
                using (var jarFileWriter = new JarFile(FileAccessMode.Write, jarFiledata))
                {
                    header["FileName"] = file2;
                    jarFileWriter.AddFile(new JarFileItem(header, file2));
                }
            }
        }