예제 #1
0
        /// <summary>
        /// Stores a response message for later retrieval
        /// </summary>
        /// <param name="response">The response message to store</param>
        /// <returns>Task</returns>
        /// <exception cref="ArgumentNullException"/>
        public async Task StoreResponse(HttpResponseMessage response)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            var resourcePath = _formatter.ToResourcePath(response.RequestMessage.RequestUri);

            // this is the object that is serialized (response, normalized request query and pointer to the content file)
            var info = _formatter.PackageResponse(response);

            // get the content stream loaded and serialize it
            await response.Content.LoadIntoBufferAsync();

            var content = await _formatter.Callbacks.Serializing(response);

            _resources.Store(resourcePath, info.ContentFileName, content);

            // now serialize the response object and its meta-data
            var fileName = _formatter.ToName(response.RequestMessage);
            var json     = JsonConvert.SerializeObject(info, Formatting.Indented, new VersionConverter());

            _resources.Store(resourcePath, fileName + ".response.json", json);
        }