Exemplo n.º 1
0
        /// <summary>
        /// Constructor. 
        /// </summary>
        public Simulation()
        {
            Name = "Simulation" + System.Guid.NewGuid().ToString();

            Condition = new SimulationCondition();
            Response = new SimulationResponse();
        }
        /// <summary>
        /// Manufacture a new HttpResponseMessage based on the status code, content, headers and other parameters in the SimulationResponse. 
        /// </summary>
        /// <param name="response">The response. If null, a default HttpResponseMessage is returned. </param>
        /// <returns></returns>
        internal static HttpResponseMessage New(SimulationResponse response)
        {
            var result = new HttpResponseMessage();
            if (response == null) return result;

            result.StatusCode = response.SimulationResponseContent.HttpStatusCode;

            if (response.SimulationResponseContent.Content != null)
            {
                StringContent content = new StringContent(response.SimulationResponseContent.Content);
                result.Content = content;
            }

            if (response.ResponseHeaders != null)
            {
                foreach (var h in response.ResponseHeaders)
                {
                    if (string.Compare(h.Name, "Content-Type", true) == 0)
                    {
                        if (result.Content != null && result.Content.Headers != null)
                        {
                            if (result.Content.Headers.Contains(h.Name))
                            {
                                result.Content.Headers.Remove(h.Name);
                            }
                            result.Content.Headers.Add(h.Name, h.Value);
                        }
                    }
                    else
                    {
                        result.Headers.Add(h.Name, h.Value);
                    }
                }
            }

            return result;
        }
Exemplo n.º 3
0
 public HttpStatusCode Add(SimulationResponse response)
 {
     if (null == response) throw new System.ArgumentNullException("response");
     if (null == response.Simulation) throw new System.ArgumentOutOfRangeException("ERROR: The .Simulation property on response must reference the owner Simulation. ");
     return Add(response.Simulation);
 }