sshushliapin/Sitecore.FakeDb

Blobs from FakeDB have different behaviour to SC.

Closed this issue · 3 comments

Assume the following code:

 byte[] buffer = new byte[2048];

var field = item.Fields["Blob"];
var data = field.GetBlobStream();
data.Read(buffer, 0, buffer.Length);
data.Close();

var data1 = field. GetBlobStream();
data1.Read(buffer, 0, buffer.Length);

If you do this against Sitecore then the code succeeds but with fake DB it fails on the data1.Read because the stream is closed. I assume this caused because SC returns a new stream on each call to GetBlobStream but FakeDB returns the same stream.

Correct. The GetBlobStreamCommand doesn't recreate the stream:

    public virtual Stream GetBlobStream(Guid blobId)
    {
      return this.Blobs.ContainsKey(blobId) ? this.Blobs[blobId] : null;
    }

Can you please share your entire test so I could quickly reproduce and then see how best to fix it?

Thanks for reporting this, guys.
Returning a copy of the stream allows to get an open stream every time it's requested. That is exactly what you need, I'll push an update.

Fixed in v1.2.1.