Create() публичный Метод

public Create ( String filename ) : GridFileStream
filename String
Результат GridFileStream
Пример #1
0
        public void TestFileDoes()
        {
            GridFile fs = new GridFile(db["tests"]);

            fs.Create("exists.txt");
            Assert.IsTrue(fs.Exists("exists.txt"));
        }
Пример #2
0
        public void TestWrite()
        {
            GridFileStream gfs = fs.Create("test.txt");
            Object         id  = gfs.GridFileInfo.Id;

            for (byte b = (byte)0; b < 128; b++)
            {
                gfs.WriteByte(b);
            }
            gfs.Close();

            Assert.AreEqual(1, CountChunks(filesystem, id));
            Document chunk = GrabChunk(id, 0);
            Binary   bin   = (Binary)chunk["data"];

            Assert.AreEqual(127, bin.Bytes[127]);
            Assert.AreEqual(0, bin.Bytes[0]);
        }
Пример #3
0
 public void TestModeCreateNew(){
     Object id;
     string filename = "createnew.txt";
     GridFile gf = new GridFile(DB,"gfcreate");
     using(GridFileStream gfs = gf.Create(filename, FileMode.CreateNew)){
         id = gfs.GridFileInfo.Id;
         TextWriter tw = new StreamWriter(gfs);
         tw.WriteLine("test");
         tw.Close();
     }
     Assert.AreEqual(1, CountChunks("gfcreate", id));
 }
Пример #4
0
 public void TestCopy(){
     GridFile fs = new GridFile(DB, "gfcopy");
     GridFileStream gfs = fs.Create("original.txt");
     gfs.WriteByte(1);
     gfs.Seek(1024 * 256 * 2, SeekOrigin.Begin);
     gfs.WriteByte(2);
     gfs.Close();
     fs.Copy("original.txt", "copy.txt");
     Assert.IsTrue(fs.Exists("original.txt"));
     Assert.IsTrue(fs.Exists("copy.txt"));
     //TODO Assert chunk data is the same too.
 }
Пример #5
0
        public void TestModeCreateNew()
        {
            Object   id;
            string   filename = "createnew.txt";
            GridFile gf       = new GridFile(db["tests"], "gfcreate");

            using (GridFileStream gfs = gf.Create(filename, FileMode.CreateNew)){
                id = gfs.GridFileInfo.Id;
                TextWriter tw = new StreamWriter(gfs);
                tw.WriteLine("test");
                tw.Close();
            }
            Assert.AreEqual(1, CountChunks("gfcreate", id));
        }
Пример #6
0
        public void TestCopy()
        {
            GridFile       fs  = new GridFile(db["tests"], "gfcopy");
            GridFileStream gfs = fs.Create("original.txt");

            gfs.WriteByte(1);
            gfs.Seek(1024 * 256 * 2, SeekOrigin.Begin);
            gfs.WriteByte(2);
            gfs.Close();
            fs.Copy("original.txt", "copy.txt");
            Assert.IsTrue(fs.Exists("original.txt"));
            Assert.IsTrue(fs.Exists("copy.txt"));
            //TODO Assert chunk data is the same too.
        }
Пример #7
0
 public void TestDeleteRemovesChunks(){
     Object id;
     string filename = "deletebyname.txt";
     string fs = "fs";
     GridFile gf = new GridFile(DB,fs);
     using(GridFileStream gfs = gf.Create(filename, FileMode.CreateNew)){
         id = gfs.GridFileInfo.Id;
         TextWriter tw = new StreamWriter(gfs);
         tw.WriteLine("test");
         tw.Close();
     }
     Assert.AreEqual(1, CountChunks(fs, id), "Chunks not found");
     gf.Delete("deletebyname.txt");
     Assert.AreEqual(0, CountChunks(fs, id), "Chunks found");
 }
Пример #8
0
        public void TestDeleteRemovesChunks()
        {
            Object   id;
            string   filename = "deletebyname.txt";
            string   fs       = "fs";
            GridFile gf       = new GridFile(DB, fs);

            using (GridFileStream gfs = gf.Create(filename, FileMode.CreateNew)){
                id = gfs.GridFileInfo.Id;
                TextWriter tw = new StreamWriter(gfs);
                tw.WriteLine("test");
                tw.Close();
            }
            Assert.AreEqual(1, CountChunks(fs, id), "Chunks not found");
            gf.Delete("deletebyname.txt");
            Assert.AreEqual(0, CountChunks(fs, id), "Chunks found");
        }
Пример #9
0
        public void TestOpenReadOnly()
        {
            string         filename = "gfi-open.txt";
            GridFile       gf       = new GridFile(DB, "gfopen");
            GridFileStream gfs      = gf.Create(filename);

            gfs.Close();

            gfs = gf.OpenRead(filename);
            Assert.IsNotNull(gfs);
            bool thrown = false;

            try{
                gfs.Write(new byte[] { 0 }, 0, 1);
            }catch (System.NotSupportedException) {
                thrown = true;
            }catch (Exception ex) {
                Assert.Fail("Wrong exception thrown " + ex.GetType().Name);
            }
            Assert.IsTrue(thrown, "NotSupportedException not thrown");
        }
Пример #10
0
        public void TestOpenReadOnly()
        {
            string filename = "gfi-open.txt";
            GridFile gf = new GridFile(db["tests"], "gfopen");
            GridFileStream gfs = gf.Create(filename);
            gfs.Close();

            gfs = gf.OpenRead(filename);
            Assert.IsNotNull(gfs);
            bool thrown = false;
            try{
                gfs.Write(new byte[]{0},0,1);
            }catch(System.NotSupportedException){
                thrown = true;
            }catch(Exception ex){
                Assert.Fail("Wrong exception thrown " + ex.GetType().Name);
            }
            Assert.IsTrue(thrown, "NotSupportedException not thrown");
        }
Пример #11
0
 public void TestFileDoes()
 {
     GridFile fs = new GridFile(DB);
     fs.Create("exists.txt");
     Assert.IsTrue(fs.Exists("exists.txt"));
 }