<commit_before>﻿using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Fakes;
using System.Threading.Tasks;
using Microsoft.QualityTools.Testing.Fakes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Xciles.Uncommon.Net;

namespace Xciles.Uncommon.Tests.Net
{
    [TestClass]
    public class UncommonRequestHelperExceptionTests
    {
        private readonly Person _person = new Person
        {
            DateOfBirth = DateTime.Now.Subtract(new TimeSpan(800, 1, 1, 1)),
            Firstname = "First",
            Lastname = "Person",
            PhoneNumber = "0123456789",
            SomeString = "This is just a string"
        };

        [TestMethod]
        public void ProcessGetRequestWebExceptionTest()
        {
            ProcessGetRequestWebExceptionTestAsync().Wait();
        }

        private async Task ProcessGetRequestWebExceptionTestAsync()
        {
            var exceptionObject = new ExceptionObject()
            {
                Description = "This is a test Exception Description",
                Message = "This is a test Exception Message",
                Type = EType.WrongHeaders
            };

            using (ShimsContext.Create())
            {

                ShimHttpClient.AllInstances.SendAsyncHttpRequestMessageCancellationToken = (client, message, arg3) =>
                {
                    return Task.FromResult(new HttpResponseMessage()
                    {
                        Content = new StringContent(JsonConvert.SerializeObject(exceptionObject)),
                        StatusCode = HttpStatusCode.BadRequest
                    });
                };

                try
                {
                    var result = await UncommonRequestHelper.ProcessGetRequestAsync<Person>("http://www.xciles.com/");
                    Assert.Fail("Should not be able to be here...");
                }
                catch (UncommonRequestException ex)
                {
                    Assert.IsTrue(ex.RequestExceptionStatus == EUncommonRequestExceptionStatus.ServiceError);
                    Assert.IsTrue(ex.ServiceExceptionResult == null);
                    Assert.IsTrue(ex.StatusCode == HttpStatusCode.BadRequest);

                    var responseResult = ex.ConvertExceptionResponseToObject<ExceptionObject>();
                    Assert.IsTrue(responseResult != null);
                    Assert.IsTrue(responseResult.Description == exceptionObject.Description);
                    Assert.IsTrue(responseResult.Message == exceptionObject.Message);
                    Assert.IsTrue(responseResult.Type == exceptionObject.Type);
                }
            }
        }



        [TestMethod]
        public void ProcessGetRequestHttpRequestExceptionTest()
        {
            ProcessGetRequestHttpRequestExceptionTestAsync().Wait();
        }

        private async Task ProcessGetRequestHttpRequestExceptionTestAsync()
        {
            var exceptionObject = new ExceptionObject()
            {
                Description = "This is a test Exception Description",
                Message = "This is a test Exception Message",
                Type = EType.WrongHeaders
            };

            using (ShimsContext.Create())
            {

                ShimHttpClient.AllInstances.SendAsyncHttpRequestMessageCancellationToken = (client, message, arg3) =>
                {
                    throw new HttpRequestException();
                };

                try
                {
                    var result = await UncommonRequestHelper.ProcessGetRequestAsync<Person>("http://www.xciles.com/");
                    Assert.Fail("Should not be able to be here...");
                }
                catch (UncommonRequestException ex)
                {
                    Assert.IsTrue(ex.RequestExceptionStatus == EUncommonRequestExceptionStatus.ServiceError);
                    Assert.IsTrue(ex.ServiceExceptionResult == null);
                    Assert.IsTrue(ex.StatusCode == HttpStatusCode.BadRequest);

                    //var responseResult = ex.ConvertExceptionResponseToObject<ExceptionObject>();
                    //Assert.IsTrue(responseResult != null);
                    //Assert.IsTrue(responseResult.Description == exceptionObject.Description);
                    //Assert.IsTrue(responseResult.Message == exceptionObject.Message);
                    //Assert.IsTrue(responseResult.Type == exceptionObject.Type);
                }
            }
        }
    }
}
<commit_msg>Adding a tiny bit of extra lines of code for tomorrow!<commit_after>﻿using System;
using System.Net;
using System.Net.Fakes;
using System.Net.Http;
using System.Net.Http.Fakes;
using System.Threading.Tasks;
using Microsoft.QualityTools.Testing.Fakes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Xciles.Uncommon.Net;

