<commit_before>namespace Nancy.Tests.Functional.Tests
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using Nancy.Cookies;
    using Nancy.ErrorHandling;
    using Nancy.IO;
    using Nancy.Responses.Negotiation;
    using Nancy.Testing;
    using Nancy.Tests.Functional.Modules;
    using Xunit;
    using Xunit.Extensions;

    public class ContentNegotiationFixture
    {
        [Fact]
        public void Should_return_int_value_from_get_route_as_response_with_status_code_set_to_value()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/int", (x,m) => 200);
            });

            var browser = new Browser(with =>
            {
                with.Module(module);
            });

            // When
            var response = browser.Get("/int");

            // Then
            Assert.Equal((HttpStatusCode)200, response.StatusCode);
        }

        [Fact]
        public void Should_return_string_value_from_get_route_as_response_with_content_set_as_value()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/string", (x, m) => "hello");
            });

            var browser = new Browser(with =>
            {
                with.Module(module);
            });

            // When
            var response = browser.Get("/string");

            // Then
            Assert.Equal("hello", response.Body.AsString());
        }

        [Fact]
        public void Should_return_httpstatuscode_value_from_get_route_as_response_with_content_set_as_value()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/httpstatuscode", (x, m) => HttpStatusCode.Accepted);
            });

            var browser = new Browser(with =>
            {
                with.Module(module);
            });

            // When
            var response = browser.Get("/httpstatuscode");

            // Then
            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
        }

        [Fact]
        public void Should_return_action_value_as_response_with_content_set_as_value()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/action", (x, m) =>
                {
                    Action<Stream> result = stream =>
                    {
                        var wrapper = new UnclosableStreamWrapper(stream);
                        using (var writer = new StreamWriter(wrapper))
                        {
                            writer.Write("<NAME>!");
                        }
                    };

                    return result;
                });
            });

            var browser = new Browser(with =>
            {
                with.Module(module);
            });

            // When
            var response = browser.Get("/action");

            // Then
            Assert.Equal("Hi<NAME>!", response.Body.AsString());
        }

        [Fact]
        public void Should_add_negotiated_headers_to_response()
        {
            // Given

            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/headers", (x, m) =>
                {
                    var context =
                        new NancyContext();

                    var negotiator =
                        new Negotiator(context);
                    negotiator.WithHeader("foo", "bar");

                    return negotiator;
                });
            });

            var brower = new Browser(with =>
            {
                with.ResponseProcessor<TestProcessor>();

                with.Module(module);
            });

            // When
            var response = brower.Get("/headers");

            // Then
            Assert.True(response.Headers.ContainsKey("foo"));
            Assert.Equal("bar", response.Headers["foo"]);
        }

        [Fact]
        public void Should_set_reason_phrase_on_response()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/customPhrase", (x, m) =>
                {
                    var context =
                        new NancyContext();

                    var negotiator =
                        new Negotiator(context);
                    negotiator.WithReasonPhrase("The test is passing!");

                    return negotiator;
                });
            });

            var brower = new Browser(with =>
            {
                with.ResponseProcessor<TestProcessor>();

                with.Module(module);
            });

            // When
            var response = brower.Get("/customPhrase");

            // Then
            Assert.Equal("The test is passing!", response.ReasonPhrase);
        }

        [Fact]
        public void Should_add_negotiated_content_headers_to_response()
        {
          // Given
<commit_msg>Tweak test to fail<commit_after>namespace Nancy.Tests.Functional.Tests
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using Nancy.Cookies;
    using Nancy.ErrorHandling;
    using Nancy.IO;
    using Nancy.Responses.Negotiation;
    using Nancy.Testing;
    using Nancy.Tests.Functional.Modules;
    using Xunit;
    using Xunit.Extensions;

    public class ContentNegotiationFixture
    {
        [Fact]
        public void Should_return_int_value_from_get_route_as_response_with_status_code_set_to_value()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/int", (x,m) => 200);
            });

            var browser = new Browser(with =>
            {
                with.Module(module);
            });

            // When
            var response = browser.Get("/int");

            // Then
            Assert.Equal((HttpStatusCode)200, response.StatusCode);
        }

        [Fact]
        public void Should_return_string_value_from_get_route_as_response_with_content_set_as_value()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/string", (x, m) => "hello");
            });

            var browser = new Browser(with =>
            {
                with.Module(module);
            });

            // When
            var response = browser.Get("/string");

            // Then
            Assert.Equal("hello", response.Body.AsString());
        }

        [Fact]
        public void Should_return_httpstatuscode_value_from_get_route_as_response_with_content_set_as_value()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/httpstatuscode", (x, m) => HttpStatusCode.Accepted);
            });

            var browser = new Browser(with =>
            {
                with.Module(module);
            });

            // When
            var response = browser.Get("/httpstatuscode");

            // Then
            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
        }

        [Fact]
        public void Should_return_action_value_as_response_with_content_set_as_value()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/action", (x, m) =>
                {
                    Action<Stream> result = stream =>
                    {
                        var wrapper = new UnclosableStreamWrapper(stream);
                        using (var writer = new StreamWriter(wrapper))
                        {
                            writer.Write("<NAME>!");
                        }
                    };

                    return result;
                });
            });

            var browser = new Browser(with =>
            {
                with.Module(module);
            });

            // When
            var response = browser.Get("/action");

            // Then
            Assert.Equal("<NAME>!", response.Body.AsString());
        }

        [Fact]
        public void Should_add_negotiated_headers_to_response()
        {
            // Given

            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/headers", (x, m) =>
                {
                    var context =
                        new NancyContext();

                    var negotiator =
                        new Negotiator(context);
                    negotiator.WithHeader("foo", "bar");

                    return negotiator;
                });
            });

            var brower = new Browser(with =>
            {
                with.ResponseProcessor<TestProcessor>();

                with.Module(module);
            });

            // When
            var response = brower.Get("/headers");

            // Then
            Assert.True(response.Headers.ContainsKey("foo"));
            Assert.Equal("bar", response.Headers["foo"]);
        }

        [Fact]
        public void Should_set_reason_phrase_on_response()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/customPhrase", (x, m) =>
                {
                    var context =
                        new NancyContext();

                    var negotiator =
                        new Negotiator(context);
                    negotiator.WithReasonPhrase("The test is passing!").WithStatusCode(404);

                    return negotiator;
                });
            });

            var brower = new Browser(with =>
            {
                with.StatusCodeHandler<DefaultStatusCodeHandler>();
                with.ResponseProcessor<TestProcessor>();
                with.Module(module);
            });

            // When
            var response = brower.Get("/customPhrase", with => with.Accept("application/json"));

            // Then
            Assert.Equal("The test is passing!", response.ReasonPhrase);
        }

        [Fact]
        public void Should_add_negotiated_content_headers_to_response()
        {
          // Given

{'fraction_non_alphanumeric': 0.09991403190371573, 'fraction_numerical': 0.0014328016047377972, 'mean_word_length': 1.217750476593942, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 53, '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': '7390312', 'n_tokens_mistral': 2620, 'n_tokens_neox': 2452, 'n_words': 460}