public async Task AzureServiceBusServer_Working_AsExpected()
        {
            var  queueClient = new QueueClient(_configuration["ConnectionString"], "cqelight");
            bool finished    = false;
            var  evtToSend   = new AzureEvent {
                Data = "evt_data"
            };

            var server = new AzureServiceBusServer(CONST_APP_ID_SERVER, _loggerFactory.Object,
                                                   new AzureServiceBusServerConfiguration(_configuration["ConnectionString"],
                                                                                          new QueueConfiguration(new JsonDispatcherSerializer(), "cqelight", false,
                                                                                                                 o =>
            {
                if (o is IDomainEvent receivedEvt)
                {
                    finished = receivedEvt.GetType() == typeof(AzureEvent) && (receivedEvt.As <AzureEvent>().Data) == "evt_data";
                }
            })));


            var client = new AzureServiceBusClient(CONST_APP_ID_CLIENT, queueClient, new AzureServiceBusClientConfiguration(
                                                       _configuration["ConnectionString"], null, null));
            await client.PublishEventAsync(evtToSend).ConfigureAwait(false);

            int currentWait = 0;

            while (!finished && currentWait <= 2000)
            {
                currentWait += 50;
                await Task.Delay(50).ConfigureAwait(false);
            }
            finished.Should().BeTrue();
        }
Exemple #2
0
        public async Task AzureServiceBusClient_PublishEvent_AsExpected()
        {
            var queueClient = new QueueClient(_configuration["ConnectionString"], "cqelight");

            var client = new AzureServiceBusClient("DA8C3F43-36C5-45F8-A773-1F11C0B77223", queueClient, new AzureServiceBusClientConfiguration(
                                                       _configuration["ConnectionString"], null, null));

            await client.PublishEventAsync(new AzureEvent { Data = "test event data" });

            bool hasCorrectlyReceived = false;

            queueClient.RegisterMessageHandler((m, c) =>
            {
                hasCorrectlyReceived = m.ContentType == typeof(AzureEvent).AssemblyQualifiedName &&
                                       m.Body != null;

                var evt = Encoding.UTF8.GetString(m.Body).FromJson <AzureEvent>();

                hasCorrectlyReceived &= evt != null && evt.Data == "test event data";

                return(Task.CompletedTask);
            }, new MessageHandlerOptions(e =>
            {
                hasCorrectlyReceived = false;
                return(Task.CompletedTask);
            }));

            int elapsedTime = 0;

            while (!hasCorrectlyReceived && elapsedTime < 2000)
            {
                elapsedTime += 50;
                await Task.Delay(50);
            }

            hasCorrectlyReceived.Should().BeTrue();
        }