Пример #1
0
        public void TestFileDoes()
        {
            GridFile fs = new GridFile(db["tests"]);

            fs.Create("exists.txt");
            Assert.IsTrue(fs.Exists("exists.txt"));
        }
Пример #2
0
 public GridFileInfo(Database db, string filename)
 {
     this.db = db;
     this.bucket = "fs";
     this.gridFile = new GridFile(db);
     SetFileDataDefaults(filename);
     if(gridFile.Exists(filename)) this.LoadFileData();
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GridFileInfo"/> class.
 /// </summary>
 /// <param name="db">The db.</param>
 /// <param name="bucket">The bucket.</param>
 /// <param name="filename">The filename.</param>
 public GridFileInfo(IMongoDatabase db, string bucket, string filename)
 {
     this.db = db;
     this.bucket = bucket;
     this.gridFile = new GridFile(db,bucket);
     SetFileDataDefaults(filename);
     if(gridFile.Exists(filename)) this.LoadFileData();
 }
Пример #4
0
 public void TestDelete()
 {
     String filename = "gfi-delete.txt";
     GridFile gf = new GridFile(db["tests"],"gfdelete");
     GridFileInfo gfi = new GridFileInfo(db["tests"],"gfdelete", filename);
     GridFileStream gfs = gfi.Create();  //TODO Expand Test to make sure that chunks for the file got deleted too.
     gfi.Delete();
     Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
 }
Пример #5
0
        public void TestDelete()
        {
            String         filename = "gfi-delete.txt";
            GridFile       gf       = new GridFile(db["tests"], "gfdelete");
            GridFileInfo   gfi      = new GridFileInfo(db["tests"], "gfdelete", filename);
            GridFileStream gfs      = gfi.Create(); //TODO Expand Test to make sure that chunks for the file got deleted too.

            gfi.Delete();
            Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
        }
 public void TestDelete(){
     String filename = "gfi-delete.txt";
     GridFile gf = new GridFile(DB,"gfdelete");
     GridFileInfo gfi = new GridFileInfo(DB,"gfdelete", filename);
     var id = gfi.Id;
     GridFileStream gfs = gfi.Create();  //TODO Expand Test to make sure that chunks for the file got deleted too.
     gfi.Delete();
     Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
     Assert.IsTrue(0 == gf.Chunks.Count(new Document("_id", id)));
 }
 public void TestCreateNonExisting(){
     String filename = "newfile.txt";
     GridFile gf = new GridFile(DB,"gfcreate");
     GridFileInfo gfi = new GridFileInfo(DB,"gfcreate", filename);
     
     Assert.AreEqual(filename, gfi.FileName);
     GridFileStream gfs = gfi.Create();
     Assert.AreEqual(filename, gfi.FileName, "Filename got erased?");
     Assert.IsTrue(gf.Exists(gfi.FileName));
 }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GridFileInfo"/> class.
 /// </summary>
 /// <param name="db">The db.</param>
 /// <param name="filename">The filename.</param>
 public GridFileInfo(MongoDatabase db, string filename)
 {
     this.db       = db;
     this.bucket   = "fs";
     this.gridFile = new GridFile(db);
     SetFileDataDefaults(filename);
     if (gridFile.Exists(filename))
     {
         this.LoadFileData();
     }
 }
 public void TestMoveTo(){
     String filename = "gfi-move.txt";
     String filename2 = "gfi-move.txt2";
     GridFile gf = new GridFile(DB,"gfmove");
     GridFileInfo gfi = new GridFileInfo(DB,"gfmove", filename);
     gfi.Create();
     gfi.MoveTo(filename2);
     Assert.IsFalse(gf.Exists(filename), "File should have been moved.");
     Assert.IsTrue(gf.Exists(filename2), "File wasn't");
     Assert.AreEqual(filename2, gfi.FileName, "Filename wasn't set in GridFileInfo");
 }
Пример #10
0
        public void TestCreateNonExisting()
        {
            String       filename = "newfile.txt";
            GridFile     gf       = new GridFile(DB, "gfcreate");
            GridFileInfo gfi      = new GridFileInfo(DB, "gfcreate", filename);

            Assert.AreEqual(filename, gfi.FileName);
            GridFileStream gfs = gfi.Create();

            Assert.AreEqual(filename, gfi.FileName, "Filename got erased?");
            Assert.IsTrue(gf.Exists(gfi.FileName));
        }
Пример #11
0
        public void TestDelete()
        {
            String         filename = "gfi-delete.txt";
            GridFile       gf       = new GridFile(DB, "gfdelete");
            GridFileInfo   gfi      = new GridFileInfo(DB, "gfdelete", filename);
            var            id       = gfi.Id;
            GridFileStream gfs      = gfi.Create(); //TODO Expand Test to make sure that chunks for the file got deleted too.

            gfi.Delete();
            Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
            Assert.IsTrue(0 == gf.Chunks.Count(new Document("_id", id)));
        }
Пример #12
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));
 }
Пример #13
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.
 }
