<commit_before>﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.CodeFixes.GenerateDeconstructMethod;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.GenerateDeconstructMethod
{
    public class GenerateDeconstructMethodTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
    {
        public GenerateDeconstructMethodTests(ITestOutputHelper logger)
           : base(logger)
        {
        }

        internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
            => (null, new GenerateDeconstructMethodCodeFixProvider());

        [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
        public async Task TestDeconstructionDeclaration_Simple()
        {
            await TestInRegularAndScriptAsync(
@"class Class
{
    void Method()
    {
        (int x, int y) = [|this|];
    }
}",
@"using System;

class Class
{
    private void Deconstruct(out int x, out int y)
    {
        throw new NotImplementedException();
    }

    void Method()
    {
        (int x, int y) = this;
    }
}");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
        public async Task TestDeconstructionDeclaration_TypeParameters()
        {
            await TestInRegularAndScriptAsync(
@"class Class<T>
{
    void Method<U>()
    {
        (T x, U y) = [|this|];
    }
}",
@"using System;

class Class<T>
{
    private void Deconstruct(out T x, out object y)
    {
        throw new NotImplementedException();
    }

    void Method<U>()<commit_msg>Add test<commit_after>﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.CodeFixes.GenerateDeconstructMethod;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.GenerateDeconstructMethod
{
    public class GenerateDeconstructMethodTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
    {
        public GenerateDeconstructMethodTests(ITestOutputHelper logger)
           : base(logger)
        {
        }

        internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
            => (null, new GenerateDeconstructMethodCodeFixProvider());

        [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
        public async Task TestDeconstructionDeclaration_Simple()
        {
            await TestInRegularAndScriptAsync(
@"class Class
{
    void Method()
    {
        (int x, int y) = [|this|];
    }
}",
@"using System;

class Class
{
    private void Deconstruct(out int x, out int y)
    {
        throw new NotImplementedException();
    }

    void Method()
    {
        (int x, int y) = this;
    }
}");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
        public async Task TestDeconstructionDeclaration_Simple_Record()
        {
            await TestInRegularAndScriptAsync(
@"record R
{
    void Method()
    {
        (int x, int y) = [|this|];
    }
}",
@"using System;

record R
{
    private void Deconstruct(out int x, out int y)
    {
        throw new NotImplementedException();
    }

    void Method()
    {
        (int x, int y) = this;
    }
}");
        }

        [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
        public async Task TestDeconstructionDeclaration_TypeParameters()
        {
            await TestInRegularAndScriptAsync(
@"class Class<T>
{
    void Method<U>()
    {
        (T x, U y) = [|this|];
    }
}",
@"using System;

class Class<T>
{
    private void Deconstruct(out T x, out object y)
    {
        throw new NotImplementedException();
    }

    void Method<U>()
{'fraction_non_alphanumeric': 0.09188361408882083, 'fraction_numerical': 0.0, 'mean_word_length': 3.1115107913669067, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '5016780', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1266, 'n_words': 332}