async Task AbandonCompleteFireEvents()
        {
            await ServiceBusScope.UsingQueueAsync(partitioned : false, sessionEnabled : false, async queueName =>
            {
                this.queueClient = new QueueClient(TestUtility.NamespaceConnectionString, queueName, ReceiveMode.PeekLock);

                await TestUtility.SendMessagesAsync(this.queueClient.InnerSender, 1);
                var messages = await TestUtility.ReceiveMessagesAsync(this.queueClient.InnerReceiver, 1);

                this.listener.Enable((name, queue, arg) => name.Contains("Abandon") || name.Contains("Complete"));
                await TestUtility.AbandonMessagesAsync(this.queueClient.InnerReceiver, messages);

                messages = await TestUtility.ReceiveMessagesAsync(this.queueClient.InnerReceiver, 1);

                await TestUtility.CompleteMessagesAsync(this.queueClient.InnerReceiver, messages);

                Assert.True(this.events.TryDequeue(out var abandonStart));
                AssertAbandonStart(queueName, abandonStart.eventName, abandonStart.payload, abandonStart.activity, null);

                Assert.True(this.events.TryDequeue(out var abandonStop));
                AssertAbandonStop(queueName, abandonStop.eventName, abandonStop.payload, abandonStop.activity,
                                  abandonStart.activity);

                Assert.True(this.events.TryDequeue(out var completeStart));
                AssertCompleteStart(queueName, completeStart.eventName, completeStart.payload, completeStart.activity, null);

                Assert.True(this.events.TryDequeue(out var completeStop));
                AssertCompleteStop(queueName, completeStop.eventName, completeStop.payload, completeStop.activity,
                                   completeStart.activity, null);

                Assert.True(this.events.IsEmpty);
            });
        }
Exemplo n.º 2
0
        public async Task AbandonCompleteFireEvents()
        {
            await ServiceBusScope.UsingQueueAsync(partitioned : false, sessionEnabled : false, async queueName =>
            {
                var queueClient = new QueueClient(TestUtility.NamespaceConnectionString, queueName, ReceiveMode.PeekLock);
                var eventQueue  = this.CreateEventQueue();

                try
                {
                    using (var listener = this.CreateEventListener(queueName, eventQueue))
                        using (var subscription = this.SubscribeToEvents(listener))
                        {
                            await TestUtility.SendMessagesAsync(queueClient.InnerSender, 1);
                            var messages = await TestUtility.ReceiveMessagesAsync(queueClient.InnerReceiver, 1);

                            listener.Enable((name, queue, arg) => name.Contains("Abandon") || name.Contains("Complete"));
                            await TestUtility.AbandonMessagesAsync(queueClient.InnerReceiver, messages);

                            messages = await TestUtility.ReceiveMessagesAsync(queueClient.InnerReceiver, 1);

                            await TestUtility.CompleteMessagesAsync(queueClient.InnerReceiver, messages);

                            Assert.True(eventQueue.TryDequeue(out var abandonStart));
                            AssertAbandonStart(queueName, abandonStart.eventName, abandonStart.payload, abandonStart.activity, null);

                            Assert.True(eventQueue.TryDequeue(out var abandonStop));
                            AssertAbandonStop(queueName, abandonStop.eventName, abandonStop.payload, abandonStop.activity, abandonStart.activity);

                            Assert.True(eventQueue.TryDequeue(out var completeStart));
                            AssertCompleteStart(queueName, completeStart.eventName, completeStart.payload, completeStart.activity, null);

                            Assert.True(eventQueue.TryDequeue(out var completeStop));
                            AssertCompleteStop(queueName, completeStop.eventName, completeStop.payload, completeStop.activity, completeStart.activity, null);

                            Assert.True(eventQueue.IsEmpty, "There were events present when none were expected");
                        }
                }
                finally
                {
                    await queueClient.CloseAsync();
                }
            });
        }