Exemplo n.º 1
0
        public void CanUseCustomizedPersisterWhenSupplyingInstanceAndThenCustomizingWithTypeMapping()
        {
            var fallbackPersister = new InMemorySagaPersister();
            var customPersister   = new InMemorySagaPersister();

            var hybridPersister = new HybridSagaPersister(fallbackPersister)
                                  .Add(customPersister)
                                  .Customize <AnotherChunkOfData, InMemorySagaPersister>();

            var data1 = new ChunkOfData {
                SomeString = "Hello"
            };

            hybridPersister.Insert(data1, new string[0]);

            var fallbackPersisterCountAfterFirstInsert = fallbackPersister.Count();
            var customPersisterCountAfterFirstInsert   = customPersister.Count();

            var data2 = new AnotherChunkOfData {
                AnotherString = "Hello"
            };

            hybridPersister.Insert(data2, new string[0]);

            var fallbackPersisterCountAfterSecondInsert = fallbackPersister.Count();
            var customPersisterCountAfterSecondInsert   = customPersister.Count();

            fallbackPersisterCountAfterFirstInsert.ShouldBe(1);
            customPersisterCountAfterFirstInsert.ShouldBe(0);

            fallbackPersisterCountAfterSecondInsert.ShouldBe(1);
            customPersisterCountAfterSecondInsert.ShouldBe(1);
        }
Exemplo n.º 2
0
        public void CanUseCustomizedPersisterWhenSettingSpecificInstance()
        {
            var fallbackPersister = new InMemorySagaPersister();
            var customPersister   = new InMemorySagaPersister();

            var hybridPersister = new HybridSagaPersister(fallbackPersister)
                                  .Customize <AnotherChunkOfData>(customPersister);

            var data1 = new ChunkOfData {
                SomeString = "Hello"
            };

            hybridPersister.Insert(data1, new string[0]);

            var fallbackPersisterCountAfterFirstInsert = fallbackPersister.Count();
            var customPersisterCountAfterFirstInsert   = customPersister.Count();

            var data2 = new AnotherChunkOfData {
                AnotherString = "Hello"
            };

            hybridPersister.Insert(data2, new string[0]);

            var fallbackPersisterCountAfterSecondInsert = fallbackPersister.Count();
            var customPersisterCountAfterSecondInsert   = customPersister.Count();

            fallbackPersisterCountAfterFirstInsert.ShouldBe(1);
            customPersisterCountAfterFirstInsert.ShouldBe(0);

            fallbackPersisterCountAfterSecondInsert.ShouldBe(1);
            customPersisterCountAfterSecondInsert.ShouldBe(1);
        }
Exemplo n.º 3
0
        public void UsesFallbackPersisterWhenNoCustomOnesAreConfigured()
        {
            // arrange
            var stringPath = Reflect.Path <ChunkOfData>(c => c.SomeString);
            var indexPaths = new[] { stringPath };

            var inMemorySagaPersister = new InMemorySagaPersister();
            var persister             = new HybridSagaPersister(inMemorySagaPersister)
                                        .Add(new ThrowingSagaPersister());

            // act
            // assert
            var data = new ChunkOfData {
                SomeString = "Hello"
            };

            persister.Insert(data, indexPaths);

            var sagaCountAfterFirstInsert = inMemorySagaPersister.Count();

            var loadedData = persister.Find <ChunkOfData>(stringPath, "Hello");

            loadedData.ShouldNotBe(null);
            loadedData.SomeString.ShouldBe("Hello");

            loadedData.SomeString = "Hello again!";
            persister.Update(loadedData, indexPaths);

            var reloadedData = persister.Find <ChunkOfData>(stringPath, "Hello again!");

            reloadedData.ShouldNotBe(null);
            reloadedData.SomeString.ShouldBe("Hello again!");

            persister.Delete(reloadedData);
            var sagaCountAfterDelete = inMemorySagaPersister.Count();

            sagaCountAfterDelete.ShouldBe(0);
            sagaCountAfterFirstInsert.ShouldBe(1);
        }
Exemplo n.º 4
0
        public void IgnoresAutoCorrelationWhenCorrelationIsExplicitlySetUp(bool abandonReply)
        {
            // arrange
            var anotherSaga = new AnotherSaga(sagaBus, abandonReply);

            sagaHandlerActivator.UseHandler(anotherSaga);

            serviceHandlerActivator.Handle <RequestWithCorrelationId>(req => serviceBus.Reply(new ReplyWithCorrelationId {
                Correlationid = req.Correlationid
            }));

            // act
            initiatorBus.Send(new InitiateRequestReply());
            Thread.Sleep(3.Seconds());

            // assert
            sagaPersister.Count().ShouldBe(1);
            var sagaData = sagaPersister.Single();

            sagaData.ShouldBeTypeOf <SomeSagaData>();
            ((SomeSagaData)sagaData).GotTheReply.ShouldBe(!abandonReply);
        }