sshushliapin / Sitecore.FakeDb

Unit testing framework for Sitecore.
MIT License
117 stars 36 forks source link

Blobs from FakeDB have different behaviour to SC. #143

Closed mikeedwards83 closed 8 years ago

mikeedwards83 commented 8 years ago

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.

pveller commented 8 years ago

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?

sshushliapin commented 8 years ago

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.

sshushliapin commented 8 years ago

Fixed in v1.2.1.