Пример #1
0
        public void EventAreFiredInTheRightPlaces(string scenario)
        {
            var          events = new List <string>();
            const string justTheSameFrigginId = "just the same friggin ID";

            var fixture = new SagaFixture <CompletionSagaData>(new CompletionSaga());

            fixture.MarkedAsComplete += (msg, data) => events.Add("markedAsComplete");

            switch (scenario)
            {
            case "mark persistent saga data as complete":
                fixture.Handle(new InitiatingMessage {
                    CorrelationId = justTheSameFrigginId
                });
                fixture.Handle(new CompletionMessage {
                    CorrelationId = justTheSameFrigginId
                });
                break;

            case "mark non-persistent saga data as complete":
                fixture.Handle(new InitiateAndCompleteMessage {
                    CorrelationId = justTheSameFrigginId
                });
                break;

            default:
                throw new ArgumentException(string.Format("Unknown scenario: {0}", scenario));
            }

            events.ShouldContain("markedAsComplete");
        }
Пример #2
0
        public void CanCorrectlyHandleWhenSagaIsMarkedAsComplete()
        {
            // arrange
            var          fixture = new SagaFixture <CompletionSagaData>(new CompletionSaga());
            const string justTheSameFrigginId = "just the same friggin ID";

            var sagaDatasMarkedAsComplete = new List <ISagaData>();

            fixture.MarkedAsComplete += (message, data) => sagaDatasMarkedAsComplete.Add(data);
            fixture.CorrelatedWithExistingSagaData += (message, data) => Console.WriteLine("Correlated!");
            fixture.CouldNotCorrelate  += message => Console.WriteLine("Could not correlate!");
            fixture.CreatedNewSagaData += (message, data) => Console.WriteLine("Created new!");
            fixture.Exception          += (message, exception) => Console.WriteLine("Exception!");

            // act
            fixture.Handle(new InitiatingMessage {
                CorrelationId = justTheSameFrigginId
            });
            fixture.Handle(new CompletionMessage {
                CorrelationId = justTheSameFrigginId
            });
            fixture.Handle(new InitiatingMessage {
                CorrelationId = justTheSameFrigginId
            });
            fixture.Handle(new CompletionMessage {
                CorrelationId = justTheSameFrigginId
            });

            // assert
            sagaDatasMarkedAsComplete.Count.ShouldBe(2);
            fixture.DeletedSagaData.Count.ShouldBe(2);
        }
Пример #3
0
        public void CanCorrelateMessagesLikeExpected()
        {
            // arrange
            var fixture = new SagaFixture <SomeSagaData>(new SomeSaga());

            fixture.CreatedNewSagaData             += (message, data) => Console.WriteLine("Created new saga data");
            fixture.CorrelatedWithExistingSagaData += (message, data) => Console.WriteLine("Correlated with existing saga data");
            fixture.CouldNotCorrelate += message => Console.WriteLine("Could not correlate");

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

            // assert
            var availableSagaData = fixture.AvailableSagaData;

            availableSagaData.Count().ShouldBe(2);
            availableSagaData.Single(d => d.SagaDataId == 10).ReceivedMessages.ShouldBe(2);
            availableSagaData.Single(d => d.SagaDataId == 12).ReceivedMessages.ShouldBe(3);
        }
Пример #4
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",
            });
        }
Пример #5
0
        public void CanCorrectlySerializeAndDeserializeCaspersSagaData()
        {
            // arrange
            var fixture = new SagaFixture <SagaData>(new Saga());

            // act
            fixture.Handle(new Message {
                CorrelationId = 42, String = "hello there"
            });
            fixture.Handle(new Message {
                CorrelationId = 42, String = "hello again!"
            });

            // assert
            fixture.AvailableSagaData.Count()
            .ShouldBe(1);

            var sagaData = fixture.AvailableSagaData.Single();

            sagaData.ReceivedStrings.ShouldContain("hello there");
            sagaData.ReceivedStrings.ShouldContain("hello again!");

            var concreteClass = (ConcreteClass)sagaData.RefToAbstractClass;

            concreteClass.WithWhat.ShouldBe("something in it");
        }
Пример #6
0
        public void WorksWithAsyncInitiator()
        {
            // arrange
            var fixture = new SagaFixture <SomeSagaData>(new SomeSaga());

            fixture.CreatedNewSagaData             += (message, data) => Console.WriteLine("Created new saga data");
            fixture.CorrelatedWithExistingSagaData += (message, data) => Console.WriteLine("Correlated with existing saga data");
            fixture.CouldNotCorrelate += message => Console.WriteLine("Could not correlate");

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

            // assert
            var availableSagaData = fixture.AvailableSagaData.Single();

            availableSagaData.SagaDataId.ShouldBe(33);
            availableSagaData.ReceivedMessages.ShouldBe(2);
        }
Пример #7
0
        public void GivesEasyAccessToTheMostRecentlyCorrelatedSagaData()
        {
            // arrange
            var fixture = new SagaFixture <SomeSagaData>(new SomeSaga());

            fixture.CreatedNewSagaData             += (message, data) => Console.WriteLine("Created new saga data");
            fixture.CorrelatedWithExistingSagaData += (message, data) => Console.WriteLine("Correlated with existing saga data");
            fixture.CouldNotCorrelate += message => Console.WriteLine("Could not correlate");

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

            fixture.Handle(new SomeMessage {
                SagaDataId = 10
            });
            var data10Correlated = fixture.Data;

            fixture.Handle(new SomeMessage {
                SagaDataId = 12
            });
            var data12Created = fixture.Data;

            fixture.Handle(new SomeMessage {
                SagaDataId = 12
            });
            var data12Correlated = fixture.Data;

            // assert
            data10Created.SagaDataId.ShouldBe(10);
            data10Correlated.SagaDataId.ShouldBe(10);
            data12Created.SagaDataId.ShouldBe(12);
            data12Correlated.SagaDataId.ShouldBe(12);
        }
        public void SureDoes()
        {
            // arrange
            var mock = Mock <IMessageContext>();

            mock.Stub(m => m.Items).Return(new Dictionary <string, object>());
            mock.Stub(m => m.Headers).Return(new Dictionary <string, object>());

            // act
            using (FakeMessageContext.Establish(mock))
            {
                fixture.Handle("hello there!");
            }

            // assert
            sagaInstance.GotMessage.ShouldBe(true);
        }
Пример #9
0
        public void GetsHumanReadableExceptionWhenSomethingGoesWrong()
        {
            // arrange
            var data = new List <SomeSagaData> {
                new SomeSagaData {
                    SagaDataId = 23
                }
            };
            var fixture = new SagaFixture <SomeSagaData>(new SomeSaga(), 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");
        }
        public void ThrowsProperExceptionWhenAttemptingToEstablishMessageContextWithItemsDictionary()
        {
            var saga        = new SearchSaga();
            var fixture     = new SagaFixture <SearchSagaData>(saga);
            var fakeContext = MockRepository.GenerateMock <IMessageContext>();

            fakeContext.Stub(s => s.ReturnAddress).Return("queuename");
            fakeContext.Stub(s => s.Headers).Return(new Dictionary <string, object>());

            // act
            var ex = Assert
                     .Throws <ArgumentException>(() =>
            {
                using (FakeMessageContext.Establish(fakeContext))
                {
                    fixture.Handle("w00000t!");
                }
            });

            ex.Message.ShouldContain("has null as the Items property");
        }
Пример #11
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);
        }