Beispiel #1
0
        public void when_converting_to_a_storage_event_it_succeeds()
        {
            var id       = Guid.NewGuid();
            var body     = new OrderCreated("TEST-ORDER");
            var metadata = new TestMetadata {
                Value = "TEST-VALUE"
            };
            var sut = new DocumentDbStorageEvent
            {
                StreamId     = "TEST-STREAM",
                Body         = JObject.FromObject(body),
                BodyType     = "OrderCreated",
                Metadata     = JObject.FromObject(metadata),
                MetadataType = "TestMetadata",
                EventNumber  = 1,
                EventId      = id
            };
            var typeMap = new ConfigurableSerializationTypeMap().RegisterTypes(
                typeof(OrderCreated).GetTypeInfo().Assembly,
                t => t.Namespace != null && t.Namespace.EndsWith("Events"),
                t => t.Name);
            var result = sut.ToStorageEvent(typeMap);

            Assert.That(result.StreamId, Is.EqualTo(sut.StreamId));
            Assert.That(((OrderCreated)result.EventBody).OrderId, Is.EqualTo(body.OrderId));
            Assert.That(((TestMetadata)result.Metadata).Value, Is.EqualTo(metadata.Value));
            Assert.That(result.EventNumber, Is.EqualTo(sut.EventNumber));
            Assert.That(result.EventId, Is.EqualTo(sut.EventId));
        }
Beispiel #2
0
        public async Task ProcessChangesAsync(ChangeFeedObserverContext context, IReadOnlyList <Document> docs)
        {
            foreach (var doc in docs)
            {
                var @event = DocumentDbStorageEvent.FromDocument(doc).ToStorageEvent(typeMap);

                switch (@event.EventBody)
                {
                case OrderCreated body:
                    await Project(@event, body);

                    break;

                case OrderDispatched e:
                    break;
                }
            }

            Console.WriteLine($"Got {docs.Count} events!");
        }