/// <summary>
        /// Writes the payload to the stream using the given callback, then verifies the payload using the test deserializer
        /// </summary>
        /// <param name="originalPayload">The payload being tested, of which a copy will be made</param>
        /// <param name="message">The stream to write to</param>
        /// <param name="odataVersion">The OData protocol version to be used for writing payloads.</param>
        /// <param name="format">The current format</param>
        /// <param name="writeToStream">The callback to write to the stream</param>
        private void WriteAndLogODataPayload(ODataPayloadElement originalPayload, TestMessage message, ODataVersion odataVersion, ODataFormat format, Action <ODataPayloadElement> writeToStream)
        {
            ExceptionUtilities.CheckArgumentNotNull(originalPayload, "originalPayload");
            ExceptionUtilities.CheckArgumentNotNull(writeToStream, "writeToStream");

            // This is needed because we may modify the payload in use but the same is used in another iteration of the combinatorial engine
            var payload = originalPayload.DeepCopy();

            WriteToStream(format, writeToStream, payload);
            var newPayload = TestWriterUtils.ReadToString(message);

            this.Logger.LogPayload(newPayload);
        }
        private static string WriteToStream(ODataFormat format, Action <ODataPayloadElement> writeToStream, ODataPayloadElement payload)
        {
            string contentType = null;

            if (format == ODataFormat.Json)
            {
                payload.Accept(new ODataPayloadJsonNormalizer());
                contentType = MimeTypes.ApplicationJsonLight;
            }
            else
            {
                ExceptionUtilities.Assert(format == ODataFormat.Atom, "Format not supported: {0}", format);
                contentType = MimeTypes.ApplicationAtomXml;
            }

            writeToStream(payload);
            return(contentType);
        }