Пример #1
0
        public async Task can_upload_document_with_name_greater_than_250_char()
        {
            var    handle       = DocumentHandle.FromString("Pdf_3");
            String longFileName = Path.Combine(
                Path.GetTempPath(),
                "_lfn" + new string('X', 240) + ".pdf");

            if (!File.Exists(longFileName))
            {
                File.Copy(TestConfig.PathToDocumentPdf, longFileName);
            }

            await _documentStoreClient.UploadAsync(longFileName, handle);

            // wait background projection polling
            await UpdateAndWaitAsync().ConfigureAwait(false);

            // check readmodel
            var tenantAccessor = ContainerAccessor.Instance.Resolve <ITenantAccessor>();
            var tenant         = tenantAccessor.GetTenant(new TenantId(TestConfig.Tenant));
            var docReader      = tenant.Container.Resolve <IMongoDbReader <DocumentDescriptorReadModel, DocumentDescriptorId> >();

            var allDocuments = docReader.AllUnsorted.Count();

            Assert.AreEqual(1, allDocuments);
        }
Пример #2
0
        public async Task Should_upload_and_download_original_format()
        {
            await _documentStoreClient.UploadAsync(
                TestConfig.PathToDocumentPdf,
                DocumentHandle.FromString("Pdf_2"),
                new Dictionary <string, object> {
                { "callback", "http://localhost/demo" }
            }
                );

            // waits for storage
            await UpdateAndWaitAsync().ConfigureAwait(false);

            var reader = _documentStoreClient.OpenRead(DocumentHandle.FromString("Pdf_2"));

            using (var downloaded = new MemoryStream())
                using (var uploaded = new MemoryStream())
                {
                    using (var fileStream = File.OpenRead(TestConfig.PathToDocumentPdf))
                    {
                        await fileStream.CopyToAsync(uploaded).ConfigureAwait(false);
                    }
                    await(await reader.OpenStream()).CopyToAsync(downloaded);

                    Assert.IsTrue(CompareMemoryStreams(uploaded, downloaded));
                }
        }
Пример #3
0
        public async Task Should_get_info_without_content()
        {
            var documentHandle = DocumentHandle.FromString("Pdf_2");

            await _documentStoreClient.UploadAsync(
                TestConfig.PathToDocumentPdf,
                documentHandle
                );

            // waits for storage
            await UpdateAndWaitAsync().ConfigureAwait(false);

            var format = new DocumentFormat("original");

            var options = new OpenOptions()
            {
                FileName    = "pluto.pdf",
                SkipContent = true
            };

            var reader = _documentStoreClient.OpenRead(documentHandle, format, options);

            using (var downloaded = new MemoryStream())
            {
                await(await reader.OpenStream()).CopyToAsync(downloaded);
                Assert.AreEqual(0, downloaded.Length);
                Assert.AreEqual(72768, reader.ContentLength);
            }
        }
Пример #4
0
        public async Task Should_download_with_range_header()
        {
            var documentHandle = DocumentHandle.FromString("Pdf_2");

            await _documentStoreClient.UploadAsync(
                TestConfig.PathToDocumentPdf,
                documentHandle
                );

            // waits for storage
            await UpdateAndWaitAsync().ConfigureAwait(false);

            var format = new DocumentFormat("original");

            var options = new OpenOptions()
            {
                FileName  = "pluto.pdf",
                RangeFrom = 0,
                RangeTo   = 199
            };

            var reader = _documentStoreClient.OpenRead(documentHandle, format, options);

            using (var downloaded = new MemoryStream())
            {
                await(await reader.OpenStream()).CopyToAsync(downloaded);

                Assert.AreEqual(200, downloaded.Length, "Wrong range support");
                Assert.AreEqual(200, reader.ContentLength);
                Assert.AreEqual("bytes 0-199/72768", reader.ReponseHeaders[HttpResponseHeader.ContentRange]);
            }

            //load without rangeto
            options = new OpenOptions()
            {
                FileName  = "pluto.pdf",
                RangeFrom = 200
            };

            reader = _documentStoreClient.OpenRead(documentHandle, format, options);
            using (var downloaded = new MemoryStream())
            {
                await(await reader.OpenStream()).CopyToAsync(downloaded);
                Assert.AreEqual(72768 - 200, downloaded.Length, "Wrong range support");
                Assert.AreEqual(72768 - 200, reader.ContentLength);
                Assert.AreEqual("bytes 200-72767/72768", reader.ReponseHeaders[HttpResponseHeader.ContentRange]);
            }
        }
