public void GetSagaConfiguration_GetsInherited()
        {
            var configurationInfo = SagaConventionConfigurationScanner.GetSagaConfiguration(typeof(Saga2));

            configurationInfo.Events.Count.Should().Be(2);
            configurationInfo.Events.Keys.Should().Contain(typeof(Event1));
            configurationInfo.Events.Keys.Should().Contain(typeof(Event2));
        }
        public void GetSagaConfiguration_MultipleAttributesPerEvent()
        {
            var configurationInfo = SagaConventionConfigurationScanner.GetSagaConfiguration(typeof(Saga5));

            Assert.Equal(1, configurationInfo.Events.Count);
            Assert.True(configurationInfo.Events.TryGetValue(typeof(Event1),
                                                             out var eventInfos));
            Assert.Equal(2, eventInfos.Count);
            var eventInfo1 = eventInfos.ElementAt(0);
            var eventInfo2 = eventInfos.ElementAt(1);

            Assert.Equal("foo", eventInfo1.SagaKey);
            Assert.Equal("bar", eventInfo2.SagaKey);
        }
        public void GetSagaConfiguration_EventKeyExpressionToStringWithoutFormat()
        {
            Guid bar    = Guid.Parse("{3A9A28C9-1776-4D17-A3DA-AA54AC618076}");
            var  event1 = new EventMessage <Event1>(new Event1()
            {
                Foo = 5, Bar = bar
            }, new Dictionary <string, string>());
            var configurationInfo = SagaConventionConfigurationScanner.GetSagaConfiguration(typeof(Saga4));

            configurationInfo.Events.TryGetValue(typeof(Event1),
                                                 out var eventInfos).Should().BeTrue();
            eventInfos.Count.Should().Be(1);
            var eventInfo = eventInfos.ElementAt(0);

            eventInfo.EventKeyExpression(event1.Event).Should().Be(bar.ToString());
        }
        public void GetSagaConfiguration_GetsAttributeConfiguredEvent()
        {
            var event1 = new EventMessage <Event1>(new Event1()
            {
                Foo = 5
            }, new Dictionary <string, string>());
            var configurationInfo = SagaConventionConfigurationScanner.GetSagaConfiguration(typeof(Saga3));

            configurationInfo.Events.TryGetValue(typeof(Event1),
                                                 out var eventInfos).Should().BeTrue();
            eventInfos.Count.Should().Be(1);
            var eventInfo = eventInfos.ElementAt(0);

            eventInfo.EventKeyExpression(event1.Event).Should().Be("5");
            eventInfo.SagaKey.Should().Be("foo");
            eventInfo.IsStartingIfSagaNotFound.Should().BeTrue();
        }
        public void GetSagaConfiguration_GetsEventInfos()
        {
            var configurationInfo = SagaConventionConfigurationScanner.GetSagaConfiguration(typeof(Saga1));

            Assert.Equal(1, configurationInfo.Events.Count);
            Assert.True(configurationInfo.Events.TryGetValue(typeof(Event1),
                                                             out var eventInfos));
            Assert.Equal(1, eventInfos.Count);
            var eventInfo = eventInfos.ElementAt(0);

            Saga1 saga   = new Saga1(Guid.NewGuid());
            var   event1 = new EventMessage <Event1>(new Event1(), new Dictionary <string, string>());

            eventInfo.HandleDelegate(saga, event1);

            Assert.Equal(1, saga.HandledEvents.Count);
            Assert.Equal(event1, saga.HandledEvents[0]);
        }
        public void GetSagaConfiguration_GetsPublicHandlers()
        {
            var configurationInfo = SagaConventionConfigurationScanner.GetSagaConfiguration(typeof(Saga6PublicHandlers));

            configurationInfo.Events.Count.Should().Be(2);
        }