Example #1
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);
        }
Example #2
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);
        }
Example #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);
        }