Пример #5
0
        public async Task Should_upload_with_a_stream()
        {
            var handle = DocumentHandle.FromString("Pdf_4");

            using (var stream = File.OpenRead(TestConfig.PathToDocumentPdf))
            {
                var response = await _documentStoreClient.UploadAsync(
                    "demo.pdf",
                    handle,
                    stream
                    );

                Assert.AreEqual("8fe8386418f85ef4ee8ef1f3f1117928", response.Hash);
                Assert.AreEqual("md5", response.HashType);
                Assert.AreEqual("http://localhost:5123/tests/documents/pdf_4", response.Uri);
            }
        }
Пример #6
0
        public async Task Should_upload_file_with_custom_data()
        {
            var response = await _documentStoreClient.UploadAsync(
                TestConfig.PathToDocumentPdf,
                DocumentHandle.FromString("Pdf_1"),
                new Dictionary <string, object> {
                { "callback", "http://localhost/demo" }
            }
                );

            Assert.AreEqual("8fe8386418f85ef4ee8ef1f3f1117928", response.Hash);
            Assert.AreEqual("md5", response.HashType);
            Assert.AreEqual("http://localhost:5123/tests/documents/pdf_1", response.Uri);
            // wait background projection polling
            await UpdateAndWaitAsync().ConfigureAwait(false);

            var customData = await _documentStoreClient.GetCustomDataAsync(DocumentHandle.FromString("Pdf_1"));

            Assert.NotNull(customData);
            Assert.IsTrue(customData.ContainsKey("callback"));
            Assert.AreEqual("http://localhost/demo", customData["callback"]);
        }
Пример #7
0
        public async Task should_upload_get_metadata_and_delete_a_document()
        {
            var handle = DocumentHandle.FromString("Pdf_3");

            await _documentStoreClient.UploadAsync(
                TestConfig.PathToDocumentPdf,
                handle,
                new Dictionary <string, object> {
                { "callback", "http://localhost/demo" }
            }
                );

            // wait background projection polling
            await UpdateAndWaitAsync().ConfigureAwait(false);

            var data = await _documentStoreClient.GetCustomDataAsync(handle);

            await _documentStoreClient.DeleteAsync(handle);

            await UpdateAndWaitAsync().ConfigureAwait(false);

            var ex = Assert.ThrowsAsync <HttpRequestException>(async() =>
            {
                await _documentStoreClient.GetCustomDataAsync(handle).ConfigureAwait(false);
            });

            Assert.IsTrue(ex.Message.Contains("404"));

            // check readmodel
            var tenantAccessor = ContainerAccessor.Instance.Resolve <ITenantAccessor>();
            var tenant         = tenantAccessor.GetTenant(new TenantId(TestConfig.Tenant));
            var docReader      = tenant.Container.Resolve <IMongoDbReader <DocumentDescriptorReadModel, DocumentDescriptorId> >();

            var allDocuments = docReader.AllUnsorted.Count();

            Assert.AreEqual(0, allDocuments);
        }
Пример #8
0
        public async Task upload_copy_handle_then_delete_original_handle()
        {
            var handle       = DocumentHandle.FromString("PdfHandleToCopy");
            var copiedHandle = DocumentHandle.FromString("PdfHandleCopied");

            await _documentStoreClient.UploadAsync(
                TestConfig.PathToDocumentPdf,
                handle,
                new Dictionary <string, object> {
                { "callback", "http://localhost/demo" }
            }
                );

            // wait background projection polling
            await UpdateAndWaitAsync().ConfigureAwait(false);

            await _documentStoreClient.CopyHandleAsync(handle, copiedHandle);

            await UpdateAndWaitAsync().ConfigureAwait(false);

            await _documentStoreClient.DeleteAsync(handle);

            await UpdateAndWaitAsync().ConfigureAwait(false);

            // check readmodel
            var tenantAccessor = ContainerAccessor.Instance.Resolve <ITenantAccessor>();
            var tenant         = tenantAccessor.GetTenant(new TenantId(TestConfig.Tenant));
            var docReader      = tenant.Container.Resolve <IMongoDbReader <DocumentDescriptorReadModel, DocumentDescriptorId> >();

            var allDocuments = docReader.AllUnsorted;

            Assert.AreEqual(1, allDocuments.Count());
            var singleDoc = docReader.AllUnsorted.Single();

            Assert.That(singleDoc.Documents.Select(h => h.ToString()), Is.EquivalentTo(new[] { copiedHandle.ToString() }));
        }