예제 #1
0
        private void DeleteBinaryPropertyTest(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 fileId = file.Id;

                    file = Node.Load <File>(fileId);
                    // action
                    file.Binary = null;
                    file.Save();

                    // assert
                    var dbFiles = BlobStoragePlatform.LoadDbFiles(file.VersionId);
                    Assert.AreEqual(0, dbFiles.Length);
                }
        }
예제 #2
0
        private DbFile UpdateByChunksTest(string initialContent, string updatedText, int sizeLimit, int chunkSize)
        {
            using (new SystemAccount())
                using (new SizeLimitSwindler(this, sizeLimit))
                {
                    var testRoot = CreateTestRoot();

                    var file = new File(testRoot)
                    {
                        Name = "File1.file"
                    };
                    file.Binary.SetStream(RepositoryTools.GetStreamFromString(initialContent));
                    file.Save();
                    var fileId = file.Id;

                    var chunks = SplitFile(updatedText, chunkSize, out var fullSize);

                    file = Node.Load <File>(fileId);
                    file.Save(SavingMode.StartMultistepSave);
                    var token = BinaryData.StartChunk(fileId, fullSize);

                    var offset = 0;
                    foreach (var chunk in chunks)
                    {
                        BinaryData.WriteChunk(fileId, token, fullSize, chunk, offset);
                        offset += chunkSize;
                    }

                    BinaryData.CommitChunk(fileId, token, fullSize);

                    file = Node.Load <File>(fileId);
                    file.FinalizeContent();


                    // assert
                    var dbFiles = BlobStoragePlatform.LoadDbFiles(file.VersionId);
                    Assert.AreEqual(1, dbFiles.Length);
                    var dbFile = dbFiles[0];
                    if (NeedExternal(BlobStoragePlatform.ExpectedBlobProviderDataType, updatedText, sizeLimit))
                    {
                        Assert.AreEqual(BlobStoragePlatform.ExpectedExternalBlobProviderType.FullName, dbFile.BlobProvider);
                        Assert.IsNotNull(dbFile.BlobProviderData);
                    }
                    else
                    {
                        Assert.IsNull(dbFile.BlobProvider);
                        Assert.IsNull(dbFile.BlobProviderData);
                    }
                    Assert.AreEqual(false, dbFile.IsDeleted);
                    Assert.AreEqual(false, dbFile.Staging);
                    Assert.AreEqual(0, dbFile.StagingVersionId);
                    Assert.AreEqual(0, dbFile.StagingPropertyTypeId);
                    Assert.AreEqual(fullSize, dbFile.Size);

                    return(dbFile);
                }
        }
예제 #3
0
        private DbFile CreateFileTest(Node testRoot, string fileContent, int sizeLimit)
        {
            using (new SystemAccount())
                using (new SizeLimitSwindler(this, sizeLimit))
                {
                    var file = new File(testRoot)
                    {
                        Name = "File1.file"
                    };
                    file.Binary.SetStream(RepositoryTools.GetStreamFromString(fileContent));

                    // action
                    file.Save();

                    // assert
                    var dbFiles = BlobStoragePlatform.LoadDbFiles(file.VersionId);
                    Assert.AreEqual(1, dbFiles.Length);
                    var dbFile = dbFiles[0];
                    if (NeedExternal(BlobStoragePlatform.ExpectedExternalBlobProviderType, fileContent, sizeLimit))
                    {
                        Assert.AreEqual(BlobStoragePlatform.ExpectedExternalBlobProviderType.FullName, dbFile.BlobProvider);
                        Assert.IsNotNull(dbFile.BlobProviderData);
                    }
                    else
                    {
                        Assert.IsNull(dbFile.BlobProvider);
                        Assert.IsNull(dbFile.BlobProviderData);
                    }
                    Assert.AreEqual(false, dbFile.IsDeleted);
                    Assert.AreEqual(false, dbFile.Staging);
                    Assert.AreEqual(0, dbFile.StagingVersionId);
                    Assert.AreEqual(0, dbFile.StagingPropertyTypeId);
                    Assert.AreEqual(fileContent.Length + 3, dbFile.Size);

                    return(dbFile);
                }
        }
