Exemplo n.º 1
0
        public void PublishMessageTest()
        {
            int  numOfMessagesReceived = 0;
            bool finished = false;

            var serviceCollection = new ServiceCollection();
            var names             = new List <string>();

            serviceCollection.AddSingleton(names);
            var executionContext = new ServiceProviderMessageHandlerExecutionContext(serviceCollection);

            using (var bus = new RabbitMessageBus(connectionFactory,
                                                  serializer,
                                                  executionContext,
                                                  "RabbitMQMessageBusTests.PublishMessageTest", queueName: "RabbitMQMessageBusTests.PublishMessageTestQueue"))
            {
                // When any message received, increase the counter
                bus.MessageReceived += (x, y) => numOfMessagesReceived++;

                // When any message acknowledged, stop waiting the do the assertion.
                bus.MessageAcknowledged += (x, y) => finished = true;

                bus.Subscribe <NameChangedEvent, NameChangedEventHandler>();

                var event1 = new NameChangedEvent("daxnet");
                bus.Publish(event1);

                while (!finished)
                {
                    ;
                }
            }

            Assert.Equal(1, numOfMessagesReceived);
        }
Exemplo n.º 2
0
        public void EventMetadataTest2()
        {
            var nameChangedEvent = new NameChangedEvent("daxnet");

            Assert.Equal(typeof(NameChangedEvent).AssemblyQualifiedName, nameChangedEvent.GetMessageClrType());
            Assert.Equal(typeof(NameChangedEvent).Name, nameChangedEvent.GetEventIntent());
        }
        public void LoadEventsTest()
        {
            var aggregateRootId = Guid.NewGuid();
            var employee        = new Employee(aggregateRootId);

            var event1 = new NameChangedEvent("daxnet");
            var event2 = new TitleChangedEvent("title");
            var event3 = new RegisteredEvent();

            event1.AttachTo(employee);
            event2.AttachTo(employee);
            event3.AttachTo(employee);

            var storeConfig       = new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator());
            var payloadSerializer = new ObjectJsonSerializer();
            var store             = new PostgreSqlEventStore(storeConfig, payloadSerializer);

            store.Save(new List <DomainEvent>
            {
                event1,
                event2,
                event3
            });

            var events = store.Load <Guid>(typeof(Employee).AssemblyQualifiedName, aggregateRootId);

            Assert.Equal(3, events.Count());
        }
        public void SaveEventsTest()
        {
            var aggregateRootId = Guid.NewGuid();
            var employee        = new Employee {
                Id = aggregateRootId
            };

            var event1 = new NameChangedEvent("daxnet");
            var event2 = new TitleChangedEvent("title");
            var event3 = new RegisteredEvent();

            event1.AttachTo(employee);
            event2.AttachTo(employee);
            event3.AttachTo(employee);

            var storeConfig       = new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator());
            var payloadSerializer = new ObjectJsonSerializer();
            var store             = new PostgreSqlEventStore(storeConfig, payloadSerializer);

            store.Save(new List <DomainEvent>
            {
                event1,
                event2,
                event3
            });
        }
Exemplo n.º 5
0
        public void ShouldGetNameChangedEventHanlder()
        {
            var nameChangedEvent = new NameChangedEvent("test", "test2");
            var handler          = InstanceFactory.GetInstance <IHandler <NameChangedEvent> >();

            handler.Handle(nameChangedEvent);
        }
