public void It_should_enforce_uniqueness()
    {
        var factory = new RavenSessionFactory(store);
        factory.ReleaseSession();
        var persister = new SagaPersister(factory);
        var uniqueString = Guid.NewGuid().ToString();

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

        persister.Save(saga1);
        factory.SaveChanges();
        factory.ReleaseSession();

        Assert.Throws<ConcurrencyException>(() =>
        {
            var saga2 = new SagaData
                {
                    Id = Guid.NewGuid(),
                    UniqueString = uniqueString
                };
            persister.Save(saga2);
            factory.SaveChanges();
        });
    }
    public void It_should_persist_successfully()
    {
        var factory = new RavenSessionFactory(store);
        factory.ReleaseSession();
        var persister = new SagaPersister(factory);
        var uniqueString = Guid.NewGuid().ToString();
        var saga1 = new SagaData
            {
                Id = Guid.NewGuid(),
                UniqueString = uniqueString
            };
        persister.Save(saga1);
        factory.SaveChanges();
        factory.ReleaseSession();

        var saga = persister.Get<SagaData>(saga1.Id);
        persister.Complete(saga);
        factory.SaveChanges();
        factory.ReleaseSession();

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

        persister.Save(saga2);
        factory.SaveChanges();
    }
    public void It_should_allow_the_update()
    {
        var factory = new RavenSessionFactory(store);
        factory.ReleaseSession();
        var persister = new SagaPersister(factory);
        var uniqueString = Guid.NewGuid().ToString();
        var saga1 = new SagaData
            {
                Id = Guid.NewGuid(),
                UniqueString = uniqueString
            };

        persister.Save(saga1);
        factory.SaveChanges();
        factory.ReleaseSession();

        var saga = persister.Get<SagaData>(saga1.Id);
        saga.UniqueString = Guid.NewGuid().ToString();
        persister.Update(saga);
        factory.SaveChanges();
        factory.ReleaseSession();

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

        //this should not blow since we changed the unique value in the previous saga
        persister.Save(saga2);
        factory.SaveChanges();
    }
    public void Should_delete_the_saga()
    {
        var sagaId = Guid.NewGuid();

        var factory = new RavenSessionFactory(store);
        factory.ReleaseSession();
        var persister = new SagaPersister(factory);
        persister.Save(new SagaData
            {
                Id = sagaId
            });
        factory.SaveChanges();

        var saga = persister.Get<SagaData>(sagaId);
        persister.Complete(saga);
        factory.SaveChanges();

        Assert.Null(persister.Get<SagaData>(sagaId));
    }
    public void It_should_set_the_attribute_and_allow_the_update()
    {
        var factory = new RavenSessionFactory(store);
        factory.ReleaseSession();
        var persister = new SagaPersister(factory);
        var uniqueString = Guid.NewGuid().ToString();

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

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

        persister.Save(saga1);
        factory.SaveChanges();
        factory.ReleaseSession();

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

        var saga = persister.Get<SagaData>(saga1.Id);
        saga.UniqueString = anotherUniqueString;
        persister.Update(saga);
        factory.SaveChanges();
        factory.ReleaseSession();

        using (var session = store.OpenSession())
        {
            var value = session.Advanced.GetMetadataFor(saga1)[SagaPersister.UniqueValueMetadataKey].ToString();
            Assert.AreEqual(anotherUniqueString, value);
        }
    }
    public void It_should_persist_successfully()
    {
        var factory = new RavenSessionFactory(store);
        factory.ReleaseSession();
        var persister = new SagaPersister(factory);
        var uniqueString = Guid.NewGuid().ToString();
        var anotherUniqueString = Guid.NewGuid().ToString();

        var saga1 = new SagaData
        {
            Id = Guid.NewGuid(),
            UniqueString = uniqueString,
            NonUniqueString = "notUnique"
        };
        persister.Save(saga1);
        factory.SaveChanges();

        var saga = persister.Get<SagaData>(saga1.Id);
        saga.NonUniqueString = "notUnique2";
        saga.UniqueString = anotherUniqueString;
        persister.Update(saga);
        factory.SaveChanges();
    }
 public void Should_not_generate_a_to_long_unique_property_id()
 {
     var factory = new RavenSessionFactory(store);
     factory.ReleaseSession();
     var persister = new SagaPersister(factory);
     var uniqueString = Guid.NewGuid().ToString();
     var saga = new SagaWithUniquePropertyAndALongNamespace
         {
             Id = Guid.NewGuid(),
             UniqueString = uniqueString
         };
     persister.Save(saga);
     factory.SaveChanges();
 }
    public void Enums_should_be_persisted()
    {
        var entity = new SagaData
            {
                Id = Guid.NewGuid(),
                Status = StatusEnum.AnotherStatus
            };

        var factory = new RavenSessionFactory(store);
        factory.ReleaseSession();
        var persister = new SagaPersister(factory);
        persister.Save(entity);
        factory.SaveChanges();

        var savedEntity = persister.Get<SagaData>(entity.Id);
        Assert.AreEqual(entity.Status, savedEntity.Status);
    }
 public void Public_setters_and_getters_of_concrete_classes_should_be_persisted()
 {
     var entity = new SagaData
             {
                 Id = Guid.NewGuid(),
                 TestComponent = new TestComponent
                     {
                         Property = "Prop"
                     }
             };
     var factory = new RavenSessionFactory(store);
     factory.ReleaseSession();
     var persister = new SagaPersister(factory);
     persister.Save(entity);
     factory.SaveChanges();
     var savedEntity = persister.Get<SagaData>(entity.Id);
     Assert.AreEqual(entity.TestComponent.Property, savedEntity.TestComponent.Property);
     Assert.AreEqual(entity.TestComponent.AnotherProperty, savedEntity.TestComponent.AnotherProperty);
 }
    public void Inherited_property_classes_should_be_persisted()
    {
        var factory = new RavenSessionFactory(store);
        factory.ReleaseSession();
        var persister = new SagaPersister(factory);
        var entity = new SagaData
            {
                Id = Guid.NewGuid(),
                PolymorphicRelatedProperty = new PolymorphicProperty
                    {
                        SomeInt = 9
                    }
            };
        persister.Save(entity);
        factory.SaveChanges();

        var savedEntity = persister.Get<SagaData>(entity.Id);
        var expected = (PolymorphicProperty)entity.PolymorphicRelatedProperty;
        var actual = (PolymorphicProperty)savedEntity.PolymorphicRelatedProperty;
        Assert.AreEqual(expected.SomeInt, actual.SomeInt);
    }