void When(DocumentLinked e)
 {
     Link(e.DocumentId);
 }
 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 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_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)));
        }