Exemplo n.º 6
0
        public void SaveEventsTest1()
        {
            var aggregateRootId = Guid.NewGuid();
            var employee        = new Employee(aggregateRootId);

            var event1 = new NameChangedEvent("daxnet");
            var event2 = new TitleChangedEvent("title");
            var event3 = new RegisteredEvent();

            event1.AttachTo(employee);
            event2.AttachTo(employee);
            event3.AttachTo(employee);

            var store = new DictionaryEventStore();

            store.Save(new List <DomainEvent>
            {
                event1,
                event2,
                event3
            });

            var events = store.Load <Guid>(typeof(Employee).AssemblyQualifiedName, aggregateRootId);

            Assert.Equal(3, events.Count());
            Assert.NotEqual(Guid.Empty, event1.Id);
            Assert.NotEqual(Guid.Empty, event2.Id);
            Assert.NotEqual(Guid.Empty, event3.Id);
        }
        public void PublishMessageTest()
        {
            int  numOfMessagesReceived = 0;
            bool finished = false;

            using (var bus = new MessageBus(new ConnectionFactory()
            {
                HostName = "localhost"
            },
                                            serializer,
                                            "RabbitMQMessageBusTests.PublishMessageTest"))
            {
                // When any message received, increase the counter
                bus.MessageReceived += (x, y) => numOfMessagesReceived++;

                // When any message acknowledged, stop waiting the do the assertion.
                bus.MessageAcknowledged += (x, y) => finished = true;

                bus.Subscribe();

                var event1 = new NameChangedEvent("daxnet");
                bus.Publish(event1);

                while (!finished)
                {
                    ;
                }
            }

            Assert.Equal(1, numOfMessagesReceived);
        }
Exemplo n.º 8
0
        public void EventMetadataTest3()
        {
            var nameChangedEvent = new NameChangedEvent("daxnet");

            Assert.Null(nameChangedEvent.GetOriginatorClrType());
            Assert.Null(nameChangedEvent.GetOriginatorIdentifier());
        }
