コード例 #1
0
        private void BinaryCacheEntityTest(string fileContent, int sizeLimit)
        {
            using (new SystemAccount())
                using (new SizeLimitSwindler(this, sizeLimit))
                {
                    var testRoot = CreateTestRoot();

                    var file = new File(testRoot)
                    {
                        Name = "File1.file"
                    };
                    file.Binary.SetStream(RepositoryTools.GetStreamFromString(fileContent));
                    file.Save();
                    var versionId        = file.VersionId;
                    var binaryPropertyId = file.Binary.Id;
                    var fileId           = file.Binary.FileId;
                    var propertyTypeId   = PropertyType.GetByName("Binary").Id;

                    // action
                    var binaryCacheEntity = BlobStorage.LoadBinaryCacheEntityAsync(
                        file.VersionId, propertyTypeId, CancellationToken.None).GetAwaiter().GetResult();

                    // assert
                    Assert.AreEqual(binaryPropertyId, binaryCacheEntity.BinaryPropertyId);
                    Assert.AreEqual(fileId, binaryCacheEntity.FileId);
                    Assert.AreEqual(fileContent.Length + 3, binaryCacheEntity.Length);

                    Assert.AreEqual(versionId, binaryCacheEntity.Context.VersionId);
                    Assert.AreEqual(propertyTypeId, binaryCacheEntity.Context.PropertyTypeId);
                    Assert.AreEqual(fileId, binaryCacheEntity.Context.FileId);
                    Assert.AreEqual(fileContent.Length + 3, binaryCacheEntity.Context.Length);

                    if (NeedExternal(BlobStoragePlatform.ExpectedBlobProviderDataType, fileContent, sizeLimit))
                    {
                        Assert.IsTrue(binaryCacheEntity.Context.Provider.GetType() == BlobStoragePlatform.ExpectedExternalBlobProviderType);
                        Assert.IsTrue(binaryCacheEntity.Context.BlobProviderData.GetType() == BlobStoragePlatform.ExpectedBlobProviderDataType);
                        Assert.AreEqual(fileContent, GetStringFromBytes(BlobStoragePlatform.GetExternalData(binaryCacheEntity.Context)));
                    }
                    else
                    {
                        Assert.AreEqual(fileContent, GetStringFromBytes(binaryCacheEntity.RawData));
                    }
                }
        }
コード例 #2
0
 private bool IsDeleted(BlobStorageContext context, bool external)
 {
     return(external
         ? BlobStoragePlatform.GetExternalData(context) == null
         : BlobStoragePlatform.LoadDbFile(context.FileId) == null);
 }