public void It_should_persist_successfully()
        {
            //MongoDB.Bson.Serialization.BsonClassMap.RegisterClassMap<SagaWithUniqueProperty>(x =>
            //                                                                                     {
            //                                                                                         x.AutoMap();
            //                                                                                         x.SetIgnoreExtraElements(true);
            //                                                                                         x.SetIdMember(x.GetMemberMap(y => y.Id));
            //                                                                                     });
            MongoMappingConfiguration.ConfigureMapping();

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

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

            SaveSaga(saga1);
            CompleteSaga<SagaWithUniqueProperty>(saga1.Id);
            SaveSaga(saga2);
        }
        public void It_should_persist_successfully()
        {
            var saga1 = new SagaWithUniqueProperty()
                            {
                                Id = Guid.NewGuid(),
                                UniqueString = "whatever",
                                NonUniqueString = "notUnique"
                            };

            SaveSaga(saga1);

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

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

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

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

            SaveSaga(saga1);
            CompleteSaga<SagaWithUniqueProperty>(saga1.Id);
            SaveSaga(saga2);
        }
        public void It_should_set_the_attribute_and_allow_the_update()
        {
            var saga1 = new SagaWithUniqueProperty()
                            {
                                Id = Guid.NewGuid(),
                                UniqueString = "whatever",
                                NonUniqueString = "notUnique"
                            };

            SaveSaga(saga1);

            //fake that the attribute was just added by removing the metadata
            var result = Sagas.FindAndModify(Query.EQ("_id", saga1.Id), SortBy.Null,
                                Update.Set(MongoSagaPersister.MetadataPropertyName, BsonTypeMapper.MapToBsonValue(null)), true);

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

            string value = null;
            BsonElement metadata;
            if(Sagas.FindOne(Query.EQ("_id", saga1.Id)).TryGetElement(MongoSagaPersister.MetadataPropertyName, out metadata))
                value=metadata.Value.AsString;

            Assert.AreEqual("whatever2", value);
        }