Exemplo n.º 9
0
        public void LastNameChanged(Object sender, NameChangedEvent args)
        {
            Person p = (Person)sender;

            if (MessageBox.Show("Попытка изменить фамилию " + p.LastName + " на " + args.NewName, "Внимание", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                args.Canceled = true;
            }
        }
Exemplo n.º 10
0
        private void Apply(NameChangedEvent @event, bool isReplaying)
        {
            // Skip if a newer event exists (just to show how it can be done)
            if (!isReplaying && Events.Any(e => e is NameChangedEvent && e.Timestamp > @event.Timestamp))
            {
                return;
            }

            Name = @event.NewName;
        }
    public void Execute()
    {
        User user = _repository.Get(_id)
                    user.Name = _name;

        _repository.Save(user);

        NameChangedEvent e = new NameChangedEvent();

        _publisher.Publish(e);
    }
Exemplo n.º 12
0
        private void Handle(NameChangedEvent nameChangedEvent, string rawJson, EventModel @event, EventMetaData metaData)
        {
            _logger.LogInformation($"Handling {nameof(NameChangedEvent)} .... {Environment.NewLine} {rawJson}");
            _operation          = DatabaseOperation.Update;
            _currentValueRecord = GetRecord(nameChangedEvent.Id);

            ThrowIfRecordIsNull(nameChangedEvent, _currentValueRecord);

            _currentValueRecord.Name = nameChangedEvent.Name;

            UpdateCommonFields(@event, metaData);
        }
Exemplo n.º 13
0
        public void PublishMessageTest()
        {
            var mb = new MessageBus();
            int numOfMessagesReceived = 0;

            mb.MessageReceived += (x, y) => numOfMessagesReceived++;
            mb.Subscribe();
            mb.Subscribe(); // Test subscribe multiple times.

            var event1 = new NameChangedEvent("daxnet");

            mb.Publish(event1);

            Assert.Equal(1, numOfMessagesReceived);
        }
Exemplo n.º 14
0
        public void SerializeAndDeserializeEventTest1()
        {
            var nameChangedEvent = new NameChangedEvent("daxnet");
            var eventId          = nameChangedEvent.Id;

            nameChangedEvent.Timestamp = DateTime.UtcNow;
            var json = JsonConvert.SerializeObject(nameChangedEvent);

            Assert.NotNull(json);

            var deserialized = JsonConvert.DeserializeObject <NameChangedEvent>(json);

            Assert.Equal(eventId, deserialized.Id);
            Assert.Equal(nameChangedEvent.Name, deserialized.Name);
            Assert.Equal(nameChangedEvent.Timestamp, deserialized.Timestamp);
        }
Exemplo n.º 15
0
        public void PublishMessageTest()
        {
            var serviceCollection = new ServiceCollection();
            var messageHandlerExecutionContext = new ServiceProviderMessageHandlerExecutionContext(serviceCollection);

            var mb = new SimpleMessageBus(new MessageJsonSerializer(), messageHandlerExecutionContext);
            int numOfMessagesReceived = 0;

            mb.MessageReceived += (x, y) => numOfMessagesReceived++;

            var event1 = new NameChangedEvent("daxnet");

            mb.Publish(event1);

            Assert.Equal(1, numOfMessagesReceived);
        }
Exemplo n.º 16
0
        public void LoadEventsWithMinMaxSequenceTest()
        {
            var aggregateRootId = Guid.NewGuid();
            var employee        = new Employee(aggregateRootId);

            var event1 = new NameChangedEvent("daxnet")
            {
                Sequence = 1
            };
            var event2 = new TitleChangedEvent("title")
            {
                Sequence = 2
            };
            var event3 = new RegisteredEvent()
            {
                Sequence = 3
            };

            event1.AttachTo(employee);
            event2.AttachTo(employee);
            event3.AttachTo(employee);

            var storeConfig       = new AdoNetEventStoreConfiguration(SQLServerFixture.ConnectionString, new GuidKeyGenerator());
            var payloadSerializer = new ObjectJsonSerializer();
            var store             = new SqlServerEventStore(storeConfig, payloadSerializer);

            store.Save(new List <DomainEvent>
            {
                event1,
                event2,
                event3
            });

            var events = store.Load <Guid>(typeof(Employee).AssemblyQualifiedName, aggregateRootId, 1, 3).ToList();

            Assert.Equal(3, events.Count);
            Assert.IsType <NameChangedEvent>(events[0]);
            Assert.IsType <TitleChangedEvent>(events[1]);
            Assert.IsType <RegisteredEvent>(events[2]);
        }
 private void name_TextChanged(object sender, EventArgs e)
 {
     SetTextboxHeight(nameTextBox.Text);
     NameChangedEvent.Invoke(this); // just let the subscribers know that the text has changed
 }
Exemplo n.º 18
0
        public void ChangeName(string name)
        {
            var e = new NameChangedEvent(name);

            ApplyEvent(e);
        }
Exemplo n.º 19
0
 protected void OnNameChanged(NameChangedEvent e)
 {
     name = e.Name;
 }
Exemplo n.º 20
0
 private void Apply(NameChangedEvent @event)
 {
     Name = @event.Name;
 }
Exemplo n.º 21
0
 public void Handle(NameChangedEvent @event)
 {
     CheckEvent(@event);
     this.ChangeName(@event.Name, applyEvent: false);
 }
Exemplo n.º 22
0
 protected void OnNameChanged(NameChangedEvent e)
 {
     forename = e.Forename;
     surname  = e.Surname;
 }
Exemplo n.º 23
0
        public void EventMetadataTest1()
        {
            var nameChangedEvent = new NameChangedEvent("daxnet");

            Assert.Equal(2, nameChangedEvent.Metadata.Count);
        }
Exemplo n.º 24
0
 private void Handle(NameChangedEvent e)
 {
     Name = e.Name;
 }
Exemplo n.º 25
0
        public void FirstNameChanged(Object sender, NameChangedEvent args)
        {
            Person p = (Person)sender;

            MessageBox.Show("Попытка изменить имя " + p.FirstName + " на " + args.NewName);
        }
Exemplo n.º 26
0
 private void Apply(NameChangedEvent @event) => Name = @event.NewName;
Exemplo n.º 27
0
        public void ChangeName(string forename, string surname)
        {
            var e = new NameChangedEvent(forename, surname);

            ApplyEvent(e);
        }