public void It_should_set_the_attribute_and_allow_the_update()
        {
            var uniqueString = Guid.NewGuid().ToString();

            var anotherUniqueString = Guid.NewGuid().ToString();

            var saga1 = new SagaWithUniqueProperty()
            {
                Id = Guid.NewGuid(),
                UniqueString = uniqueString,
                NonUniqueString = "notUnique"
            };

            SaveSaga(saga1);

            using(var session = store.OpenSession())
            {
                //fake that the attribute was just added by removing the metadata
                session.Advanced.GetMetadataFor(saga1).Remove(RavenSagaPersister.UniqueValueMetadataKey);
                session.SaveChanges();
            }

            UpdateSaga<SagaWithUniqueProperty>(saga1.Id, s => s.UniqueString = anotherUniqueString);

            string value;

            using (var session = store.OpenSession())
                value = session.Advanced.GetMetadataFor(saga1)[RavenSagaPersister.UniqueValueMetadataKey].ToString();

            Assert.AreEqual(anotherUniqueString, value);
        }
        public void should_throw_a_ArgumentNullException()
        {
            var saga1 = new SagaWithUniqueProperty
                            {
                                Id = Guid.NewGuid(),
                                UniqueString = null
                            };

            SaveSaga(saga1);
        }
        public void It_should_persist_successfully()
        {
            var uniqueString = Guid.NewGuid().ToString();

            var saga1 = new SagaWithUniqueProperty()
                        {
                            Id = Guid.NewGuid(),
                            UniqueString = uniqueString,
                            NonUniqueString = "notUnique"
                        };

            SaveSaga(saga1);

            UpdateSaga<SagaWithUniqueProperty>(saga1.Id, s => s.NonUniqueString = "notUnique2");
        }
        public void It_should_enforce_uniqueness()
        {
            var uniqueString = Guid.NewGuid().ToString();

            var saga1 = new SagaWithUniqueProperty
                        {
                            Id = Guid.NewGuid(),
                            UniqueString = uniqueString
                        };

            var saga2 = new SagaWithUniqueProperty
                        {
                            Id = Guid.NewGuid(),
                            UniqueString = uniqueString
                        };

            SaveSaga(saga1);
            Assert.Throws<ConcurrencyException>(() => SaveSaga(saga2));
        }
        public void It_should_persist_successfully()
        {
            var uniqueString = Guid.NewGuid().ToString();
            var saga1 = new SagaWithUniqueProperty
            {
                Id = Guid.NewGuid(),
                UniqueString = uniqueString
            };

            var saga2 = new SagaWithUniqueProperty
            {
                Id = Guid.NewGuid(),
                UniqueString = uniqueString
            };

            SaveSaga(saga1);
            CompleteSaga<SagaWithUniqueProperty>(saga1.Id);
            SaveSaga(saga2);
        }
        public void It_should_allow_the_update()
        {
            var uniqueString = Guid.NewGuid().ToString();
            var saga1 = new SagaWithUniqueProperty
                        {
                            Id = Guid.NewGuid(),
                            UniqueString = uniqueString
                        };

            SaveSaga(saga1);

            UpdateSaga<SagaWithUniqueProperty>(saga1.Id, s => s.UniqueString = Guid.NewGuid().ToString());

            var saga2 = new SagaWithUniqueProperty
            {
                Id = Guid.NewGuid(),
                UniqueString = uniqueString
            };

            //this should not blow since we changed the uniq value in the previous saga
            SaveSaga(saga2);
        }