예제 #1
0
        private void DeleteTest(string fileContent, int sizeLimit)
        {
            using (new SystemAccount())
                using (new SizeLimitSwindler(this, sizeLimit))
                {
                    var propertyTypeId = PropertyType.GetByName("Binary").Id;
                    var external       = NeedExternal(BlobStoragePlatform.ExpectedBlobProviderDataType, fileContent, sizeLimit);

                    var testRoot = CreateTestRoot();

                    var file = new File(testRoot)
                    {
                        Name = "File1.file"
                    };
                    file.Binary.SetStream(RepositoryTools.GetStreamFromString(fileContent));
                    file.Save();
                    var fileId = file.Binary.FileId;
                    // memorize blob storage context for further check
                    var ctx = BlobStorage.GetBlobStorageContextAsync(file.Binary.FileId, false,
                                                                     file.VersionId, propertyTypeId, CancellationToken.None).GetAwaiter().GetResult();
                    BlobStoragePlatform.UpdateFileCreationDate(file.Binary.FileId, DateTime.UtcNow.AddDays(-1));

                    // Action #1
                    file.ForceDelete();

                    // Assert #1
                    var dbFile = BlobStoragePlatform.LoadDbFile(fileId);
                    Assert.IsNotNull(dbFile);
                    Assert.AreEqual(false, dbFile.IsDeleted);
                    Assert.IsFalse(IsDeleted(ctx, external));

                    // Action #2
                    BlobStorage.CleanupFilesSetFlagAsync(CancellationToken.None)
                    .GetAwaiter().GetResult();

                    // Assert #2
                    dbFile = BlobStoragePlatform.LoadDbFile(fileId);
                    Assert.IsNotNull(dbFile);
                    Assert.AreEqual(true, dbFile.IsDeleted);
                    Assert.IsFalse(IsDeleted(ctx, external));

                    // Action #3
                    var _ = BlobStorage.CleanupFilesAsync(CancellationToken.None)
                            .GetAwaiter().GetResult();

                    // Assert #3
                    dbFile = BlobStoragePlatform.LoadDbFile(fileId);
                    Assert.IsNull(dbFile);
                    Assert.IsTrue(IsDeleted(ctx, external));
                }
        }
예제 #2
0
 private bool IsDeleted(BlobStorageContext context, bool external)
 {
     return(external
         ? BlobStoragePlatform.GetExternalData(context) == null
         : BlobStoragePlatform.LoadDbFile(context.FileId) == null);
 }