private void InternalMoveFile(string fromVirtualPath, string destinationVirtualPath) { MongoGridFS mongoGridFs = GetGridFS(); string fixedDestinationPath = FixPath(destinationVirtualPath); mongoGridFs.MoveTo(FixPath(fromVirtualPath), fixedDestinationPath); MongoGridFSFileInfo fileInfo = mongoGridFs.FindOne(fixedDestinationPath); mongoGridFs.SetMetadata(fileInfo, CreateMetadata(fixedDestinationPath, fileInfo.Metadata["is_directory"] == new BsonBoolean(true))); }
public void MoveToTest() { gridFS.Delete(Query.Null); Assert.AreEqual(0, gridFS.Chunks.Count()); Assert.AreEqual(0, gridFS.Files.Count()); using (var uploadStream = new MemoryStream(ContentBytes)) { var fileInfo = gridFS.Upload(uploadStream, UploadFileName); Assert.AreEqual(1, gridFS.Chunks.Count()); Assert.AreEqual(1, gridFS.Files.Count()); gridFS.MoveTo(UploadFileName, UploadFileName2); Assert.AreEqual(1, gridFS.Chunks.Count()); Assert.AreEqual(1, gridFS.Files.Count()); var movedInfo = gridFS.FindOne(UploadFileName2); Assert.AreEqual(UploadFileName2, movedInfo.Name); Assert.AreEqual(fileInfo.Id, movedInfo.Id); } }
public void TestMoveTo() { _gridFS.Delete(Query.Null); Assert.AreEqual(0, _gridFS.Chunks.Count()); Assert.AreEqual(0, _gridFS.Files.Count()); var contents = "Hello World"; var bytes = Encoding.UTF8.GetBytes(contents); var uploadStream = new MemoryStream(bytes); var fileInfo = _gridFS.Upload(uploadStream, "HelloWorld.txt"); Assert.AreEqual(1, _gridFS.Chunks.Count()); Assert.AreEqual(1, _gridFS.Files.Count()); _gridFS.MoveTo("HelloWorld.txt", "HelloWorld2.txt"); Assert.AreEqual(1, _gridFS.Chunks.Count()); Assert.AreEqual(1, _gridFS.Files.Count()); var movedInfo = _gridFS.FindOne("HelloWorld2.txt"); Assert.AreEqual("HelloWorld2.txt", movedInfo.Name); Assert.AreEqual(fileInfo.Id, movedInfo.Id); }