예제 #4
0
        private DbFile[] CopyFileRowTest(string initialContent, string updatedText, int sizeLimit)
        {
            using (new SystemAccount())
                using (new SizeLimitSwindler(this, sizeLimit))
                {
                    var testRoot = CreateTestRoot();
                    var target   = new SystemFolder(testRoot)
                    {
                        Name = "Target"
                    };
                    target.Save();

                    var file = new File(testRoot)
                    {
                        Name = "File1.file"
                    };
                    file.Binary.SetStream(RepositoryTools.GetStreamFromString(initialContent));
                    file.Save();

                    // action
                    file.CopyTo(target);

                    // assert
                    var copy = Node.Load <File>(RepositoryPath.Combine(target.Path, file.Name));
                    Assert.AreNotEqual(file.Id, copy.Id);
                    Assert.AreNotEqual(file.VersionId, copy.VersionId);
                    Assert.AreEqual(file.Binary.FileId, copy.Binary.FileId);

                    // action 2
                    copy.Binary.SetStream(RepositoryTools.GetStreamFromString(updatedText));
                    copy.Save();

                    // assert 2
                    Assert.AreNotEqual(file.Binary.FileId, copy.Binary.FileId);

                    var dbFiles = new DbFile[2];

                    var loadedDbFiles = BlobStoragePlatform.LoadDbFiles(file.VersionId);
                    Assert.AreEqual(1, loadedDbFiles.Length);
                    dbFiles[0] = loadedDbFiles[0];

                    loadedDbFiles = BlobStoragePlatform.LoadDbFiles(copy.VersionId);
                    Assert.AreEqual(1, loadedDbFiles.Length);
                    dbFiles[1] = loadedDbFiles[0];

                    if (NeedExternal(BlobStoragePlatform.ExpectedBlobProviderDataType, initialContent, sizeLimit))
                    {
                        Assert.AreEqual(BlobStoragePlatform.ExpectedExternalBlobProviderType.FullName, dbFiles[0].BlobProvider);
                        Assert.IsNotNull(dbFiles[0].BlobProviderData);
                    }
                    else
                    {
                        Assert.IsNull(dbFiles[0].BlobProvider);
                        Assert.IsNull(dbFiles[0].BlobProviderData);
                    }
                    Assert.AreEqual(false, dbFiles[0].IsDeleted);
                    Assert.AreEqual(false, dbFiles[0].Staging);
                    Assert.AreEqual(0, dbFiles[0].StagingVersionId);
                    Assert.AreEqual(0, dbFiles[0].StagingPropertyTypeId);
                    Assert.AreEqual(initialContent.Length + 3, dbFiles[0].Size);

                    if (NeedExternal(BlobStoragePlatform.ExpectedBlobProviderDataType, updatedText, sizeLimit))
                    {
                        Assert.AreEqual(BlobStoragePlatform.ExpectedExternalBlobProviderType.FullName, dbFiles[1].BlobProvider);
                        Assert.IsNotNull(dbFiles[1].BlobProviderData);
                    }
                    else
                    {
                        Assert.IsNull(dbFiles[1].BlobProvider);
                        Assert.IsNull(dbFiles[1].BlobProviderData);
                    }
                    Assert.AreEqual(false, dbFiles[1].IsDeleted);
                    Assert.AreEqual(false, dbFiles[1].Staging);
                    Assert.AreEqual(0, dbFiles[1].StagingVersionId);
                    Assert.AreEqual(0, dbFiles[1].StagingPropertyTypeId);
                    Assert.AreEqual(updatedText.Length + 3, dbFiles[1].Size);

                    return(dbFiles);
                }
        }
예제 #5
0
        private DbFile UpdateFileTest(Node testRoot, string initialContent, string updatedContent, int sizeLimit)
        {
            using (new SystemAccount())
                using (new SizeLimitSwindler(this, sizeLimit))
                {
                    var file = new File(testRoot)
                    {
                        Name = "File1.file"
                    };
                    file.Binary.SetStream(RepositoryTools.GetStreamFromString(initialContent));
                    file.Save();
                    var fileId             = file.Id;
                    var blobProviderBefore = file.Binary.BlobProvider;
                    var fileRowIdBefore    = file.Binary.FileId;

                    file = Node.Load <File>(fileId);
                    file.Binary.SetStream(RepositoryTools.GetStreamFromString(updatedContent));

                    // action
                    file.Save();

                    // assert
                    var blobProviderAfter = file.Binary.BlobProvider;
                    var fileRowIdAfter    = file.Binary.FileId;
                    // if blob provider before and after is built-in, the existing file row is updated, else re-created.
                    if (blobProviderAfter == null && blobProviderBefore == null)
                    {
                        Assert.AreEqual(fileRowIdBefore, fileRowIdAfter);
                    }
                    else
                    {
                        Assert.AreNotEqual(fileRowIdBefore, fileRowIdAfter);
                    }

                    var dbFiles = BlobStoragePlatform.LoadDbFiles(file.VersionId);
                    Assert.AreEqual(1, dbFiles.Length);
                    var dbFile = dbFiles[0];
                    //Assert.AreNotEqual(initialBlobId, file.Binary.FileId);
                    if (NeedExternal(BlobStoragePlatform.ExpectedBlobProviderDataType, updatedContent, sizeLimit))
                    {
                        Assert.AreEqual(BlobStoragePlatform.ExpectedExternalBlobProviderType.FullName, dbFile.BlobProvider);
                        Assert.IsNotNull(dbFile.BlobProviderData);
                    }
                    else
                    {
                        Assert.IsNull(dbFile.BlobProvider);
                        Assert.IsNull(dbFile.BlobProviderData);
                    }
                    Assert.AreEqual(false, dbFile.IsDeleted);
                    Assert.AreEqual(false, dbFile.Staging);
                    Assert.AreEqual(0, dbFile.StagingVersionId);
                    Assert.AreEqual(0, dbFile.StagingPropertyTypeId);
                    if (updatedContent.Length == 0)
                    {
                        Assert.AreEqual(0, dbFile.Size);
                    }
                    else
                    {
                        Assert.AreEqual(updatedContent.Length + 3, dbFile.Size);
                    }

                    return(dbFile);
                }
        }