public void CRUDFilesTest()
        {
            // add 2 files - an attachment and a thumbnail.
            FileUploadObject thumbnailFileObject1 = new FileUploadObject
            {
                Category = "Thumbnail",
                FileName = "206.jpg",
                Stream = LoadFileStream("206.jpg")
            };

            FileUploadObject thumbnailFileObject2 = new FileUploadObject
            {
                Category = "Thumbnail",
                FileName = "GenerateThumbnail4Png.png",
                Stream = LoadFileStream("GenerateThumbnail4Png.png")
            };

            FileUploadObject attachmentFileObject = new FileUploadObject
            {
                Category = "Attachment",
                FileName = "NHibernate.chm",
                Stream = LoadFileStream("NHibernate.chm")
            };

            // save the thumbnail and attachment
            this.fileManagementApi.Save(thumbnailFileObject1);
            this.fileManagementApi.Save(thumbnailFileObject2);
            this.fileManagementApi.Save(attachmentFileObject);

            // to simulate a product id
            Guid productId = Guid.NewGuid();
            this.fileBindingApi.Bind("Thumbnail", productId, thumbnailFileObject1.Id);
            this.fileBindingApi.Bind("Thumbnail", productId, thumbnailFileObject2.Id);
            this.fileBindingApi.Bind("Attachment", productId, attachmentFileObject.Id);

            // load all files associated with the product
            IEnumerable<FileHeadObject> fileHeadObjects = this.fileBindingApi.FindBoundFiles(productId);
            Assert.AreEqual(3, fileHeadObjects.Count());

            // load thumbnails associated with the product
            fileHeadObjects = this.fileBindingApi.FindBoundFiles(productId, "Thumbnail");
            Assert.AreEqual(2, fileHeadObjects.Count());

            // unbind attachments of the product but the attachments still exist.
            this.fileBindingApi.Unbind(productId, "Attachment");
            fileHeadObjects = this.fileBindingApi.FindBoundFiles(productId, "Attachment");
            Assert.AreEqual(0, fileHeadObjects.Count());
            Assert.IsNotNull(this.fileManagementApi.Load(attachmentFileObject.Id));

            // delete all thumbnails of the product
            this.fileBindingApi.DeleteBoundFiles(productId, "Thumbnail");
            fileHeadObjects = this.fileBindingApi.FindBoundFiles(productId, "Thumbnail");
            Assert.AreEqual(0, fileHeadObjects.Count());
            Assert.IsNull(this.fileManagementApi.Load(thumbnailFileObject1.Id));
            Assert.IsNull(this.fileManagementApi.Load(thumbnailFileObject2.Id));

            // finally delete the attachment to clear the temporary data.
            this.fileManagementApi.Delete(attachmentFileObject.Id);
        }
        public void CRUDFilesTest()
        {
            // add 2 files - an attachment and a thumbnail.
            Stream thumbnailFileStream = LoadFileStream("206.jpg");
            long thumbnailFileSize = thumbnailFileStream.Length;
            FileUploadObject thumbnailFileObject = new FileUploadObject
            {
                Category = "Thumbnail",
                FileName = "206.jpg",
                Stream = thumbnailFileStream
            };

            Stream attachmentFileStream = LoadFileStream("NHibernate.chm");
            long attachmentFileSize = attachmentFileStream.Length;
            FileUploadObject attachmentFileObject = new FileUploadObject
            {
                Category = "Attachment",
                FileName = "NHibernate.chm",
                Stream = LoadFileStream("NHibernate.chm")
            };

            // assert on thumbnail
            FileHeadObject thumbnailFileHeader = this.fileManagementApi.Save(thumbnailFileObject);
            Assert.AreEqual(thumbnailFileObject.Id, thumbnailFileHeader.Id);
            Assert.AreEqual("206.jpg", thumbnailFileHeader.FileName);
            Assert.AreEqual("jpg", thumbnailFileHeader.FileExtensionName);
            Assert.AreEqual(thumbnailFileSize, thumbnailFileHeader.BytesCount);
            Assert.AreEqual("Thumbnail", thumbnailFileHeader.Category);
            Assert.AreEqual(1, thumbnailFileHeader.Version);

            // save the attachment
            this.fileManagementApi.Save(attachmentFileObject);

            // delete then load the thunbmail.
            this.fileManagementApi.Delete(thumbnailFileObject.Id);
            Assert.IsNull(this.fileManagementApi.Load(thumbnailFileObject.Id));

            // load the attachment then assert.
            FileHeadObject attachmentFileHeader = this.fileManagementApi.Load(attachmentFileObject.Id);
            Assert.AreEqual(attachmentFileObject.Id, attachmentFileHeader.Id);
            Assert.AreEqual("NHibernate.chm", attachmentFileHeader.FileName);
            Assert.AreEqual("chm", attachmentFileHeader.FileExtensionName);
            Assert.AreEqual(attachmentFileSize, attachmentFileHeader.BytesCount);
            Assert.AreEqual("Attachment", attachmentFileHeader.Category);

            // bulk get files. (the thumbnail is deleted.)
            IEnumerable<FileHeadObject> files = this.fileManagementApi.BulkGet(new[] { thumbnailFileObject.Id, attachmentFileObject.Id });
            Assert.AreEqual(1, files.Count());

            // delete the attachment
            this.fileManagementApi.Delete(attachmentFileObject.Id);
            files = this.fileManagementApi.BulkGet(new[] { thumbnailFileObject.Id, attachmentFileObject.Id });
            Assert.AreEqual(0, files.Count());
        }