Permalink
Browse files

Fixed GridFS delete operations: now the FileChunk are also removed.

  • Loading branch information...
1 parent 79f0e32 commit 0a714a3715ca8ee0dea8e7d11c2caa8f3a94b286 @emmekappa emmekappa committed Aug 20, 2010
Showing with 25 additions and 1 deletion.
  1. +24 −0 NoRM.Tests/GridFS/GridFileCollectionTests.cs
  2. +1 −1 NoRM/GridFS/GridFileCollection.cs
@@ -125,5 +125,29 @@ public void File_Save_Should_Replace_Old_Content()
Assert.Equal(new byte[] { 3, 2, 1 }, gridFS.FindOne(new { _id = file.Id }).Content.ToArray());
}
}
+
+ [Fact]
+ public void Delete_Should_Remove_FileChunks()
+ {
+ using (var conn = Mongo.Create(TestHelper.ConnectionString()))
+ {
+ var ms = new MemoryStream(50000);
+ for (int i = 0; i < 2000; i++)
+ {
+ ms.Write(BitConverter.GetBytes(i), 0, 4);
+ }
+
+ var gridFS = conn.Database.Files();
+ var file = new GridFile();
+ file.ContentType = "application/unknown";
+ file.FileName = "test.raw";
+ file.Content = ms.ToArray();
+ gridFS.Save(file);
+
+ gridFS.Delete(file.Id);
+
+ Assert.Equal(0, conn.Database.GetCollection<FileChunk>("chunks").GetCollectionStatistics().Count);
+ }
+ }
}
}
@@ -69,7 +69,7 @@ public void Delete(ObjectId IDofFileToDelete)
if (IDofFileToDelete != null)
{
this.FileSummaries.Delete(new { _id = IDofFileToDelete });
- this.FileChunks.Delete(new { _id = IDofFileToDelete });
+ this.FileChunks.Delete(new { files_id = IDofFileToDelete });
}
else
{

0 comments on commit 0a714a3

Please sign in to comment.