/// <summary>
        /// This interface is used to generate a quote from Projects that were uploading using the Add Project API. A quote can contain multiple projects.
        /// </summary>
        /// <param name="projects"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public Quote GenerateQuote(IEnumerable<Project> projects, ProjectQuoteOptions options)
        {
            Quote result = null;

            if (options == null)
            {
                throw new ArgumentNullException("options", "Must specify options to generate a quote");
            }

            Uri uri = new Uri(this.EndPoint.AbsoluteUri + "api/quote/generate");

            options.Initialize(this);

            HttpWebRequest request = this.CreateRequestPOST(uri, new GenerateQuote(projects, options));

            using (HttpWebResponse response = request.GetResponseWithoutException() as HttpWebResponse)
            {
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        XDocument document = XDocument.Load(reader);

                        result = new Quote(document.Element("Quote"), this);
                    }
                }
                else
                {
                    this.HandleError(response);
                }
            }

            return result;
        }
        /// <summary>
        /// This interface authorizes a quote. Only quotes with a status of “Pending” can be authorized.
        /// </summary>
        /// <param name="quote"></param>
        /// <returns></returns>
        public QuoteAuthorization AuthorizeQuote(Quote quote)
        {
            if (quote.Status != "Pending")
            {
                throw new ArgumentException("Only quotes with a status of Pending can be authorized", "quote");
            }

            QuoteAuthorization result = null;

            Uri uri = new Uri(this.EndPoint.AbsoluteUri + "api/quote/" + quote.QuoteID + "/authorize");

            HttpWebRequest request = this.CreateRequestPOST(uri, quote);

            using (HttpWebResponse response = request.GetResponseWithoutException() as HttpWebResponse)
            {
                if (response.StatusCode == HttpStatusCode.Accepted || response.StatusCode == HttpStatusCode.PaymentRequired)
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        XDocument document = XDocument.Load(reader);

                        if (document.Element("QuoteAuthorization") != null)
                        {
                            result = new QuoteAuthorization(document.Element("QuoteAuthorization"), this);
                        }
                        //else if (document.Element("Quote") != null)
                        //{
                        //    result = new QuoteAuthorization(document.Element("Quote"), this);
                        //}
                    }
                }
                else
                {
                    this.HandleError(response);
                }
            }

            return result;
        }
        /// <summary>
        /// This interface is used to generate a quote from Files that were uploading using the Add File API. A quote can contain multiple projects.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="files"></param>
        /// <param name="options"></param>
        /// <param name="referenceFiles">If null, will not use reference files</param>
        /// <returns></returns>
        public Quote GenerateQuote(Service service, IEnumerable<File> files, QuoteOptions options, IEnumerable<File> referenceFiles = null)
        {
            // Check the service
            if (service == null)
            {
                throw new ArgumentNullException("service", "Must specify a Service to generate a quote");
            }

            if (!service.AcceptsFiles)
            {
                throw new ArgumentException("This service does not accept files.  Please use GenerateQuote with Products", "service");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options", "Must specify options to generate a quote");
            }

            options.Initialize(this, service);

            // Now Generate the Quote based on the uplaoded files
            Quote result = null;

            Uri uri = new Uri(this.EndPoint.AbsoluteUri + "api/quote/generate");

            HttpWebRequest request = this.CreateRequestPOST(uri, new GenerateQuote(files, options, referenceFiles));

            using (HttpWebResponse response = request.GetResponseWithoutException() as HttpWebResponse)
            {
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        XDocument document = XDocument.Load(reader);

                        result = new Quote(document.Element("Quote"), this);
                    }
                }
                else
                {
                    this.HandleError(response);
                }
            }

            return result;
        }
        /// <summary>
        /// Updates information about a quote. This is useful for polling
        /// </summary>
        /// <param name="quote"></param>
        /// <returns></returns>
        public void UpdateQuote(Quote quote)
        {
            Uri uri = new Uri(this.EndPoint.AbsoluteUri + "api/quote/" + quote.QuoteID);

            HttpWebRequest request = this.CreateRequestGET(uri);

            using (HttpWebResponse response = request.GetResponseWithoutException() as HttpWebResponse)
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        XDocument document = XDocument.Load(reader);

                        quote.UpdateFromXElement(document.Element("Quote"));
                    }
                }
                else
                {
                    this.HandleError(response);
                }
            }
        }
 /// <summary>
 /// Rejects a quote that has already been created. This deletes the quote.
 /// </summary>
 /// <param name="quote"></param>
 /// <returns></returns>
 public RejectQuoteStatus RejectQuote(Quote quote)
 {
     return this.RejectQuote(quote.QuoteID);
 }
        /// <summary>
        /// Returns information about a quote. This is useful for polling
        /// </summary>
        /// <param name="quoteID"></param>
        /// <returns></returns>
        public Quote GetQuote(int quoteID)
        {
            Quote result = null;

            Uri uri = new Uri(this.EndPoint.AbsoluteUri + "api/quote/" + quoteID);

            HttpWebRequest request = this.CreateRequestGET(uri);

            using (HttpWebResponse response = request.GetResponseWithoutException() as HttpWebResponse)
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        XDocument document = XDocument.Load(reader);

                        result = new Quote(document.Element("Quote"), this);
                    }
                }
                else
                {
                    this.HandleError(response);
                }
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private void CleanupQuoteSetup(ContentAPI client, Quote quote)
        {
            // Never fail (future implementation of ListQuotes will help this)
            try
            {
                RejectQuoteStatus result = client.RejectQuote(quote.QuoteID);

                // Unit test breakpoint line
                if (result == RejectQuoteStatus.Success)
                {
                    result = RejectQuoteStatus.Success;
                }
            }
            catch { }
        }
        public void AuthorizeNullQuoteTest()
        {
            ContentAPI client = ConstructServiceClient();

            Quote authorizeQuote = new Quote(0, DateTime.Now, 0, 0, "", 0m, 0m, 0m, null);
            QuoteAuthorization quoteAuthorization = client.AuthorizeQuote(authorizeQuote);

            Assert.IsNull(quoteAuthorization);
        }