<commit_before>﻿using System;
using NUnit.Framework;
using System.Text;

namespace RestSharp.Tests
{
    /// <summary>
    /// Note: These tests do not handle QueryString building, which is handled in Http, not RestClient
    /// </summary>
    [TestFixture]
    public class UrlBuilderTests
    {
        [Test]
        public void Should_not_duplicate_question_mark()
        {
            RestRequest request = new RestRequest();

            request.AddParameter("param2", "value2");

            RestClient client = new RestClient("http://example.com/resource?param1=value1");
            Uri expected = new Uri("http://example.com/resource?param1=value1&param2=value2");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void GET_with_leading_slash()
        {
            RestRequest request = new RestRequest("/resource");
            RestClient client = new RestClient(new Uri("http://example.com"));
            Uri expected = new Uri("http://example.com/resource");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void POST_with_leading_slash()
        {
            RestRequest request = new RestRequest("/resource", Method.POST);
            RestClient client = new RestClient(new Uri("http://example.com"));
            Uri expected = new Uri("http://example.com/resource");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void GET_with_leading_slash_and_baseurl_trailing_slash()
        {
            RestRequest request = new RestRequest("/resource");

            request.AddParameter("foo", "bar");

            RestClient client = new RestClient(new Uri("http://example.com"));
            Uri expected = new Uri("http://example.com/resource?foo=bar");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void GET_wth_trailing_slash_and_query_parameters()
        {
            RestRequest request = new RestRequest("/resource/");
            RestClient client = new RestClient("http://example.com");

            request.AddParameter("foo", "bar");

            Uri expected = new Uri("http://example.com/resource/?foo=bar");
            Uri output = client.BuildUri(request);

            client.Execute(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void GET_with_empty_request_and_query_parameters_without_encoding()
        {
            RestRequest request = new RestRequest();

            request.AddParameter("param2", "bar,baz", ParameterType.QueryStringWithoutEncode);

            RestClient client = new RestClient("http://example.com/resource?param1=value1");
            Uri expected = new Uri("http://example.com/resource?param1=value1&param2=bar,baz");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void POST_with_leading_slash_and_baseurl_trailing_slash()
        {
            RestRequest request = new RestRequest("/resource", Method.POST);
            RestClient client = new RestClient(new Uri("http://example.com"));
            Uri expected = new Uri("http://example.com/resource");
            Uri output = client.BuildUri(request);<commit_msg>URLBuilder test added for query string without encoding updated<commit_after>﻿using System;
using NUnit.Framework;
using System.Text;

namespace RestSharp.Tests
{
    /// <summary>
    /// Note: These tests do not handle QueryString building, which is handled in Http, not RestClient
    /// </summary>
    [TestFixture]
    public class UrlBuilderTests
    {
        [Test]
        public void Should_not_duplicate_question_mark()
        {
            RestRequest request = new RestRequest();

            request.AddParameter("param2", "value2");

            RestClient client = new RestClient("http://example.com/resource?param1=value1");
            Uri expected = new Uri("http://example.com/resource?param1=value1&param2=value2");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void GET_with_leading_slash()
        {
            RestRequest request = new RestRequest("/resource");
            RestClient client = new RestClient(new Uri("http://example.com"));
            Uri expected = new Uri("http://example.com/resource");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void POST_with_leading_slash()
        {
            RestRequest request = new RestRequest("/resource", Method.POST);
            RestClient client = new RestClient(new Uri("http://example.com"));
            Uri expected = new Uri("http://example.com/resource");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void GET_with_leading_slash_and_baseurl_trailing_slash()
        {
            RestRequest request = new RestRequest("/resource");

            request.AddParameter("foo", "bar");

            RestClient client = new RestClient(new Uri("http://example.com"));
            Uri expected = new Uri("http://example.com/resource?foo=bar");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void GET_wth_trailing_slash_and_query_parameters()
        {
            RestRequest request = new RestRequest("/resource/");
            RestClient client = new RestClient("http://example.com");

            request.AddParameter("foo", "bar");

            Uri expected = new Uri("http://example.com/resource/?foo=bar");
            Uri output = client.BuildUri(request);

            client.Execute(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void GET_with_empty_request_and_query_parameters_without_encoding()
        {
            RestRequest request = new RestRequest();

            request.AddQueryParameter("param2", "bar,baz", false);

            RestClient client = new RestClient("http://example.com/resource?param1=value1");
            Uri expected = new Uri("http://example.com/resource?param1=value1&param2=bar,baz");
            Uri output = client.BuildUri(request);

            Assert.AreEqual(expected, output);
        }

        [Test]
        public void POST_with_leading_slash_and_baseurl_trailing_slash()
        {
            RestRequest request = new RestRequest("/resource", Method.POST);
            RestClient client = new RestClient(new Uri("http://example.com"));
            Uri expected = new Uri("http://example.com/resource");
            Uri output = client.BuildUri(request);
{'fraction_non_alphanumeric': 0.11477045908183632, 'fraction_numerical': 0.003992015968063872, 'mean_word_length': 2.3058435438265787, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6065102', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1762, 'n_words': 387}