#region License



#endregion

using System;
using System.Net;
using System.Text;

using Spring.Http;
using Spring.Util;

using NUnit.Framework;

namespace Spring.Rest.Client
{
    /// <summary>
    /// Unit tests for the HttpResponseException class.
    /// </summary>
    /// <author>Bruno Baia</author>
    [TestFixture]
    public class HttpResponseExceptionTests
    {
        [Test]
        public void BinarySerialization()
        {
            Uri requestUri = new Uri("http://www.springframework.net");
            HttpMethod requestMethod = HttpMethod.POST;
            byte[] body = new byte[2] { 0, 1 };
            HttpHeaders headers = new HttpHeaders();
            headers.ContentType = new MediaType("text", "plain");
            HttpStatusCode statusCode = HttpStatusCode.Accepted;
            string statusDescription = "Accepted description";

            HttpResponseException exBefore = new HttpResponseException(requestUri, requestMethod, 
                new HttpResponseMessage<byte[]>(body, headers, statusCode, statusDescription));

            HttpResponseException exAfter = SerializationTestUtils.BinarySerializeAndDeserialize(exBefore) as HttpResponseException;

            Assert.IsNotNull(exAfter);
            Assert.AreEqual(requestUri, exAfter.RequestUri, "Invalid request URI");
            Assert.AreEqual(requestMethod, exAfter.RequestMethod, "Invalid request method");
            Assert.AreEqual(body, exAfter.Response.Body, "Invalid response body");
            Assert.AreEqual(new MediaType("text", "plain"), exAfter.Response.Headers.ContentType, "Invalid response headers");
            Assert.AreEqual(statusCode, exAfter.Response.StatusCode, "Invalid status code");
            Assert.AreEqual(statusDescription, exAfter.Response.StatusDescription, "Invalid status description");
        }
    }
}
