<commit_before>﻿using System;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
using Newtonsoft.Json;
using Xunit.Sdk;

namespace CompatibleSoftware.QuotingTool.API.Tests
{
    public class CustomerJsonTests : IDisposable
    {
        private readonly HttpApplication _httpApplication;

        public CustomerJsonTests()
        {
            _httpApplication = new HttpApplication();
        }

        public void Dispose()
        {
            _httpApplication.Dispose();
        }

        [Fact]
        public void GetResponseReturnsCorrectStatusCode()
        {
            using (var client = _httpApplication.GetClient())
            {
                var response = client.GetAsync("").Result;

                Assert.True(
                    response.IsSuccessStatusCode,
                    "Actual Status Code: " + response.StatusCode);
            }
        }

        [Fact]
        public void PostResponseReturnsCorrectStatusCode()
        {
            using (var client = _httpApplication.GetClient())
            {
                var json = new
                {
                    name = "Customer 1",
                    createdBy = "Admin",
                    createdDate = DateTimeOffset.Now
                };

                var response = client.PostAsJsonAsync("", json).Result;

                Assert.True(
                    response.IsSuccessStatusCode,
                    "Actual Status Code: " + response.StatusCode);
            }
        }

        [Fact]
        [UseDatabase]
        public void GetAfterPostReturnsResponseWithPostedEntry()
        {
            using (var client = _httpApplication.GetClient())
            {
                var json = new
                {
                    name = "Customer 2",
                    createdBy = "Bob",
                    createdDate = DateTimeOffset.Now
                };

                var expected = json.ToJObject();
                client.PostAsJsonAsync("", json).Wait();

                var response = client.GetAsync("").Result;

                var actual = response.Content.ReadAsJsonAsync().Result;

                Assert.Contains(expected, actual.Entries);
            }
        }
    }

    public class UseDatabaseAttribute : BeforeAfterTestAttribute
    {
        public override void Before(MethodInfo methodUnderTest)
        {
            base.Before(methodUnderTest);
        }

        public override void After(MethodInfo methodUnderTest)
        {<commit_msg>Fix for broken test<commit_after>﻿using System;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
using Newtonsoft.Json;
using Xunit.Sdk;

namespace CompatibleSoftware.QuotingTool.API.Tests
{
    public class CustomerJsonTests : IDisposable
    {
        private readonly HttpApplication _httpApplication;

        public CustomerJsonTests()
        {
            _httpApplication = new HttpApplication();
        }

        public void Dispose()
        {
            _httpApplication.Dispose();
        }

        [Fact]
        public void GetResponseReturnsCorrectStatusCode()
        {
            using (var client = _httpApplication.GetClient())
            {
                var response = client.GetAsync("").Result;

                Assert.True(
                    response.IsSuccessStatusCode,
                    "Actual Status Code: " + response.StatusCode);
            }
        }

        [Fact]
        public void PostResponseReturnsCorrectStatusCode()
        {
            using (var client = _httpApplication.GetClient())
            {
                var json = new
                {
                    name = "Customer 1",
                    createdBy = "Admin",
                    createdDate = DateTimeOffset.Now
                };

                var response = client.PostAsJsonAsync("", json).Result;

                Assert.True(
                    response.IsSuccessStatusCode,
                    "Actual Status Code: " + response.StatusCode);
            }
        }

        [Fact]
        [UseDatabase]
        public void GetAfterPostReturnsResponseWithPostedEntry()
        {
            using (var client = _httpApplication.GetClient())
            {
                var json = new
                {
                    name = "Customer 2",
                    createdBy = "Bob",
                    createdDate = DateTimeOffset.Now
                };

                var expected = json.ToJObject();
                client.PostAsJsonAsync("", json).Wait();

                var response = client.GetAsync("").Result;

                var actual = response.Content.ReadAsJsonAsync().Result;

                Assert.Contains(expected, actual.entries);
            }
        }
    }

    public class UseDatabaseAttribute : BeforeAfterTestAttribute
    {
        public override void Before(MethodInfo methodUnderTest)
        {
            base.Before(methodUnderTest);
        }

        public override void After(MethodInfo methodUnderTest)
        {
{'fraction_non_alphanumeric': 0.07971586424625099, 'fraction_numerical': 0.0007892659826361484, 'mean_word_length': 1.4559108527131783, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3144611', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1137, 'n_words': 253}