Esempio n. 1
0
        public void throw_if_custom_id_property_doesnt_exist([ShortStrings] string value)
        {
            var entity = new NoIdEntity();

            Assert.That(() =>
            {
                EntityManagerFactory.Create(entity, value, _pump.Object);
            }, Throws.InstanceOf <ArgumentOutOfRangeException>());
        }
Esempio n. 2
0
        public void throw_if_topic_is_blank_or_empty([BlankOrEmptyStrings] string topic)
        {
            var entity = new RegularIdEntity <Guid>();

            Assert.That(() =>
            {
                EntityManagerFactory.Create(entity, _pump.Object, topic);
            }, Throws.InstanceOf <ArgumentOutOfRangeException>());
        }
Esempio n. 3
0
 public void throw_if_entity_has_no_id_and_topic_is_not_provided(
     [ValueSource(nameof(ObjectsWithNoObviousId))] object entity
     )
 {
     Assert.That(() =>
     {
         EntityManagerFactory.Create(entity, _pump.Object);
     }, Throws.InstanceOf <InvalidOperationException>());
 }
Esempio n. 4
0
        public void use_the_id_as_topic_by_default(
            [ValueSource(nameof(ObjectsWithRegularId))]
            object entity
            )
        {
            var topic   = entity.GetType().GetProperty("Id")?.GetValue(entity)?.ToString() ?? string.Empty;
            var manager = EntityManagerFactory.Create(entity, _pump.Object);

            Assert.That(manager.Topic, Is.EqualTo(topic), $"{nameof(manager.Topic)} should be {topic}");
            _pump.Verify(x => x.Connect(topic, manager), $"{topic} should be passed to pump as topic");
        }
Esempio n. 5
0
        public void use_custom_property_for_topic_if_requested(
            [ValueSource(nameof(ObjectsWithAlternativeId))]
            object entity
            )
        {
            const string idPropertyName = nameof(AnotherKeyEntity <object> .AlternativeId);
            var          topic          = entity.GetType().GetProperty(idPropertyName)?.GetValue(entity)?.ToString() ?? string.Empty;
            var          manager        = EntityManagerFactory.Create(entity, idPropertyName, _pump.Object);

            Assert.That(manager.Topic, Is.EqualTo(topic), $"{nameof(manager.Topic)} should be {topic}");
            _pump.Verify(x => x.Connect(topic, manager), $"{topic} should be passed to pump as topic");
        }
Esempio n. 6
0
        public void use_specified_topic_instead_of_id_if_provided(
            [ValueSource(nameof(ObjectsWithNoObviousId))]
            [ValueSource(nameof(ObjectsWithRegularId))]
            object entity
            )
        {
            var topic   = Guid.NewGuid().ToString().Substring(0, 4);
            var manager = EntityManagerFactory.Create(entity, _pump.Object, topic);

            Assert.That(manager.Topic, Is.EqualTo(topic), $"{nameof(manager.Topic)} should be {topic}");
            _pump.Verify(x => x.Connect(topic, manager), $"{topic} should be passed to pump as topic");
        }
Esempio n. 7
0
        public void distribute_messages_to_local_subscribers()
        {
            var pump      = CreateTestPump();
            var topic     = Guid.NewGuid().ToString();
            var manager1  = EntityManagerFactory.Create(new TestEntity(), pump, topic);
            var manager2  = EntityManagerFactory.Create(new TestEntity(), pump, topic);
            var manager3  = EntityManagerFactory.Create(new TestEntity(), pump, topic);
            var testValue = Guid.NewGuid().ToString();

            Assert.That(manager2.Entity.Name, Is.Not.EqualTo(testValue));
            Assert.That(manager3.Entity.Name, Is.Not.EqualTo(testValue));

            manager1.Entity.Name = testValue;
            manager1.Commit();
            Assert.That(manager2.Entity.Name, Is.EqualTo(testValue), nameof(manager2));
            Assert.That(manager3.Entity.Name, Is.EqualTo(testValue), nameof(manager3));
        }
Esempio n. 8
0
        public void send_all_existing_messages_for_a_topic_to_a_new_local_handler()
        {
            var pump      = CreateTestPump();
            var topic     = Guid.NewGuid().ToString();
            var entity1   = new TestEntity();
            var firstName = entity1.Name;
            var manager1  = EntityManagerFactory.Create(entity1, pump, topic);

            manager1.Commit();

            var entity2 = new TestEntity();

            Assume.That(entity2.Name, Is.Not.EqualTo(firstName));

            var manager2 = EntityManagerFactory.Create(entity2, pump, topic);

            Assert.That(entity2.Name, Is.EqualTo(firstName));
        }
Esempio n. 9
0
 private EntityManager <TestEntity> CreateTestEntityManager()
 {
     return(EntityManagerFactory.Create(_testEntity, _pump.Object));
 }
Esempio n. 10
0
 protected BaseContext(IDatabaseModelContext context)
 {
     databaseContext = context;
     entityManager   = EntityManagerFactory.Create <TEntity>(databaseContext.ObjectContext);
 }