Exemplo n.º 1
0
        public void UsesOptimisticLockingAndDetectsRaceConditionsWhenUpdatingFindingById()
        {
            var persister         = CreatePersister(createTables: true);
            var indexBySomeString = new[] { "Id" };
            var id             = Guid.NewGuid();
            var simpleSagaData = new SimpleSagaData {
                Id = id, SomeString = "hello world!"
            };

            persister.Insert(simpleSagaData, indexBySomeString);

            var sagaData1 = persister.Find <SimpleSagaData>("Id", id);

            sagaData1.SomeString = "I changed this on one worker";

            using (EnterAFakeMessageContext())
            {
                var sagaData2 = persister.Find <SimpleSagaData>("Id", id);
                sagaData2.SomeString = "I changed this on another worker";
                persister.Update(sagaData2, indexBySomeString);
            }

            Assert.Throws <OptimisticLockingException>(() => persister.Insert(sagaData1, indexBySomeString));
        }