コード例 #1
0
            public void then_it_should_return_the_handler_given_the_event_type()
            {
                object result  = null;
                var    handler = HandlerFactory(x => result = x);
                var    e       = new FakeEvent();

                SUT.RegisterHandlerToEvent(e.GetType(), handler);
                SUT.GetHandlersForEvent(e.GetType(), x => x(e), () => { });

                result.ShouldBeSameAs(e);
            }
コード例 #2
0
            public void then_it_should_not_be_called()
            {
                var    e       = new FakeEvent();
                object result  = null;
                var    handler = HandlerFactory(x => result = x);

                SUT.RegisterHandlerToEvent(e.GetType(), handler);

                SUT.UnregisterHandlerFromEvent(e.GetType(), handler);
                SUT.GetHandlersForEvent(e.GetType(), x => x(e), () => { });

                result.ShouldBeNull();
            }
コード例 #3
0
        public void WhenCreateCalledWithEventThenShouldReturnEntityWithExpectedPropertiesPopulated()
        {
            var services = new ServiceCollection();

            services.AddOpenEventSourcing()
            .AddEntityFrameworkCoreInMemory()
            .AddJsonSerializers();

            var serviceProvider   = services.BuildServiceProvider();
            var eventModelFactory = serviceProvider.GetRequiredService <IEventModelFactory>();
            var eventSerializer   = serviceProvider.GetRequiredService <IEventSerializer>();

            var @event  = new FakeEvent(subject: Guid.NewGuid().ToString(), version: 1);
            var context = new EventContext <FakeEvent>(streamId: @event.Subject, @event: @event, correlationId: CorrelationId.New(), causationId: CausationId.From(Guid.NewGuid().ToString()), timestamp: DateTimeOffset.UtcNow, actor: Actor.From("test-user"));
            var entity  = eventModelFactory.Create(streamId: @event.Subject, context);

            entity.StreamId.Should().Be(@event.Subject);
            entity.CausationId.Should().Be(context.CausationId);
            entity.CorrelationId.Should().Be(context.CorrelationId);
            entity.Data.Should().Be(eventSerializer.Serialize(@event));
            entity.Id.Should().Be(@event.Id);
            entity.Name.Should().Be(nameof(FakeEvent));
            entity.Timestamp.Should().Be(@event.Timestamp);
            entity.Type.Should().Be(@event.GetType().FullName);
            entity.Actor.Should().Be(context.Actor);
        }
コード例 #4
0
            public void then_it_should_not_remove_any_others()
            {
                var    e        = new FakeEvent();
                object result1  = null;
                object result2  = null;
                var    handler1 = HandlerFactory(x => result1 = x);
                var    handler2 = HandlerFactory(x => result2 = x);

                SUT.RegisterHandlerToEvent(e.GetType(), handler1);
                SUT.RegisterHandlerToEvent(e.GetType(), handler2);

                SUT.UnregisterHandlerFromEvent(e.GetType(), handler1);
                SUT.GetHandlersForEvent(e.GetType(), x => x(e), () => { });

                result1.ShouldBeNull();
                result2.ShouldBeSameAs(e);
            }
コード例 #5
0
        public void Write_WrapsValue_AddsTypeNameToWrapper()
        {
            //Arrange

            //Act
            string json = serializer.Serialize(@event);

            //Assert
            json.Should().Contain("TypeName");
            json.Should().Contain("TypeValue");
            json.Should().Contain(@event.GetType().ToString());
            json.Should().Contain(@event.AggregateId.ToString());
            json.Should().Contain(@event.Id.ToString());
            json.Should().Contain(@event.Date.ToString("d"));
            json.Should().Contain(@event.Message);
        }