private static void AssertApolloResponse(
            this MockClientConnection connection,
            ApolloMessageType type,
            string id,
            bool compareId,
            string expectedPayloadJson,
            bool compareJson,
            bool dequeue = true)
        {
            if (connection.ResponseMessageCount == 0)
            {
                Assert.Fail("No messages queued.");
            }

            var message = dequeue ? connection.DequeueNextReceivedMessage() : connection.PeekNextReceivedMessage();
            var str     = Encoding.UTF8.GetString(message.Data);

            var options = new JsonSerializerOptions();

            options.PropertyNameCaseInsensitive = true;
            options.AllowTrailingCommas         = true;
            options.Converters.Add(new ApolloResponseMessageConverter());

            var convertedMessage = System.Text.Json.JsonSerializer.Deserialize <ApolloResponseMessage>(str, options);

            Assert.IsNotNull(convertedMessage, "Could not deserialized response message");
            Assert.AreEqual(type, convertedMessage.Type, $"Expected message type of {type.ToString()} but got {convertedMessage.Type.ToString()}");

            if (compareJson)
            {
                if (expectedPayloadJson == null)
                {
                    Assert.IsNull(convertedMessage.Payload);
                }
                else
                {
                    CommonAssertions.AreEqualJsonStrings(expectedPayloadJson, convertedMessage.Payload);
                }
            }

            if (compareId)
            {
                Assert.AreEqual(id, convertedMessage.Id);
            }
        }