namespace Xciles.Uncommon.Tests.Net
{
    [TestClass]
    public class UncommonRequestHelperExceptionTests
    {
        private readonly Person _person = new Person
        {
            DateOfBirth = DateTime.Now.Subtract(new TimeSpan(800, 1, 1, 1)),
            Firstname = "First",
            Lastname = "Person",
            PhoneNumber = "0123456789",
            SomeString = "This is just a string"
        };

        [TestMethod]
        public void ProcessGetRequestWebExceptionTest()
        {
            ProcessGetRequestWebExceptionTestAsync().Wait();
        }

        private async Task ProcessGetRequestWebExceptionTestAsync()
        {
            var exceptionObject = new ExceptionObject()
            {
                Description = "This is a test Exception Description",
                Message = "This is a test Exception Message",
                Type = EType.WrongHeaders
            };

            using (ShimsContext.Create())
            {

                ShimHttpClient.AllInstances.SendAsyncHttpRequestMessageCancellationToken = (client, message, arg3) =>
                {
                    return Task.FromResult(new HttpResponseMessage()
                    {
                        Content = new StringContent(JsonConvert.SerializeObject(exceptionObject)),
                        StatusCode = HttpStatusCode.BadRequest
                    });
                };

                try
                {
                    var result = await UncommonRequestHelper.ProcessGetRequestAsync<Person>("http://www.xciles.com/");
                    Assert.Fail("Should not be able to be here...");
                }
                catch (UncommonRequestException ex)
                {
                    Assert.IsTrue(ex.RequestExceptionStatus == EUncommonRequestExceptionStatus.ServiceError);
                    Assert.IsTrue(ex.ServiceExceptionResult == null);
                    Assert.IsTrue(ex.StatusCode == HttpStatusCode.BadRequest);

                    var responseResult = ex.ConvertExceptionResponseToObject<ExceptionObject>();
                    Assert.IsTrue(responseResult != null);
                    Assert.IsTrue(responseResult.Description == exceptionObject.Description);
                    Assert.IsTrue(responseResult.Message == exceptionObject.Message);
                    Assert.IsTrue(responseResult.Type == exceptionObject.Type);
                }
            }
        }



        [TestMethod]
        public void ProcessGetRequestHttpRequestExceptionTest()
        {
            ProcessGetRequestHttpRequestExceptionTestAsync().Wait();
        }

        private async Task ProcessGetRequestHttpRequestExceptionTestAsync()
        {
            var exceptionObject = new ExceptionObject()
            {
                Description = "This is a test Exception Description",
                Message = "This is a test Exception Message",
                Type = EType.WrongHeaders
            };

            using (ShimsContext.Create())
            {

                ShimHttpClient.AllInstances.SendAsyncHttpRequestMessageCancellationToken = (client, message, arg3) =>
                {
                    //var webEx = new WebException("", WebExceptionStatus.UnknownError, )
                    throw new HttpRequestException();
                };

                ShimHttpWebResponse.AllInstances.ResponseStreamGet = (response) =>
                {
                    return ShimsContext.ExecuteWithoutShims(() => response.GetResponseStream());
                };

                try
                {
                    var result = await UncommonRequestHelper.ProcessGetRequestAsync<Person>("http://www.xciles.com/");
                    Assert.Fail("Should not be able to be here...");
                }
                catch (UncommonRequestException ex)
                {
                    Assert.IsTrue(ex.RequestExceptionStatus == EUncommonRequestExceptionStatus.ServiceError);
                    Assert.IsTrue(ex.ServiceExceptionResult == null);
                    Assert.IsTrue(ex.StatusCode == HttpStatusCode.BadRequest);

                    //var responseResult = ex.ConvertExceptionResponseToObject<ExceptionObject>();
                    //Assert.IsTrue(responseResult != null);
                    //Assert.IsTrue(responseResult.Description == exceptionObject.Description);
                    //Assert.IsTrue(responseResult.Message == exceptionObject.Message);
                    //Assert.IsTrue(responseResult.Type == exceptionObject.Type);
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.08379770791714856, 'fraction_numerical': 0.003785090947324151, 'mean_word_length': 1.7317633543940265, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5322305', 'n_tokens_mistral': 2217, 'n_tokens_neox': 2079, 'n_words': 408}