Inheritance: SourceCodeBuilder
        public void When_field_type_is_nullable_it_must_be_reported_and_disabled()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    int? [|f|];
                ")
                .Build();

            // Act and assert
            VerifyDiagnosticWithFix(source);
        }
        public void When_field_contains_multiple_variables_they_must_be_reported_and_fixed()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    <annotate/> int? [|f|], [|g|];
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
        public void When_async_method_returns_void_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof(Task).Namespace)
                .InDefaultClass(@"
                    async void M() { throw new NotImplementedException(); }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_field_type_is_nullable_but_analysis_is_disabled_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .WithSettings(new AnalyzerSettingsBuilder()
                    .DisableReportOnNullableValueTypes)
                .InDefaultClass(@"
                    int? f;
                ")
                .Build();

            // Act and assert
            VerifyDiagnosticWithFix(source);
        }
        public void When_lambda_return_value_is_nullable_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    public void M()
                    {
                        Func<int, string> f = p => null;
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_property_type_is_generic_task_it_must_be_reported_and_fixed()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (Task<>).Namespace)
                .InDefaultClass(@"
                    <annotate/> Task<string> [|P|] { get; set; }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
        public void When_property_item_type_is_object_it_must_be_reported_and_fixed()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (ArrayList).Namespace)
                .InDefaultClass(@"
                    <annotate/> ArrayList [|P|] { get; }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
        public void When_property_item_type_is_enum_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (IEnumerable<>).Namespace)
                .Using(typeof (BindingFlags).Namespace)
                .InDefaultClass(@"
                    IEnumerable<BindingFlags> P { get; set; }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_property_is_not_debuggable_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (IEnumerable<>).Namespace)
                .Using(typeof (DebuggerNonUserCodeAttribute).Namespace)
                .InDefaultClass(@"
                    [DebuggerNonUserCode]
                    IEnumerable<string> P { get; set; }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_ref_parameter_is_nullable_it_must_be_reported_and_fixed()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    void M(<annotate/> ref int? [|p|]) { }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
        public void When_method_is_compiler_generated_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (CompilerGeneratedAttribute).Namespace)
                .InDefaultClass(@"
                    [CompilerGenerated]
                    string M() { throw new NotImplementedException(); }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_indexer_property_type_is_collection_of_reference_type_it_must_be_reported_and_fixed()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (IEnumerable<>).Namespace)
                .InDefaultClass(@"
                    <annotate/> IEnumerable<int?> [|this|][int p]
                    {
                        get { throw new NotImplementedException(); }
                        set { throw new NotImplementedException(); }
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
        public void When_field_type_is_value_type_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    int f;
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_field_type_is_reference_it_must_be_reported_and_fixed()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    <annotate/> string [|f|];
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
        public void When_field_type_is_enum_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (BindingFlags).Namespace)
                .InDefaultClass(@"
                    BindingFlags f;
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_field_is_event_handler_with_accessors_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (EventHandler).Namespace)
                .InDefaultClass(@"
                    public event EventHandler E
                    {
                        add { throw new NotImplementedException(); }
                        remove { throw new NotImplementedException(); }
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_field_is_event_handler_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (EventHandler).Namespace)
                .InDefaultClass(@"
                    public event EventHandler E;
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_field_is_constant_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    public const string F = ""X"";
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_ref_parameter_is_value_type_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    void M(ref int p) { }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_property_type_is_lazy_it_must_be_reported_and_fixed()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    <annotate/> Lazy<string> [|P|] { get; set; }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
        public void When_property_type_is_task_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (Task).Namespace)
                .InDefaultClass(@"
                    public Task P { get; set; }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_method_returns_void_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    void M() { }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_method_is_async_task_it_must_be_reported_and_fixed()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (Task).Namespace)
                .InDefaultClass(@"
                    <annotate/> async Task [|M|]() { throw new NotImplementedException(); }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
        public void When_return_value_type_is_reference_it_must_be_reported_and_fixed()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    <annotate/> string [|M|]() { throw new NotImplementedException(); }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
        public void When_method_is_not_debuggable_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (DebuggerNonUserCodeAttribute).Namespace)
                .InDefaultClass(@"
                    [DebuggerNonUserCode]
                    string M() { throw new NotImplementedException(); }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_parameter_is_compiler_generated_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (CompilerGeneratedAttribute).Namespace)
                .InDefaultClass(@"
                    void M([CompilerGenerated] string p) { }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_return_value_is_in_file_with_codegen_comment_at_top_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .WithHeader(@"
            //------------------------------------------------------------------------------
            // <auto-generated>
            //     This code was generated by a tool.
            //     Runtime Version:4.0.30319.0
            //
            //     Changes to this file may cause incorrect behavior and will be lost if
            //     the code is regenerated.
            // </auto-generated>
            //------------------------------------------------------------------------------
            ")
                .InDefaultClass(@"
                    string M() { throw new NotImplementedException(); }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_property_is_compiler_generated_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (IEnumerable<>).Namespace)
                .Using(typeof (CompilerGeneratedAttribute).Namespace)
                .InDefaultClass(@"
                    [CompilerGenerated]
                    IEnumerable<string> P { get; set; }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_return_value_type_is_value_type_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .InDefaultClass(@"
                    int M() { throw new NotImplementedException(); }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
        public void When_property_is_in_file_with_codegen_comment_at_top_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new MemberSourceCodeBuilder()
                .Using(typeof (IEnumerable<>).Namespace)
                .WithHeader(@"
            //------------------------------------------------------------------------------
            // <auto-generated>
            //     This code was generated by a tool.
            //     Runtime Version:4.0.30319.0
            //
            //     Changes to this file may cause incorrect behavior and will be lost if
            //     the code is regenerated.
            // </auto-generated>
            //------------------------------------------------------------------------------
            ")
                .InDefaultClass(@"
                    IEnumerable<string> this[int index]
                    {
                        get
                        {
                            throw new NotImplementedException();
                        }
                        set
                        {
                            throw new NotImplementedException();
                        }
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }