<commit_before>namespace WpfAnalyzers.Test.WPF0014SetValueMustUseRegisteredTypeTests
{
    using Gu.Roslyn.Asserts;
    using NUnit.Framework;

    internal class HappyPath
    {
        private static readonly SetValueAnalyzer Analyzer = new SetValueAnalyzer();

        [TestCase("this.SetValue(BarProperty, 1);")]
        [TestCase("this.SetCurrentValue(BarProperty, 1);")]
        public void DependencyProperty(string setValueCall)
        {
            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
            typeof(int),
            typeof(FooControl),
            new PropertyMetadata(default(int)));

        public int Bar
        {
            get { return (int)GetValue(BarProperty); }
            set { SetValue(BarProperty, value); }
        }

        public void Meh()
        {
            this.SetValue(BarProperty, 1);
        }
    }
}";
            testCode = testCode.AssertReplace("this.SetValue(BarProperty, 1);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, testCode);
        }

        [TestCase("this.SetValue(BarProperty, 1);")]
        [TestCase("this.SetCurrentValue(BarProperty, 1);")]
        public void DependencyPropertyPartial(string setValueCall)
        {
            var part1 = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public partial class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
            typeof(int),
            typeof(FooControl),
            new PropertyMetadata(default(int)));

        public int Bar
        {
            get { return (int)GetValue(BarProperty); }
            set { SetValue(BarProperty, value); }
        }
    }
}";

            var part2 = @"
namespace RoslynSandbox
{
    public partial class FooControl
    {
        public void Meh()
        {
            this.SetValue(BarProperty, 1);
        }
    }
}";
            part2 = part2.AssertReplace("this.SetValue(BarProperty, 1);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, part1, part2);
        }

        [TestCase("this.SetValue(BarProperty, 1);")]
        [TestCase("this.SetValue(BarProperty, null);")]
        [TestCase("this.SetCurrentValue(BarProperty, 1);")]
        [TestCase("this.SetCurrentValue(BarProperty, null);")]
        public void DependencyPropertyOfTypeNullableInt(string setValueCall)
        {
            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
            typeof(int?),
            typeof(FooControl),
            new PropertyMetadata(default(int?)));

        public int? Bar
        {
            get { return (int?)GetValue(BarProperty); }
            set { SetValue(BarProperty, value); }
        }

        public void Meh()
        {
            this.SetValue(BarProperty, 1);
        }
    }
}";
            testCode = testCode.AssertReplace("this.SetValue(BarProperty, 1);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, testCode);
        }

        [TestCase("fooControl.SetValue(FooControl.BarProperty, 1);")]
        [TestCase("fooControl.SetValue(FooControl.BarProperty, null);")]
        [TestCase("fooControl.SetCurrentValue(FooControl.BarProperty, 1);")]
        [TestCase("fooControl.SetCurrentValue(FooControl.BarProperty, null);")]
        public void DependencyPropertyOfTypeNullableFromOutside(string setValueCall)
        {
            var fooControlCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
            typeof(int?),
            typeof(FooControl),
            new PropertyMetadata(default(int?)));

        public int? Bar
        {
            get { return (int?)GetValue(BarProperty); }
            set { SetValue(BarProperty, value); }
        }
    }
}";

            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class Foo
    {
        public void Meh()
        {
            var fooControl = new FooControl();
            fooControl.SetValue(BarProperty, 1);
        }
    }
}";
            testCode = testCode.AssertReplace("fooControl.SetValue(BarProperty, 1);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, fooControlCode, testCode);
        }

        [TestCase("this.SetValue(BarProperty, meh);")]
        [TestCase("this.SetCurrentValue(BarProperty, meh);")]
        public void DependencyPropertyOfTypeNullableIntParameter(string setValueCall)
        {
            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
            typeof(int?),
            typeof(FooControl),
            new PropertyMetadata(default(int?)));

        public int? Bar
        {
            get { return (int?)this.GetValue(BarProperty); }
            set { this.SetValue(BarProperty, value); }
        }

        public void Meh(int meh)
        {
            this.SetValue(BarProperty, meh);
        }
    }
}";
            testCode = testCode.AssertReplace("this.SetValue(BarProperty, meh);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, testCode);
        }

        [TestCase("this.SetValue(BarProperty, 1);")]
        [TestCase("this.SetValue(BarProperty, null);")]
        [TestCase("this.SetCurrentValue(BarProperty, 1);")]
        [TestCase("this.SetCurrentValue(BarProperty, null);")]
        public void DependencyPropertyOfTypeObject(string setValueCall)
        {
            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",<commit_msg>Test for #197, no repro.<commit_after>namespace WpfAnalyzers.Test.WPF0014SetValueMustUseRegisteredTypeTests
{
    using Gu.Roslyn.Asserts;
    using NUnit.Framework;

    internal class HappyPath
    {
        private static readonly SetValueAnalyzer Analyzer = new SetValueAnalyzer();

        [TestCase("this.SetValue(BarProperty, 1);")]
        [TestCase("this.SetCurrentValue(BarProperty, 1);")]
        public void DependencyProperty(string setValueCall)
        {
            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
            typeof(int),
            typeof(FooControl),
            new PropertyMetadata(default(int)));

        public int Bar
        {
            get { return (int)GetValue(BarProperty); }
            set { SetValue(BarProperty, value); }
        }

        public void Meh()
        {
            this.SetValue(BarProperty, 1);
        }
    }
}";
            testCode = testCode.AssertReplace("this.SetValue(BarProperty, 1);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, testCode);
        }

        [TestCase("this.SetValue(BarProperty, 1);")]
        [TestCase("this.SetCurrentValue(BarProperty, 1);")]
        public void DependencyPropertyPartial(string setValueCall)
        {
            var part1 = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public partial class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
            typeof(int),
            typeof(FooControl),
            new PropertyMetadata(default(int)));

        public int Bar
        {
            get { return (int)GetValue(BarProperty); }
            set { SetValue(BarProperty, value); }
        }
    }
}";

            var part2 = @"
namespace RoslynSandbox
{
    public partial class FooControl
    {
        public void Meh()
        {
            this.SetValue(BarProperty, 1);
        }
    }
}";
            part2 = part2.AssertReplace("this.SetValue(BarProperty, 1);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, part1, part2);
        }

        [TestCase("this.SetValue(BarProperty, 1);")]
        [TestCase("this.SetValue(BarProperty, null);")]
        [TestCase("this.SetCurrentValue(BarProperty, 1);")]
        [TestCase("this.SetCurrentValue(BarProperty, null);")]
        public void DependencyPropertyOfTypeNullableInt(string setValueCall)
        {
            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
            typeof(int?),
            typeof(FooControl),
            new PropertyMetadata(default(int?)));

        public int? Bar
        {
            get { return (int?)GetValue(BarProperty); }
            set { SetValue(BarProperty, value); }
        }

        public void Meh()
        {
            this.SetValue(BarProperty, 1);
        }
    }
}";
            testCode = testCode.AssertReplace("this.SetValue(BarProperty, 1);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, testCode);
        }

        [TestCase("fooControl.SetValue(FooControl.BarProperty, 1);")]
        [TestCase("fooControl.SetValue(FooControl.BarProperty, null);")]
        [TestCase("fooControl.SetCurrentValue(FooControl.BarProperty, 1);")]
        [TestCase("fooControl.SetCurrentValue(FooControl.BarProperty, null);")]
        public void DependencyPropertyOfTypeNullableFromOutside(string setValueCall)
        {
            var fooControlCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
            typeof(int?),
            typeof(FooControl),
            new PropertyMetadata(default(int?)));

        public int? Bar
        {
            get { return (int?)GetValue(BarProperty); }
            set { SetValue(BarProperty, value); }
        }
    }
}";

            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class Foo
    {
        public void Meh()
        {
            var fooControl = new FooControl();
            fooControl.SetValue(BarProperty, 1);
        }
    }
}";
            testCode = testCode.AssertReplace("fooControl.SetValue(BarProperty, 1);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, fooControlCode, testCode);
        }

        [TestCase("this.SetValue(BarProperty, meh);")]
        [TestCase("this.SetCurrentValue(BarProperty, meh);")]
        public void DependencyPropertyOfTypeNullableIntParameter(string setValueCall)
        {
            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
            typeof(int?),
            typeof(FooControl),
            new PropertyMetadata(default(int?)));

        public int? Bar
        {
            get { return (int?)this.GetValue(BarProperty); }
            set { this.SetValue(BarProperty, value); }
        }

        public void Meh(int meh)
        {
            this.SetValue(BarProperty, meh);
        }
    }
}";
            testCode = testCode.AssertReplace("this.SetValue(BarProperty, meh);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, testCode);
        }

        [TestCase("this.SetValue(ValueProperty, meh);")]
        [TestCase("this.SetCurrentValue(ValueProperty, meh);")]
        public void DependencyPropertyOfTypeNullableTParameter(string setValueCall)
        {
            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl<T> : Control
        where T : struct
    {
        public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
            nameof(Value),
            typeof(T?),
            typeof(FooControl<T>),
            new PropertyMetadata(default(T?)));

        public FooControl(T meh)
        {
            this.SetValue(ValueProperty, meh);
        }

        public T? Value
        {
            get => (T?)this.GetValue(ValueProperty);
            set => this.SetValue(ValueProperty, value);
        }
    }
}";
            testCode = testCode.AssertReplace("this.SetValue(ValueProperty, meh);", setValueCall);
            AnalyzerAssert.Valid(Analyzer, testCode);
        }

        [TestCase("this.SetValue(BarProperty, 1);")]
        [TestCase("this.SetValue(BarProperty, null);")]
        [TestCase("this.SetCurrentValue(BarProperty, 1);")]
        [TestCase("this.SetCurrentValue(BarProperty, null);")]
        public void DependencyPropertyOfTypeObject(string setValueCall)
        {
            var testCode = @"
namespace RoslynSandbox
{
    using System.Windows;
    using System.Windows.Controls;

    public class FooControl : Control
    {
        public static readonly DependencyProperty BarProperty = DependencyProperty.Register(
            ""Bar"",
{'fraction_non_alphanumeric': 0.10598521467159511, 'fraction_numerical': 0.00419391526869491, 'mean_word_length': 2.314252061248528, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1117590', 'n_tokens_mistral': 3894, 'n_tokens_neox': 3657, 'n_words': 730}