Example #1
0
    public void Duplicates_should_not_be_generated_for_interface_inheritance_chains()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var storage = new SubscriptionPersister
            {
                DocumentStore = store
            };

            storage.Init();
            storage.Subscribe(TestClients.ClientA, new[]
            {
                new MessageType(typeof(ISomeInterface))
            });
            storage.Subscribe(TestClients.ClientA, new[]
            {
                new MessageType(typeof(ISomeInterface2))
            });
            storage.Subscribe(TestClients.ClientA, new[]
            {
                new MessageType(typeof(ISomeInterface3))
            });

            var subscriptionsForMessageType = storage.GetSubscriberAddressesForMessage(new[]
            {
                new MessageType(typeof(ISomeInterface)),
                new MessageType(typeof(ISomeInterface2)),
                new MessageType(typeof(ISomeInterface3))
            });

            Assert.AreEqual(1, subscriptionsForMessageType.Count());
        }
    }
    public void It_should_enforce_uniqueness()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            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();
            });
        }
    }
Example #3
0
    public void shouldnt_create_additional_db_rows()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var storage = new SubscriptionPersister
            {
                DocumentStore = store
            };

            storage.Subscribe(new Address("testEndPoint", "localhost"), new List <MessageType>
            {
                new MessageType("SomeMessageType", "1.0.0.0")
            });
            storage.Subscribe(new Address("testEndPoint", "localhost"), new List <MessageType>
            {
                new MessageType("SomeMessageType", "1.0.0.0")
            });


            using (var session = store.OpenSession())
            {
                var subscriptions = session
                                    .Query <Subscription>()
                                    .Customize(c => c.WaitForNonStaleResults())
                                    .Count();

                Assert.AreEqual(1, subscriptions);
            }
        }
    }
Example #4
0
    public void A_subscription_entry_should_be_added_to_the_database()
    {
        var clientEndpoint = Address.Parse("TestEndpoint");

        var messageTypes = new[]
        {
            new MessageType("MessageType1", "1.0.0.0"),
            new MessageType("MessageType2", "1.0.0.0")
        };

        using (var store = DocumentStoreBuilder.Build())
        {
            var storage = new SubscriptionPersister
            {
                DocumentStore = store
            };

            using (var transaction = new TransactionScope())
            {
                storage.Subscribe(clientEndpoint, messageTypes);
                transaction.Complete();
            }

            using (var session = store.OpenSession())
            {
                var subscriptions = session
                                    .Query <Subscription>()
                                    .Customize(c => c.WaitForNonStaleResults())
                                    .Count();

                Assert.AreEqual(2, subscriptions);
            }
        }
    }
    public void It_should_persist_successfully()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            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_persist_successfully()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            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 It_should_allow_the_update()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            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();
        }
    }
Example #8
0
 public void It_should_return_null()
 {
     using (var store = DocumentStoreBuilder.Build())
     {
         var factory = new RavenSessionFactory(store);
         factory.ReleaseSession();
         var persister = new SagaPersister(factory);
         Assert.Null(persister.Get <SagaData>("UniqueString", Guid.NewGuid().ToString()));
     }
 }
    public void No_subscribers_should_be_returned()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var storage = new SubscriptionPersister
            {
                DocumentStore = store
            };

            storage.Init();
            var subscriptionsForMessageType = storage.GetSubscriberAddressesForMessage(MessageTypes.MessageA);

            Assert.AreEqual(0, subscriptionsForMessageType.Count());
        }
    }
    public void should_throw_a_ArgumentNullException()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var saga1 = new SagaWithUniqueProperty
            {
                Id           = Guid.NewGuid(),
                UniqueString = null
            };

            var factory   = new RavenSessionFactory(store);
            var persister = new SagaPersister(factory);
            persister.Save(saga1);
            factory.SaveChanges();
        }
    }
        public void simple_construction()
        {
            var settings = new RavenDbSettings
            {
                RunInMemory = true
            };

            var actions = new IDocumentStoreConfigurationAction[]
            { new CustomizeRavenJsonSerializer(new JsonConverter[0]), };

            var builder = new DocumentStoreBuilder(settings, actions);
            var store   = builder.Build().ShouldBeOfType <EmbeddableDocumentStore>();

            store.RunInMemory.ShouldBeTrue();
            store.Conventions.CustomizeJsonSerializer.ShouldNotBeNull();
        }
    public void All_subscription_entries_for_specified_message_types_should_be_removed()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var storage = new SubscriptionPersister
            {
                DocumentStore = store
            };

            storage.Subscribe(TestClients.ClientA, MessageTypes.All);

            storage.Unsubscribe(TestClients.ClientA, MessageTypes.All);

            var clients = storage.GetSubscriberAddressesForMessage(MessageTypes.All);
            Assert.IsFalse(clients.Any(a => a == TestClients.ClientA));
        }
    }
Example #13
0
 public void Should_not_generate_a_to_long_unique_property_id()
 {
     using (var store = DocumentStoreBuilder.Build())
     {
         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 Datetime_property_should_be_persisted()
    {
        var entity = new SagaData
        {
            Id = Guid.NewGuid(),
            DateTimeProperty = DateTime.Parse("12/02/2010 12:00:00.01")
        };

        using (var store = DocumentStoreBuilder.Build())
        {
            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.DateTimeProperty, savedEntity.DateTimeProperty);
        }
    }
Example #15
0
    public void It_should_set_the_attribute_and_allow_the_update()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            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 Enums_should_be_persisted()
    {
        var entity = new SagaData
        {
            Id     = Guid.NewGuid(),
            Status = StatusEnum.AnotherStatus
        };

        using (var store = DocumentStoreBuilder.Build())
        {
            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);
        }
    }
Example #17
0
    public void The_names_of_all_subscribers_should_be_returned()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            var storage = new SubscriptionPersister
            {
                DocumentStore = store
            };

            storage.Subscribe(TestClients.ClientA, MessageTypes.MessageA);
            storage.Subscribe(TestClients.ClientA, MessageTypes.MessageB);
            storage.Subscribe(TestClients.ClientB, MessageTypes.MessageA);
            storage.Subscribe(TestClients.ClientA, MessageTypes.MessageAv2);

            var subscriptionsForMessageType = storage.GetSubscriberAddressesForMessage(MessageTypes.MessageA);

            Assert.AreEqual(2, subscriptionsForMessageType.Count());
            Assert.AreEqual(TestClients.ClientA, subscriptionsForMessageType.First());
        }
    }
    public void Should_delete_the_saga()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            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 Public_setters_and_getters_of_concrete_classes_should_be_persisted()
 {
     using (var store = DocumentStoreBuilder.Build())
     {
         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);
     }
 }
Example #20
0
    public void Inherited_property_classes_should_be_persisted()
    {
        using (var store = DocumentStoreBuilder.Build())
        {
            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);
        }
    }