Ejemplo n.º 1
0
            public void SagaRemovedFromCacheIfCompleted()
            {
                var saga = new FakeSaga {
                    CorrelationId = GuidStrategy.NewGuid()
                };
                var sagaStore  = new Mock <IStoreSagas>();
                var cachedSaga = default(Saga);

                using (var sagaContext = new SagaContext(typeof(FakeSaga), saga.CorrelationId, new FakeEvent()))
                    using (var cachedSagaStore = new CachedSagaStore(sagaStore.Object))
                    {
                        cachedSagaStore.Save(saga, sagaContext);

                        saga.Completed = true;

                        cachedSagaStore.Save(saga, sagaContext);

                        Assert.False(cachedSagaStore.TryGetSaga(typeof(FakeSaga), saga.CorrelationId, out cachedSaga));
                    }
            }
Ejemplo n.º 2
0
            public void SagaRemovedFromCacheIfConcurrencyExceptionThrown()
            {
                var saga = new FakeSaga {
                    CorrelationId = GuidStrategy.NewGuid()
                };
                var sagaStore  = new Mock <IStoreSagas>();
                var cachedSaga = default(Saga);
                var save       = 0;

                using (var sagaContext = new SagaContext(typeof(FakeSaga), saga.CorrelationId, new FakeEvent()))
                    using (var cachedSagaStore = new CachedSagaStore(sagaStore.Object))
                    {
                        sagaStore.Setup(mock => mock.Save(It.IsAny <Saga>(), sagaContext)).Callback(() => { if (save++ == 1)
                                                                                                            {
                                                                                                                throw new ConcurrencyException();
                                                                                                            }
                                                                                                    });
                        cachedSagaStore.Save(saga, sagaContext);

                        Assert.True(cachedSagaStore.TryGetSaga(typeof(FakeSaga), saga.CorrelationId, out cachedSaga));
                        Assert.Throws <ConcurrencyException>(() => cachedSagaStore.Save(saga, sagaContext));
                        Assert.False(cachedSagaStore.TryGetSaga(typeof(FakeSaga), saga.CorrelationId, out cachedSaga));
                    }
            }
Ejemplo n.º 3
0
            public void SagaUpdatedAfterSaveIfNotCompleted()
            {
                var saga = new FakeSaga {
                    CorrelationId = GuidStrategy.NewGuid()
                };
                var memoryCache = new MemoryCache(Guid.NewGuid().ToString());
                var sagaStore   = new Mock <IStoreSagas>();

                using (var sagaContext = new SagaContext(typeof(FakeSaga), saga.CorrelationId, new FakeEvent()))
                    using (var cachedSagaStore = new CachedSagaStore(sagaStore.Object, TimeSpan.FromMinutes(1), memoryCache))
                    {
                        cachedSagaStore.Save(saga, sagaContext);

                        Assert.Same(saga, memoryCache.Get(typeof(FakeSaga).GetFullNameWithAssembly() + '-' + saga.CorrelationId));
                    }
            }
            public void SagaRemovedFromCacheIfConcurrencyExceptionThrown()
            {
                var saga = new FakeSaga { CorrelationId = GuidStrategy.NewGuid() };
                var sagaStore = new Mock<IStoreSagas>();
                var cachedSaga = default(Saga);
                var save = 0;

                using (var sagaContext = new SagaContext(typeof(FakeSaga), saga.CorrelationId, new FakeEvent()))
                using (var cachedSagaStore = new CachedSagaStore(sagaStore.Object))
                {
                    sagaStore.Setup(mock => mock.Save(It.IsAny<Saga>(), sagaContext)).Callback(() => { if (save++ == 1) { throw new ConcurrencyException(); } });
                    cachedSagaStore.Save(saga, sagaContext);

                    Assert.True(cachedSagaStore.TryGetSaga(typeof(FakeSaga), saga.CorrelationId, out cachedSaga));
                    Assert.Throws<ConcurrencyException>(() => cachedSagaStore.Save(saga, sagaContext));
                    Assert.False(cachedSagaStore.TryGetSaga(typeof(FakeSaga), saga.CorrelationId, out cachedSaga));
                }
            }
            public void SagaRemovedFromCacheIfCompleted()
            {
                var saga = new FakeSaga { CorrelationId = GuidStrategy.NewGuid() };
                var sagaStore = new Mock<IStoreSagas>();
                var cachedSaga = default(Saga);

                using (var sagaContext = new SagaContext(typeof(FakeSaga), saga.CorrelationId, new FakeEvent()))
                using (var cachedSagaStore = new CachedSagaStore(sagaStore.Object))
                {
                    cachedSagaStore.Save(saga, sagaContext);

                    saga.Completed = true;

                    cachedSagaStore.Save(saga, sagaContext);

                    Assert.False(cachedSagaStore.TryGetSaga(typeof(FakeSaga), saga.CorrelationId, out cachedSaga));
                }
            }
            public void SagaUpdatedAfterSaveIfNotCompleted()
            {
                var saga = new FakeSaga { CorrelationId = GuidStrategy.NewGuid() };
                var memoryCache = new MemoryCache(Guid.NewGuid().ToString());
                var sagaStore = new Mock<IStoreSagas>();

                using (var sagaContext = new SagaContext(typeof(FakeSaga), saga.CorrelationId, new FakeEvent()))
                using (var cachedSagaStore = new CachedSagaStore(sagaStore.Object, TimeSpan.FromMinutes(1), memoryCache))
                {
                    cachedSagaStore.Save(saga, sagaContext);

                    Assert.Same(saga, memoryCache.Get(typeof(FakeSaga).GetFullNameWithAssembly() + '-' + saga.CorrelationId));
                }
            }