<commit_before>﻿using Moq;
using RestEase;
using RestEase.Implementation;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace RestEaseUnitTests.ImplementationFactoryTests
{
    public class DefaultValueTests
    {
        public interface IHasDefaultValue
        {
            [Get("foo")]
            Task GetFooAsync(string foo = "", int bar = 3);
        }

        public interface IHasDefaultCancellationToken
        {
            [Get("foo")]
            Task GetFooAsync(CancellationToken cancellationToken = default);
        }

        private readonly Mock<IRequester> requester = new Mock<IRequester>(MockBehavior.Strict);
        private readonly EmitImplementationFactory factory = EmitImplementationFactory.Instance;

        [Fact]
        public void PreservesParameterNamesAndDefaultValues()
        {
            var implementation = this.factory.CreateImplementation<IHasDefaultValue>(this.requester.Object);

            var methodInfo = implementation.GetType().GetMethod("GetFooAsync");
            var parameters = methodInfo.GetParameters();

            Assert.Equal("foo", parameters[0].Name);
            Assert.Equal(ParameterAttributes.Optional | ParameterAttributes.HasDefault, parameters[0].Attributes);
            Assert.Equal(string.Empty, parameters[0].DefaultValue);

            Assert.Equal("bar", parameters[1].Name);
            Assert.Equal(ParameterAttributes.Optional | ParameterAttributes.HasDefault, parameters[1].Attributes);
            Assert.Equal(3, parameters[1].DefaultValue);
        }

        [Fact]
        public void HandlesDefaultStructValues()
        {
            this.factory.CreateImplementation<IHasDefaultCancellationToken>(this.requester.Object);
        }

    }
}<commit_msg>DefaultValueTests pass<commit_after>﻿using Moq;
using RestEase;
using RestEase.Implementation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace RestEaseUnitTests.ImplementationFactoryTests
{
    public class DefaultValueTests : ImplementationFactoryTestsBase
    {
        public interface IHasDefaultValue
        {
            [Get("foo")]
            Task GetFooAsync(string foo = "", int bar = 3, float? baz = null);
        }

        public interface IHasDefaultCancellationToken
        {
            [Get("foo")]
            Task GetFooAsync(CancellationToken cancellationToken = default);
        }

        public DefaultValueTests(ITestOutputHelper output) : base(output) { }

        [Fact]
        public void PreservesParameterNamesAndDefaultValues()
        {
            var implementation = this.CreateImplementation<IHasDefaultValue>();

            var methodInfo = implementation.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Single(x => x.Name.EndsWith(".GetFooAsync"));
            var parameters = methodInfo.GetParameters();

            Assert.Equal("foo", parameters[0].Name);
            Assert.Equal(ParameterAttributes.Optional | ParameterAttributes.HasDefault, parameters[0].Attributes);
            Assert.Equal(string.Empty, parameters[0].DefaultValue);

            Assert.Equal("bar", parameters[1].Name);
            Assert.Equal(ParameterAttributes.Optional | ParameterAttributes.HasDefault, parameters[1].Attributes);
            Assert.Equal(3, parameters[1].DefaultValue);

            Assert.Equal("baz", parameters[2].Name);
            Assert.Equal(ParameterAttributes.Optional | ParameterAttributes.HasDefault, parameters[2].Attributes);
            Assert.Null(parameters[2].DefaultValue);
        }

        [Fact]
        public void HandlesDefaultStructValues()
        {
            this.CreateImplementation<IHasDefaultCancellationToken>();
        }

    }
}
{'fraction_non_alphanumeric': 0.09640974140095405, 'fraction_numerical': 0.004770273663068039, 'mean_word_length': 3.0446700507614213, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, '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': '2562269', 'n_tokens_mistral': 986, 'n_tokens_neox': 975, 'n_words': 183}