public void request_for_missing_format_should_404() { // arrange var info = new DocumentHandleInfo( new DocumentHandle("doc"), new FileNameWithExtension("a.file") ); var format = new DocumentFormat("missing"); var doc = new DocumentDescriptorReadModel( 1L, new DocumentDescriptorId(1), new BlobId("file_1") ); SetupDocumentHandle(info, doc.Id); SetupDocumentModel(doc); // act var response = Controller.GetFormat(_tenantId, info.Handle, format).Result; // assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); Assert.AreEqual("Document doc doesn't have format missing", response.GetError().Message); }
public void should_download_original_file() { // arrange var info = new DocumentHandleInfo( new DocumentHandle("doc"), new FileNameWithExtension("\"A document.docx\"") ); var format = new DocumentFormat("original"); var blobId = new BlobId("file_1"); var doc = new DocumentDescriptorReadModel( 1L, new DocumentDescriptorId(1), blobId); SetupDocumentHandle(info, doc.Id); SetupDocumentModel(doc); BlobStore .GetDescriptor(blobId) .Returns(i => new FsBlobDescriptor(blobId, TestConfig.PathToWordDocument)); // act using (var response = Controller.GetFormat(_tenantId, info.Handle, format)) { // assert response.EnsureSuccessStatusCode(); Assert.AreEqual("\"A document.docx\"", response.Content.Headers.ContentDisposition.FileName); } }
public void should_download_pdf_format() { // arrange var info = new DocumentHandleInfo( new DocumentHandle("doc"), new FileNameWithExtension("a.file") ); var format = new DocumentFormat("pdf"); var pdfBlobId = new BlobId("pdf"); var doc = new DocumentDescriptorReadModel( 1L, new DocumentDescriptorId(1), new BlobId("file_1")); doc.AddFormat(new PipelineId("abc"), format, pdfBlobId); SetupDocumentHandle(info, doc.Id); SetupDocumentModel(doc); BlobStore.GetDescriptor(pdfBlobId).Returns(i => new FsBlobDescriptor(pdfBlobId, TestConfig.PathToDocumentPdf)); // act using (var response = Controller.GetFormat(_tenantId, info.Handle, format)) { // assert response.EnsureSuccessStatusCode(); Assert.AreEqual("application/pdf", response.Content.Headers.ContentType.MediaType); } }
public void request_for_missing_format_should_404() { // arrange var info = new DocumentHandleInfo( new DocumentHandle("doc"), new FileNameWithExtension("a.file") ); var format = new DocumentFormat("missing"); var doc = new DocumentDescriptorReadModel( 1L, new DocumentDescriptorId(1), new BlobId("file_1") ); SetupDocumentHandle(info, doc.Id); SetupDocumentModel(doc); // act var response = Controller.GetFormat(_tenantId, info.Handle, format); // assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); Assert.AreEqual("Document doc doesn't have format missing", response.GetError().Message); }
public void when_file_is_not_found_should_return_404() { // arrange var info = new DocumentHandleInfo( new DocumentHandle("doc"), new FileNameWithExtension("a.file") ); var format = new DocumentFormat("original"); var blobId = new BlobId("file_1"); var doc = new DocumentDescriptorReadModel( 1L, new DocumentDescriptorId(1), blobId); SetupDocumentHandle(info, doc.Id); SetupDocumentModel(doc); BlobStore.GetDescriptor(blobId).Returns(i => null); // act var response = Controller.GetFormat(_tenantId, info.Handle, format); // assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); Assert.AreEqual("File file_1 not found", response.GetError().Message); }
public void On(DocumentDescriptorInitialized e) { var longCheckpoint = e.CheckpointToken; var document = new DocumentDescriptorReadModel(longCheckpoint, (DocumentDescriptorId)e.AggregateId, e.BlobId) { Hash = e.Hash }; _documents.Insert(e, document); }
public void verify_format_updated() { SetHandleToReturn(); var docRm = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("file_1")); docRm.AddHandle(new DocumentHandle("rev_1")); docRm.Created = true; rmDocuments.Add(docRm); CreateSut(); var evt = new DocumentLinked(new DocumentHandle("rev_1"), new DocumentDescriptorId(1), new DocumentDescriptorId(2), new FileNameWithExtension("test.txt")); _sut.Handle(evt, false); //Handle is linked to document. var evtFormat = new FormatAddedToDocumentDescriptor(new DocumentFormat("blah"), new BlobId("test.1"), new PipelineId("tika")); evtFormat.AssignIdForTest(new DocumentDescriptorId(1)); _sut.Handle(evtFormat, false); //format is linked to document. var evtFormatUpdated = new DocumentFormatHasBeenUpdated(new DocumentFormat("blah"), new BlobId("test.2"), new PipelineId("tika")); evtFormatUpdated.AssignIdForTest(new DocumentDescriptorId(1)); _sut.Handle(evtFormatUpdated, false); //format is linked to document. Assert.That(rmStream, Has.Count.EqualTo(3)); Assert.That(rmStream[0].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[0].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[0].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("original")); Assert.That(rmStream[0].Filename.FileName, Is.EqualTo("test")); Assert.That(rmStream[0].Filename.Extension, Is.EqualTo("txt")); Assert.That(rmStream[0].FormatInfo.BlobId, Is.EqualTo(new BlobId("file_1"))); Assert.That(rmStream[0].DocumentDescriptorId, Is.EqualTo(new DocumentDescriptorId(1))); Assert.That(rmStream[1].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[1].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[1].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("blah")); Assert.That(rmStream[1].FormatInfo.BlobId.ToString(), Is.EqualTo("test.1")); Assert.That(rmStream[1].FormatInfo.PipelineId.ToString(), Is.EqualTo("tika")); Assert.That(rmStream[1].Filename.FileName, Is.EqualTo("test")); //expectation returns always the same handle Assert.That(rmStream[1].Filename.Extension, Is.EqualTo("txt")); Assert.That(rmStream[1].DocumentDescriptorId, Is.EqualTo(new DocumentDescriptorId(1))); Assert.That(rmStream[2].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentFormatUpdated)); Assert.That(rmStream[2].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[2].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("blah")); Assert.That(rmStream[2].FormatInfo.BlobId.ToString(), Is.EqualTo("test.2")); Assert.That(rmStream[2].FormatInfo.PipelineId.ToString(), Is.EqualTo("tika")); Assert.That(rmStream[2].Filename.FileName, Is.EqualTo("test")); //expectation returns always the same handle Assert.That(rmStream[2].Filename.Extension, Is.EqualTo("txt")); Assert.That(rmStream[2].DocumentDescriptorId, Is.EqualTo(new DocumentDescriptorId(1))); }
public void verify_stream_events_have_custom_handle_data() { SetHandleToReturn(); var docRm = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("file_1")); docRm.Created = true; docRm.AddHandle(new DocumentHandle("rev_1")); rmDocuments.Add(docRm); CreateSut(); var evt = new DocumentLinked(new DocumentHandle("rev_1"), new DocumentDescriptorId(1), new DocumentDescriptorId(2), new FileNameWithExtension("test.txt")); _sut.Handle(evt, false); //Handle is linked to document. Assert.That(rmStream, Has.Count.EqualTo(1)); Assert.That(rmStream[0].DocumentCustomData, Is.EqualTo(handle.CustomData)); }
public void verify_pipeline_id_is_original_when_pipeline_is_null() { SetHandleToReturn(); var docRm = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("file_1")); docRm.AddHandle(new DocumentHandle("rev_1")); docRm.Created = true; rmDocuments.Add(docRm); CreateSut(); var evt = new DocumentLinked( new DocumentHandle("rev_1"), new DocumentDescriptorId(1), new DocumentDescriptorId(2), new FileNameWithExtension("test.txt")); _sut.Handle(evt, false); //Handle is linked to document. Assert.That(rmStream, Has.Count.EqualTo(1)); Assert.That(rmStream[0].FormatInfo.PipelineId, Is.EqualTo(new PipelineId("original"))); }
public void verify_stream_events_on_attachment() { SetHandleToReturn(); var docRm = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("file_1")); var rev1 = new DocumentHandle("rev_1"); docRm.AddHandle(rev1); rmDocuments.Add(docRm); var attachHandle = new DocumentHandle("rev_2"); var docRmAttach = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("file_2")); docRmAttach.AddHandle(attachHandle); rmDocuments.Add(docRmAttach); CreateSut(); var evt = new DocumentDescriptorHasNewAttachment(attachHandle, "path.txt").AssignIdForTest(new DocumentId(1)); _sut.Handle(evt, false); //Handle is linked to document. Assert.That(rmStream, Has.Count.EqualTo(1)); Assert.That(rmStream[0].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewAttachment)); Assert.That(rmStream[0].EventData[StreamReadModelEventDataKeys.ChildHandle], Is.EqualTo(attachHandle)); }
public void verify_handle_linked_to_document_with_formats() { SetHandleToReturn(); IBlobDescriptor stub = Substitute.For <IBlobDescriptor>(); stub.FileNameWithExtension.Returns(new FileNameWithExtension("test.txt")); _blobStore.GetDescriptor(Arg.Any <BlobId>()).Returns(stub); var docRm = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("file_1")); docRm.AddFormat(new PipelineId("tika"), new DocumentFormat("blah"), new BlobId("pdf")); docRm.AddFormat(new PipelineId("test"), new DocumentFormat("blah blah"), new BlobId("test")); docRm.Created = true; rmDocuments.Add(docRm); CreateSut(); var evt = new DocumentLinked(new DocumentHandle("rev_1"), new DocumentDescriptorId(1), new DocumentDescriptorId(2), new FileNameWithExtension("test.txt")); _sut.Handle(evt, false); //I'm expecting new format added to handle Assert.That(rmStream, Has.Count.EqualTo(3)); Assert.That(rmStream[0].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[0].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[0].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("original")); Assert.That(rmStream[0].Filename.FileName, Is.EqualTo("test")); Assert.That(rmStream[0].Filename.Extension, Is.EqualTo("txt")); Assert.That(rmStream[1].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[1].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[1].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("blah")); Assert.That(rmStream[1].Filename.FileName, Is.EqualTo("test")); Assert.That(rmStream[1].Filename.Extension, Is.EqualTo("txt")); Assert.That(rmStream[2].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[2].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[2].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("blah blah")); Assert.That(rmStream[2].Filename.FileName, Is.EqualTo("test")); Assert.That(rmStream[2].Filename.Extension, Is.EqualTo("txt")); }
public void should_download_pdf_format() { // arrange var info = new DocumentHandleInfo( new DocumentHandle("doc"), new FileNameWithExtension("a.file") ); var format = new DocumentFormat("pdf"); var pdfBlobId = new BlobId("pdf"); var doc = new DocumentDescriptorReadModel( 1L, new DocumentDescriptorId(1), new BlobId("file_1")); doc.AddFormat(new PipelineId("abc"), format, pdfBlobId); SetupDocumentHandle(info, doc.Id); SetupDocumentModel(doc); BlobStore.GetDescriptor(pdfBlobId).Returns(i => new FsBlobDescriptor(pdfBlobId, TestConfig.PathToDocumentPdf)); // act using (var response = Controller.GetFormat(_tenantId, info.Handle, format).Result) { // assert response.EnsureSuccessStatusCode(); Assert.AreEqual("application/pdf", response.Content.Headers.ContentType.MediaType); } }
public void should_download_original_file() { // arrange var info = new DocumentHandleInfo( new DocumentHandle("doc"), new FileNameWithExtension("\"A document.docx\"") ); var format = new DocumentFormat("original"); var blobId = new BlobId("file_1"); var doc = new DocumentDescriptorReadModel( 1L, new DocumentDescriptorId(1), blobId); SetupDocumentHandle(info, doc.Id); SetupDocumentModel(doc); BlobStore .GetDescriptor(blobId) .Returns(i => new FsBlobDescriptor(blobId, TestConfig.PathToWordDocument)); // act using (var response = Controller.GetFormat(_tenantId, info.Handle, format).Result) { // assert response.EnsureSuccessStatusCode(); Assert.AreEqual("\"A document.docx\"", response.Content.Headers.ContentDisposition.FileName); } }
public void verify_handle_linked_to_document_with_formats() { SetHandleToReturn(); IBlobDescriptor stub = Substitute.For<IBlobDescriptor>(); stub.FileNameWithExtension.Returns(new FileNameWithExtension("test.txt")); _blobStore.GetDescriptor(Arg.Any<BlobId>()).Returns(stub); var docRm = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("file_1")); docRm.AddFormat(new PipelineId("tika"), new DocumentFormat("blah"), new BlobId("pdf")); docRm.AddFormat(new PipelineId("test"), new DocumentFormat("blah blah"), new BlobId("test")); docRm.Created = true; rmDocuments.Add(docRm); CreateSut(); var evt = new DocumentLinked(new DocumentHandle("rev_1"), new DocumentDescriptorId(1), new DocumentDescriptorId(2), new FileNameWithExtension("test.txt")); _sut.Handle(evt, false); //I'm expecting new format added to handle Assert.That(rmStream, Has.Count.EqualTo(3)); Assert.That(rmStream[0].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[0].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[0].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("original")); Assert.That(rmStream[0].Filename.FileName, Is.EqualTo("test")); Assert.That(rmStream[0].Filename.Extension, Is.EqualTo("txt")); Assert.That(rmStream[1].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[1].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[1].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("blah")); Assert.That(rmStream[1].Filename.FileName, Is.EqualTo("test")); Assert.That(rmStream[1].Filename.Extension, Is.EqualTo("txt")); Assert.That(rmStream[2].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[2].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[2].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("blah blah")); Assert.That(rmStream[2].Filename.FileName, Is.EqualTo("test")); Assert.That(rmStream[2].Filename.Extension, Is.EqualTo("txt")); }
protected void SetupDocumentModel(DocumentDescriptorReadModel doc) { this.DocumentReader.FindOneById(doc.Id).Returns(info => doc); }
public void verify_stream_events_have_documentId() { SetHandleToReturn(); var docRm = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("blob_test")); docRm.Created = true; docRm.AddHandle(new DocumentHandle("rev_1")); rmDocuments.Add(docRm); CreateSut(); var evt = new DocumentLinked(new DocumentHandle("rev_1"), new DocumentDescriptorId(1), new DocumentDescriptorId(2), new FileNameWithExtension("test.txt")); _sut.Handle(evt, false); //Handle is linked to document. Assert.That(rmStream, Has.Count.EqualTo(1)); Assert.That(rmStream[0].DocumentDescriptorId, Is.EqualTo(new DocumentDescriptorId(1))); }
public void when_file_is_not_found_should_return_404() { // arrange var info = new DocumentHandleInfo( new DocumentHandle("doc"), new FileNameWithExtension("a.file") ); var format = new DocumentFormat("original"); var blobId = new BlobId("file_1"); var doc = new DocumentDescriptorReadModel( 1L, new DocumentDescriptorId(1), blobId); SetupDocumentHandle(info, doc.Id); SetupDocumentModel(doc); BlobStore.GetDescriptor(blobId).Returns(i => null); // act var response = Controller.GetFormat(_tenantId, info.Handle, format).Result; // assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); Assert.AreEqual("File file_1 not found", response.GetError().Message); }