Пример #14
0
        public void TestMoveTo()
        {
            String       filename  = "gfi-move.txt";
            String       filename2 = "gfi-move.txt2";
            GridFile     gf        = new GridFile(DB, "gfmove");
            GridFileInfo gfi       = new GridFileInfo(DB, "gfmove", filename);

            gfi.Create();
            gfi.MoveTo(filename2);
            Assert.IsFalse(gf.Exists(filename), "File should have been moved.");
            Assert.IsTrue(gf.Exists(filename2), "File wasn't");
            Assert.AreEqual(filename2, gfi.FileName, "Filename wasn't set in GridFileInfo");
        }
Пример #15
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.
        }
Пример #16
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));
        }
Пример #17
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");
 }
Пример #18
0
        public void TestOpenNonExistentFails()
        {
            string       filename = "gfi-opennothere.txt";
            GridFile     gf       = new GridFile(DB, "gfopen");
            GridFileInfo gfi      = new GridFileInfo(DB, "gfopen", filename);
            bool         thrown   = false;

            try{
                GridFileStream gfs = gfi.OpenRead();
            }catch (DirectoryNotFoundException dnfe) {
                Assert.AreEqual(gf.Name + Path.VolumeSeparatorChar + filename, dnfe.Message);
                thrown = true;
            }
            Assert.IsTrue(thrown);
        }
Пример #19
0
 public void TestCreateExisting()
 {
     String filename = "existing.txt";
     GridFile gf = new GridFile(db["tests"],"gfcreate");
     GridFileInfo gfi = new GridFileInfo(db["tests"],"gfcreate", filename);
     GridFileStream gfs = gfi.Create();
     bool thrown = false;
     try{
         gfi = new GridFileInfo(db["tests"],"create", filename);
         gfi.Create();
     }catch(IOException){
         thrown = true;
     }
     Assert.IsTrue(thrown, "Shouldn't be able to create the same file twice.");
 }
Пример #20
0
        public void TestCreateExisting()
        {
            String         filename = "existing.txt";
            GridFile       gf       = new GridFile(db["tests"], "gfcreate");
            GridFileInfo   gfi      = new GridFileInfo(db["tests"], "gfcreate", filename);
            GridFileStream gfs      = gfi.Create();
            bool           thrown   = false;

            try{
                gfi = new GridFileInfo(db["tests"], "create", filename);
                gfi.Create();
            }catch (IOException) {
                thrown = true;
            }
            Assert.IsTrue(thrown, "Shouldn't be able to create the same file twice.");
        }
Пример #21
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");
        }
Пример #22
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");
        }
Пример #23
0
        public void TestFileDoesNotExist()
        {
            GridFile fs = new GridFile(db["tests"]);

            Assert.IsFalse(fs.Exists("non-existent filename"));
        }
Пример #24
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");
        }
Пример #25
0
 public void TestMoveTo()
 {
     String filename = "gfi-move.txt";
     String filename2 = "gfi-move.txt2";
     GridFile gf = new GridFile(db["tests"],"gfmove");
     GridFileInfo gfi = new GridFileInfo(db["tests"],"gfmove", filename);
     gfi.Create();
     gfi.MoveTo(filename2);
     Assert.IsFalse(gf.Exists(filename), "File should have been moved.");
     Assert.IsTrue(gf.Exists(filename2), "File wasn't");
 }
Пример #26
0
 public void TestOpenNonExistentFails()
 {
     string filename = "gfi-opennothere.txt";
     GridFile gf = new GridFile(db["tests"], "gfopen");
     GridFileInfo gfi = new GridFileInfo(db["tests"], "gfopen", filename);
     bool thrown = false;
     try{
         GridFileStream gfs = gfi.OpenRead();
     }catch(DirectoryNotFoundException dnfe){
         Assert.AreEqual(gf.Name + Path.VolumeSeparatorChar + filename, dnfe.Message);
         thrown = true;
     }
     Assert.IsTrue(thrown);
 }
Пример #27
0
 public void Init()
 {
     db.Connect();
     fs = new GridFile(db["tests"], filesystem);
     CleanDB(); //Run here instead of at the end so that the db can be examined after a run.
 }
Пример #28
0
 public void TestFileDoesNotExist()
 {
     GridFile fs = new GridFile(DB);
     Assert.IsFalse(fs.Exists("non-existent filename"));
 }
Пример #29
0
 public void TestFileDoes()
 {
     GridFile fs = new GridFile(DB);
     fs.Create("exists.txt");
     Assert.IsTrue(fs.Exists("exists.txt"));
 }
Пример #30
0
 public override void OnInit()
 {
     fs = new GridFile(DB, filesystem);
 }
Пример #31
0
 public override void OnInit()
 {
     fs = new GridFile(DB, filesystem);
 }
Пример #32
0
 public void Init()
 {
     db.Connect();
     fs = new GridFile(db["tests"], filesystem);
     CleanDB(); //Run here instead of at the end so that the db can be examined after a run.
 }