Exemplo n.º 1
0
        public void WorksWhenMessageReferenceIsOfTheSupertype()
        {
            // arrange
            var data = new CounterpartData {
                Dcid = 800
            };
            var calledHandlers = new List <string>();
            var fixture        = new SagaFixture <CounterpartData>(new CounterpartUpdater(calledHandlers));

            fixture.AddSagaData(data);
            CounterpartChanged messageSupertype1 = new CounterpartCreated {
                Dcid = 800
            };
            CounterpartChanged messageSupertype2 = new CounterpartUpdated {
                Dcid = 800
            };

            // act
            // assert
            fixture.Handle(messageSupertype1);
            fixture.Handle(messageSupertype2);

            calledHandlers.ShouldBe(new List <string>
            {
                "CounterpartCreated",
                "CounterpartUpdated",
            });
        }
Exemplo n.º 2
0
        public void GetsHumanReadableExceptionWhenSomethingGoesWrong()
        {
            // arrange
            var data = new List <SomeSagaData> {
                new SomeSagaData {
                    SagaDataId = 23
                }
            };
            var fixture = new SagaFixture <SomeSagaData>(new SomeSaga());

            fixture.AddSagaData(data);

            // act
            var exception = Assert.Throws <ApplicationException>(() => fixture.Handle(new SomePoisonMessage {
                SagaDataId = 23
            }));

            Console.WriteLine(exception.ToString());

            // assert
            exception.Message.ShouldContain("Oh no, something bad happened while processing message with saga data id 23");
        }
Exemplo n.º 3
0
        public void CanUseSagaDataProvidedInVariousWays(string howToProvideSagaData)
        {
            // arrange
            const string recognizableText = "this, I can recognize!";
            var          someSagaData     = new SomeSagaData {
                SagaDataId = 10, JustSomeText = recognizableText
            };
            SagaFixture <SomeSagaData> fixture;

            switch (howToProvideSagaData)
            {
            //case "in the list":
            //    fixture = new SagaFixture<SomeSagaData>(new SomeSaga(), new List<SomeSagaData> { someSagaData });
            //    break;

            case "after the fact":
                fixture = new SagaFixture <SomeSagaData>(new SomeSaga());
                fixture.AddSagaData(someSagaData);
                break;

            default:
                throw new ArgumentException(string.Format("Don't know how to provide saga data like this: {0}", howToProvideSagaData), "howToProvideSagaData");
            }

            // act
            fixture.Handle(new SomeMessage {
                SagaDataId = 10
            });

            // assert
            var availableSagaData = fixture.AvailableSagaData;

            availableSagaData.Count().ShouldBe(1);
            var sagaDataClone = availableSagaData.Single(d => d.SagaDataId == 10);

            sagaDataClone.JustSomeText.ShouldBe(recognizableText);
        }