Ejemplo n.º 1
0
        public override void Events_that_cannot_be_deserialized_due_to_unknown_member_do_not_cause_sourcing_to_fail()
        {
            Guid orderId   = Guid.NewGuid();
            var  goodEvent = new Order.CustomerInfoChanged
            {
                CustomerName   = "Waylon Jennings",
                AggregateId    = orderId,
                SequenceNumber = 1
            }.ToStorableEvent();
            var badEvent = new StorableEvent
            {
                StreamName     = goodEvent.StreamName,
                Type           = goodEvent.Type,
                AggregateId    = goodEvent.AggregateId,
                SequenceNumber = 2,
                Body           = new
                {
                    CustomerName = "Willie Nelson",
                    HairColor    = "red"
                }.ToJson(),
                UtcTime = DateTime.UtcNow
            };

            SaveEventsDirectly(goodEvent, badEvent);

            var repository = CreateRepository <Order>();

            var order = repository.GetLatest(orderId);

            order.CustomerName.Should().Be("Willie Nelson");
        }
        public override async Task Events_that_cannot_be_deserialized_due_to_unknown_member_do_not_cause_sourcing_to_fail()
        {
            var orderId   = Guid.NewGuid();
            var goodEvent = new Order.CustomerInfoChanged
            {
                CustomerName   = "Waylon Jennings",
                AggregateId    = orderId,
                SequenceNumber = 1
            }.ToStoredEvent();
            var badEvent = new InMemoryStoredEvent
            {
                Type           = goodEvent.Type,
                AggregateId    = orderId.ToString(),
                SequenceNumber = 2,
                StreamName     = "Order",
                Body           = new
                {
                    CustomerName = "Willie Nelson",
                    HairColor    = "red"
                }.ToJson(),
                Timestamp = DateTimeOffset.UtcNow
            };

            await SaveEventsDirectly(goodEvent, badEvent);

            var repository = CreateRepository <Order>();

            var order = await repository.GetLatest(orderId);

            order.CustomerName.Should().Be("Willie Nelson");
        }
Ejemplo n.º 3
0
        public async Task Scheduled_Events_that_cannot_be_deserialized_due_to_unknown_command_do_not_cause_sourcing_to_fail()
        {
            var orderId   = Guid.NewGuid();
            var goodEvent = new Order.CustomerInfoChanged
            {
                CustomerName   = "Waylon Jennings",
                AggregateId    = orderId,
                SequenceNumber = 1
            }.ToInMemoryStoredEvent();
            var badEvent = CreateStoredEvent(
                streamName: goodEvent.StreamName,
                type: "Scheduled:UNKNOWNCOMMAND",
                aggregateId: Guid.Parse(goodEvent.AggregateId),
                sequenceNumber: 2,
                body: new
            {
                Command = new
                {
                    CommandName = "UNKNOWNCOMMAND"
                }
            }.ToJson(),
                utcTime: DateTime.UtcNow);

            await SaveEventsDirectly(goodEvent, badEvent);

            var repository = CreateRepository <Order>();

            var order = await repository.GetLatest(orderId);

            order.CustomerName.Should().Be("Waylon Jennings");
        }
Ejemplo n.º 4
0
        public void If_no_aggregate_id_is_specified_when_adding_events_then_a_default_is_chosen_and_reused()
        {
            var created             = new Order.Created();
            var customerInfoChanged = new Order.CustomerInfoChanged();

            CreateScenarioBuilder()
            .AddEvents(created, customerInfoChanged);

            created.AggregateId.Should().NotBeEmpty();
            customerInfoChanged.AggregateId.Should().Be(created.AggregateId);
        }
Ejemplo n.º 5
0
        public async Task A_DuckTypeProjector_can_access_the_metadata_of_known_event_types_dynamically()
        {
            var lastEventId = Events.Write(1, _ => new Order.CustomerInfoChanged());

            Order.CustomerInfoChanged receivedEvent = null;

            var projector = Projector.CreateFor <Order.CustomerInfoChanged>(e => receivedEvent = e);

            using (var catchup = CreateReadModelCatchup(projector))
            {
                await catchup.Run();
            }

            long absoluteSequenceNumber = receivedEvent.Metadata.AbsoluteSequenceNumber;

            absoluteSequenceNumber.Should().Be(lastEventId);
        }