public async Task TestUnsubscribeExclusiveDurableSubWhileActiveThenInactive()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = await EstablishConnectionAsync(testPeer);

                await connection.StartAsync();

                testPeer.ExpectBegin();
                ISession session = await connection.CreateSessionAsync(AcknowledgementMode.AutoAcknowledge);

                String topicName = "myTopic";
                ITopic dest      = await session.GetTopicAsync("myTopic");

                String subscriptionName = "mySubscription";

                // Attach the durable exclusive receiver
                testPeer.ExpectDurableSubscriberAttach(topicName: topicName, subscriptionName: subscriptionName);
                testPeer.ExpectLinkFlow();

                IMessageConsumer consumer = await session.CreateDurableConsumerAsync(dest, subscriptionName, null, false);

                Assert.NotNull(consumer, "TopicSubscriber object was null");

                // Now try to unsubscribe, should fail
                Assert.CatchAsync <NMSException>(async() => session.DeleteDurableConsumer(subscriptionName));

                // Now close the subscriber
                testPeer.ExpectDetach(expectClosed: false, sendResponse: true, replyClosed: false);

                await consumer.CloseAsync();

                // Try to unsubscribe again, should work now
                testPeer.ExpectDurableSubUnsubscribeNullSourceLookup(failLookup: false, shared: false, subscriptionName: subscriptionName, topicName: topicName, hasClientId: true);
                testPeer.ExpectDetach(expectClosed: true, sendResponse: true, replyClosed: true);

                session.DeleteDurableConsumer(subscriptionName);

                testPeer.WaitForAllMatchersToComplete(1000);

                testPeer.ExpectClose();
                await connection.CloseAsync();

                testPeer.WaitForAllMatchersToComplete(1000);
            }
        }