public void On(DocumentLinked e) { _writer.LinkDocument( e.Handle, e.DocumentId, e.CheckpointToken ); }
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 On(DocumentLinked e) { if (IsReplay) { return; } if (e.PreviousDocumentId != null) { _commandBus.Send(new DeleteDocumentDescriptor(e.PreviousDocumentId, e.Handle) .WithDiagnosticTriggeredByInfo(e, string.Format("Handle relinked from {0} to {1}", e.PreviousDocumentId, e.DocumentId)) ); } }
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_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 On(DocumentLinked e) { var doc = _documentDescriptorReadModel.FindOneById(e.DocumentId); if (doc == null) { Logger.InfoFormat("Document {0} is linked to document descriptor {1} that was not found. Probably the document descriptor was de-duplicated.", e.AggregateId, e.DocumentId); return; } if (!doc.Created) { return; //Still not deduplicated. } var handle = _documentWriter.FindOneById(e.Handle); foreach (var format in doc.Formats) { var descriptor = _blobStore.GetDescriptor(format.Value.BlobId); _streamReadModelCollection.Insert(e, new StreamReadModel() { Id = GetNewId(), Handle = e.Handle, Filename = descriptor.FileNameWithExtension, DocumentDescriptorId = e.DocumentId, FormatInfo = new FormatInfo() { BlobId = format.Value.BlobId, DocumentFormat = format.Key, PipelineId = format.Value.PipelineId != PipelineId.Null ? format.Value.PipelineId : new PipelineId("original"), }, EventType = HandleStreamEventTypes.DocumentHasNewFormat, DocumentCustomData = handle.CustomData, }); } }
void When(DocumentLinked e) { Link(e.DocumentId); }