public void StringEventListenerReceivesProperString(string text) { // Arrange var testContext = new TestBusContext(); var hostBuilder = new MicroserviceHostBuilder().WithBusContext(testContext); using var host = hostBuilder .WithQueueName("test.queue") .AddEventListener <StringEventListenerDummy>() .CreateHost(); host.Start(); //Act var message = new DummyEvent("test.topic") { DummyText = text }; new EventPublisher(testContext).Publish(message); // Assert Thread.Sleep(WaitTime); var expectedResult = JsonConvert.SerializeObject(message); Assert.AreEqual(expectedResult, StringEventListenerDummy.ReceivedData); }
public void WithQueueNameSetsQueueProperly(string queueName) { // Arrange var host = new MicroserviceHostBuilder(); // Act host.WithQueueName(queueName); // Assert Assert.AreEqual(queueName, host.QueueName); }
public void AddingListenerRegistersProperReceiver() { // Arrange var testContext = new TestBusContext(); var hostBuilder = new MicroserviceHostBuilder().WithBusContext(testContext); // Act hostBuilder.AddEventListener <EventListenerDummy>(); hostBuilder.WithQueueName("test.queue"); hostBuilder.CreateHost().Start(); // Assert var message = new DummyEvent("TestTopic"); new EventPublisher(testContext).Publish(message); Thread.Sleep(WaitTime); Assert.AreEqual(message, EventListenerDummy.HandlesResult); }
public void EventListenerWithReturnsInvalidOperationException() { //Arrange var testContext = new TestBusContext(); var hostBuilder = new MicroserviceHostBuilder().WithBusContext(testContext); using var host = hostBuilder .WithQueueName("test.queue") .AddEventListener <MissingDependencyEventListener>() .CreateHost(); var eventListener = host.Listeners.First(); //Act void Act() => eventListener.Callback.Invoke(new EventMessage()); //Assert var exception = Assert.ThrowsException <InvalidOperationException>(Act); bool containsErrorMessage = exception.Message.Contains( "Unable to resolve service for type 'Miffy.MicroServices.Test.Component.EventListeners.MethodEventListener"); Assert.IsTrue(containsErrorMessage); }
public void CommandListenerWithNullReturnsNullProperly(string text) { // Arrange var testContext = new TestBusContext(); var hostBuilder = new MicroserviceHostBuilder().WithBusContext(testContext); using var host = hostBuilder .WithQueueName("test.queue") .AddEventListener <NullCommandListener>() .CreateHost(); host.Start(); var publisher = new CommandPublisher(testContext); var message = new DummyCommand { Text = text }; //Act var result = publisher.PublishAsync <DummyCommand>(message); // Assert Assert.IsNull(result.Result); }