コード例 #1
0
        When_parameter_in_implicit_interface_implementation_is_effectively_annotated_through_annotation_on_interface_it_must_be_skipped
            ()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        interface I
                        {
                            void M([NotNull] string p);
                        }

                        class C : I
                        {
                            // implicitly inherits decoration from interface
                            void I.M(string p) { }

                            // requires explicit decoration
                            public void M([NotNull] string p) { }

                            // unrelated overload
                            public void M([NotNull] object p) { }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #2
0
        public void When_parameter_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        namespace N
                        {
                            class C
                            {
                                void M(string p) { }
                            }
                        }
                    "))
                                           .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                                                                .IncludingMember(new ExternalAnnotationFragmentBuilder()
                                                                                 .Named("M:N.C.M(System.String)")
                                                                                 .WithParameter(new ExternalAnnotationParameterBuilder()
                                                                                                .Named("p")
                                                                                                .CanBeNull())))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #3
0
        public void When_parameter_in_implicit_interface_implementation_is_not_annotated_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        interface I
                        {
                            void M([NotNull] string p);
                        }

                        class C : I
                        {
                            // implicitly inherits decoration from interface
                            void I.M(string p) { }

                            // requires explicit decoration
                            public void M(string p) { }

                            // unrelated overload
                            public void M([NotNull] object p) { }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(NullabilityRule.RuleName);
        }
コード例 #4
0
        public void When_parameter_in_base_constructor_is_annotated_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        class B
                        {
                            protected B([NotNull] string p) { }
                        }

                        class D : B
                        {
                            public D(string p) : base(p) { }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(NullabilityRule.RuleName);
        }
コード例 #5
0
        public void When_indexer_parameter_in_base_class_is_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        abstract class B
                        {
                            public abstract int this[[NotNull] string p] { get; set; }
                        }

                        abstract class D1 : B { }

                        class D2 : D1
                        {
                            // implicitly inherits decoration from base class
                            public override int this[string p]
                            {
                                get { throw new NotImplementedException(); }
                                set { throw new NotImplementedException(); }
                            }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #6
0
        public void When_type_parameter_is_inherited_it_must_be_resolved_without_error()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        public class B<T>
                        {
                            [NotNull]
                            public virtual T M(/* missing annotation */ T p)
                            {
                                throw new NotImplementedException();
                            }
                        }

                        public class D<T> : B<T>
                        {
                            [NotNull]
                            public override T M(/* missing annotation */ T p) // Should not throw 'Unable to resolve TypeParameter to a type argument.'
                            {
                                throw new NotImplementedException();
                            }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(2);
        }
コード例 #7
0
        public void When_base_parameter_inherits_annotation_from_interface_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        namespace N
                        {
                            public interface I
                            {
                                void M([NotNull] string p);
                            }

                            public class B : I
                            {
                                public virtual void M(string p) { }
                            }

                            public class C : B
                            {
                                public override void M(string p) { }
                            }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_return_value_in_implicit_interface_is_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        interface I
                        {
                            [CanBeNull]
                            string M();
                        }

                        class C : I
                        {
                            // implicitly inherits decoration from interface
                            public string M() { throw new NotImplementedException(); }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #9
0
        public void When_override_breaks_inheritance_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                    namespace N
                    {
                        public class B
                        {
                            [NotNull]
                            public virtual string P { get; set; }
                        }

                        public class C : B
                        {
                            public new string P { get; set; }
                        }
                    }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(NullabilityRule.RuleName);
        }
        public void When_property_in_explicit_interface_is_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <ItemNullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .Using(typeof(IEnumerable <>).Namespace)
                                                       .InGlobalScope(@"
                        interface I
                        {
                            [ItemCanBeNull]
                            IEnumerable<string> P { get; set; }
                        }

                        class C : I
                        {
                            // implicitly inherits decoration from interface
                            IEnumerable<string> I.P { get; set; }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_return_value_in_explicit_interface_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        namespace N
                        {
                            interface I
                            {
                                string M();
                            }

                            class C : I
                            {
                                // implicitly inherits decoration from interface
                                string I.M() { throw new NotImplementedException(); }
                            }
                        }
                    "))
                                           .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                                                                .IncludingMember(new ExternalAnnotationFragmentBuilder()
                                                                                 .Named("M:N.I.M")
                                                                                 .CanBeNull()))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #12
0
        public void When_field_is_annotated_with_nullable_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .WithNullabilityAttributes(new NullabilityAttributesBuilder()
                                                                                  .InCodeNamespace("N1"))
                                                       .InGlobalScope(@"
                        namespace N2
                        {
                            using CBN = N1.CanBeNullAttribute;

                            class C
                            {
                                [CBN()] // Using type/namespace alias
                                string f;
                            }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_method_is_lambda_named_by_compiler_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        class C1
                        {
                            private void Test()
                            {
                                C2.M( () =>     // no syntax exists to decorate this lambda expression
                                {
                                    throw new NotImplementedException();
                                });
                            }
                        }
                        public class C2
                        {
                            public static void M([NotNull] Func<int?> callback)
                            {
                            }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_generic_parameters_in_method_of_generic_class_are_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        namespace SystemCollections
                        {
                            public class Dictionary<TKey, TValue>
                            {
                                public void Add(TKey key, TValue value) { throw new NotImplementedException(); }
                            }
                        }
                    "))
                                           .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                                                                .IncludingMember(new ExternalAnnotationFragmentBuilder()
                                                                                 .Named("M:SystemCollections.Dictionary`2.Add(`0,`1)")
                                                                                 .WithParameter(new ExternalAnnotationParameterBuilder()
                                                                                                .Named("key")
                                                                                                .CanBeNull())
                                                                                 .WithParameter(new ExternalAnnotationParameterBuilder()
                                                                                                .Named("value")
                                                                                                .CanBeNull())))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #15
0
        public void When_generic_field_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        namespace N
                        {
                            public class C<T> where T : struct
                            {
                                public T? F;
                            }
                        }
                    "))
                                           .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                                                                .IncludingMember(new ExternalAnnotationFragmentBuilder()
                                                                                 .Named("F:N.C`1.F")
                                                                                 .CanBeNull()))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_field_in_nested_class_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        namespace TestSystem
                        {
                            public class Outer
                            {
                                private class Inner
                                {
                                    public int? Value;
                                }
                            }
                        }
                    "))
                                           .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                                                                .IncludingMember(new ExternalAnnotationFragmentBuilder()
                                                                                 .Named("F:TestSystem.Outer.Inner.Value")
                                                                                 .CanBeNull()))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_property_in_generic_class_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .Using(typeof(IEnumerable <>).Namespace)
                                                       .InGlobalScope(@"
                        namespace SampleNamespace
                        {
                            public class SampleClass<T>
                            {
                                public virtual IEnumerable<T> TheEnumerable { get; set; }
                            }
                        }
                    "))
                                           .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                                                                .IncludingMember(new ExternalAnnotationFragmentBuilder()
                                                                                 .Named("P:SampleNamespace.SampleClass`1.TheEnumerable")
                                                                                 .CanBeNull()))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        When_nested_generic_parameters_in_method_of_generic_interface_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .Using(typeof(IEnumerable <>).Namespace)
                                                       .InGlobalScope(@"
                        namespace SystemCollections
                        {
                            public interface IDictionary<TKey, TValue>
                            {
                                void SetItems(IEnumerable<KeyValuePair<TKey, TValue>> items);
                            }
                        }
                    "))
                                           .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                                                                .IncludingMember(new ExternalAnnotationFragmentBuilder()
                                                                                 .Named(
                                                                                     "M:SystemCollections.IDictionary`2.SetItems(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{`0,`1}})")
                                                                                 .WithParameter(new ExternalAnnotationParameterBuilder()
                                                                                                .Named("items")
                                                                                                .CanBeNull())))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_return_value_in_implicit_interface_is_not_annotated_with_explicit_interface_it_must_be_reported
            ()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        interface I
                        {
                            [NotNull]
                            string M();
                        }

                        class C : I
                        {
                            // implicitly inherits decoration from interface
                            string I.M() { throw new NotImplementedException(); }

                            // requires explicit decoration
                            public string M() { throw new NotImplementedException(); }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(NullabilityRule.RuleName);
        }
コード例 #20
0
        public void When_override_breaks_inheritance_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <ItemNullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .Using(typeof(IEnumerable <>).Namespace)
                                                       .InGlobalScope(@"
                    namespace N
                    {
                        public class B
                        {
                            [ItemNotNull]
                            public virtual IEnumerable<int?> M() { throw new NotImplementedException(); }
                        }

                        public class C : B
                        {
                            public new IEnumerable<int?> M() { throw new NotImplementedException(); }
                        }
                    }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(ItemNullabilityRule.RuleName);
        }
        public void When_containing_type_is_decorated_with_conditional_its_members_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .WithReference(typeof (ConditionalAttribute).Assembly)
                    .Using(typeof (ConditionalAttribute).Namespace)
                    .InGlobalScope(@"
                        namespace N
                        {
                            [Conditional(""JETBRAINS_ANNOTATIONS"")]
                            class C : Attribute
                            {
                                string M() { throw new NotImplementedException(); }
                            }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #22
0
        public void When_containing_type_is_decorated_with_conditional_its_members_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .WithReference(typeof(ConditionalAttribute).Assembly)
                                                       .Using(typeof(ConditionalAttribute).Namespace)
                                                       .InGlobalScope(@"
                        namespace N
                        {
                            [Conditional(""JETBRAINS_ANNOTATIONS"")]
                            class C : Attribute
                            {
                                public string P { get; set; }
                            }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #23
0
        public void When_property_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        namespace N
                        {
                            class C
                            {
                                string P { get; set; }
                            }
                        }
                    "))
                                           .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                                                                .IncludingMember(new ExternalAnnotationFragmentBuilder()
                                                                                 .Named("P:N.C.P")
                                                                                 .NotNull()))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #24
0
        public void When_property_in_base_class_is_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        class B
                        {
                            [NotNull]
                            public virtual string P { get; set; }
                        }

                        class D1 : B { }

                        class D2 : D1
                        {
                            // implicitly inherits decoration from base class
                            public override string P { get; set; }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #25
0
        public void When_property_in_base_class_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <NullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .InGlobalScope(@"
                        namespace N
                        {
                            class B
                            {
                                public virtual string P { get; set; }
                            }

                            class D1 : B { }

                            class D2 : D1
                            {
                                // implicitly inherits decoration from base class
                                public override string P { get; set; }
                            }
                        }
                    "))
                                           .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                                                                .IncludingMember(new ExternalAnnotationFragmentBuilder()
                                                                                 .Named("P:N.B.P")
                                                                                 .NotNull()))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #26
0
        public void When_method_is_anonymous_named_by_compiler_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <ItemNullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .Using(typeof(IEnumerable <>).Namespace)
                                                       .InGlobalScope(@"
                        class C1
                        {
                            private void Test()
                            {
                                C2.M(delegate       // no syntax exists to decorate this anonymous method
                                {
                                    throw new NotImplementedException();
                                });
                            }
                        }
                        public class C2
                        {
                            public static void M([ItemNotNull] Func<IEnumerable<int?>> callback)
                            {
                            }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_property_in_implicit_interface_is_not_annotated_with_explicit_interface_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <ItemNullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .Using(typeof(IEnumerable <>).Namespace)
                                                       .InGlobalScope(@"
                        interface I
                        {
                            [ItemNotNull]
                            IEnumerable<string> P { get; set; }
                        }

                        class C : I
                        {
                            // implicitly inherits decoration from interface
                            IEnumerable<string> I.P { get; set; }

                            // requires explicit decoration
                            public IEnumerable<string> P { get; set; }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(ItemNullabilityRule.RuleName);
        }
        public void When_base_property_inherits_item_annotation_from_interface_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <ItemNullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .Using(typeof(IEnumerable).Namespace)
                                                       .InGlobalScope(@"
                        namespace N
                        {
                            public interface I
                            {
                                [ItemNotNull]
                                IEnumerable P { get; set; }
                            }

                            public class B : I
                            {
                                public virtual IEnumerable P { get; set; }
                            }

                            public class C : B
                            {
                                public override IEnumerable P { get; set; }
                            }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #29
0
        public void When_return_value_in_implicit_interface_is_annotated_with_explicit_interface_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <ItemNullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .Using(typeof(IList <>).Namespace)
                                                       .InGlobalScope(@"
                        interface I
                        {
                            [ItemNotNull]
                            IList<string> M();
                        }

                        class C : I
                        {
                            // implicitly inherits decoration from interface
                            IList<string> I.M() { throw new NotImplementedException(); }

                            // requires explicit decoration
                            [ItemNotNull]
                            public IList<string> M() { throw new NotImplementedException(); }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #30
0
        public void When_return_value_in_base_class_is_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <ItemNullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .Using(typeof(IList <>).Namespace)
                                                       .InGlobalScope(@"
                        class B
                        {
                            [ItemNotNull]
                            public virtual IList<string> M() { throw new NotImplementedException(); }
                        }

                        class D1 : B { }

                        class D2 : D1
                        {
                            // implicitly inherits decoration from base class
                            public override IList<string> M() { throw new NotImplementedException(); }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #31
0
        public void When_base_method_inherits_item_annotation_from_interface_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                                           .ForRule <ItemNullabilityRule>()
                                           .OnAssembly(new ClassSourceCodeBuilder()
                                                       .Using(typeof(IList <>).Namespace)
                                                       .InGlobalScope(@"
                        namespace N
                        {
                            public interface I
                            {
                                [ItemNotNull]
                                IList<string> M();
                            }

                            public class B : I
                            {
                                public virtual IList<string> M() { throw new NotImplementedException(); }
                            }

                            public class C : B
                            {
                                public override IList<string> M() { throw new NotImplementedException(); }
                            }
                        }
                    "))
                                           .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_base_property_inherits_item_annotation_from_interface_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .Using(typeof (IEnumerable).Namespace)
                    .InGlobalScope(@"
                        namespace N
                        {
                            public interface I
                            {
                                [ItemNotNull]
                                IEnumerable P { get; set; }
                            }

                            public class B : I
                            {
                                public virtual IEnumerable P { get; set; }
                            }

                            public class C : B
                            {
                                public override IEnumerable P { get; set; }
                            }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_field_in_nested_class_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        namespace TestSystem
                        {
                            public class Outer
                            {
                                private class Inner
                                {
                                    public int? Value;
                                }
                            }
                        }
                    "))
                .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                    .IncludingMember(new ExternalAnnotationFragmentBuilder()
                        .Named("F:TestSystem.Outer.Inner.Value")
                        .CanBeNull()))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_base_method_inherits_annotation_from_interface_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        namespace N
                        {
                            public interface I
                            {
                                [NotNull]
                                string M();
                            }

                            public class B : I
                            {
                                public virtual string M() { throw new NotImplementedException(); }
                            }

                            public class C : B
                            {
                                public override string M() { throw new NotImplementedException(); }
                            }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_async_method_returns_void_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new MemberSourceCodeBuilder()
                    .InDefaultClass(@"
                        async void M() { throw new NotImplementedException(); }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_async_method_returns_generic_task_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new MemberSourceCodeBuilder()
                    .Using(typeof (Task<>).Namespace)
                    .InDefaultClass(@"
                        async Task<string> M() { throw new NotImplementedException(); }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #37
0
        public void When_array_item_type_is_value_type_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        class C
                        {
                            byte[] f;
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #38
0
        public void When_lambda_return_value_is_nullable_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new MemberSourceCodeBuilder()
                    .InDefaultClass(@"
                        public void M()
                        {
                            Func<int, string> f = p => null;
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
コード例 #39
0
        public void When_deriving_constructed_arrays_from_externally_annotated_class_with_open_array_types_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        public abstract class B<T>
                        {
                            public abstract T[] P { get; }

                            public abstract T[] M(T[] p, int i);
                        }

                        public class D : B<string>
                        {
                            public override string[] P { get { throw new NotImplementedException(); } }

                            public override string[] M(string[] p, int i) { throw new NotImplementedException(); }
                        }
                    "))
                .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                    .IncludingMember(new ExternalAnnotationFragmentBuilder()
                        .Named("P:B`1.P")
                        .NotNull())
                    .IncludingMember(new ExternalAnnotationFragmentBuilder()
                        .Named("M:B`1.M(`0[],System.Int32)")
                        .NotNull()
                        .WithParameter(new ExternalAnnotationParameterBuilder()
                            .Named("p")
                            .NotNull())))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_property_item_type_is_generic_nullable_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .Using(typeof (IEnumerable<>).Namespace)
                    .InGlobalScope(@"
                        class C<T> where T : struct
                        {
                            IEnumerable<T?> P { get; set; }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(ItemNullabilityRule.RuleName);
        }
        public void When_return_value_in_implicit_interface_is_not_annotated_with_explicit_interface_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        interface I
                        {
                            [NotNull]
                            string M();
                        }

                        class C : I
                        {
                            // implicitly inherits decoration from interface
                            string I.M() { throw new NotImplementedException(); }

                            // requires explicit decoration
                            public string M() { throw new NotImplementedException(); }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(NullabilityRule.RuleName);
        }
        public void When_return_value_in_implicit_interface_is_annotated_with_externally_annotated_explicit_interface_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        namespace N
                        {
                            interface I
                            {
                                string M();
                            }

                            class C : I
                            {
                                // implicitly inherits decoration from interface
                                string I.M() { throw new NotImplementedException(); }

                                // requires explicit decoration
                                [NotNull]
                                public string M() { throw new NotImplementedException(); }
                            }
                        }
                    "))
                .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                    .IncludingMember(new ExternalAnnotationFragmentBuilder()
                        .Named("M:N.I.M")
                        .CanBeNull()))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_return_value_in_implicit_interface_is_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        interface I
                        {
                            [CanBeNull]
                            string M();
                        }

                        class C : I
                        {
                            // implicitly inherits decoration from interface
                            public string M() { throw new NotImplementedException(); }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_return_value_in_base_class_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        namespace N
                        {
                            class B
                            {
                                public virtual string M() { throw new NotImplementedException(); }
                            }

                            class D1 : B { }

                            class D2 : D1
                            {
                                // implicitly inherits decoration from base class
                                public override string M() { throw new NotImplementedException(); }
                            }
                        }
                    "))
                .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                    .IncludingMember(new ExternalAnnotationFragmentBuilder()
                        .Named("M:N.B.M")
                        .NotNull()))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_override_breaks_inheritance_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                    namespace N
                    {
                        public class B
                        {
                            [NotNull]
                            public virtual string M() { throw new NotImplementedException(); }
                        }

                        public class C : B
                        {
                            public new string M() { throw new NotImplementedException(); }
                        }
                    }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(NullabilityRule.RuleName);
        }
        public void When_method_is_async_task_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new MemberSourceCodeBuilder()
                    .Using(typeof (Task).Namespace)
                    .InDefaultClass(@"
                        async Task M() { throw new NotImplementedException(); }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(NullabilityRule.RuleName);
        }
        public void When_method_is_not_debuggable_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new MemberSourceCodeBuilder()
                    .Using(typeof (DebuggerNonUserCodeAttribute).Namespace)
                    .InDefaultClass(@"
                        [DebuggerNonUserCode]
                        string M() { throw new NotImplementedException(); }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_property_is_annotated_with_item_nullable_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .Using(typeof (IEnumerable<>).Namespace)
                    .InGlobalScope(@"
                        class C
                        {
                            [ItemCanBeNull]
                            IEnumerable<string> P { get; set; }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_property_in_implicit_interface_is_not_annotated_with_explicit_interface_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .Using(typeof (IEnumerable<>).Namespace)
                    .InGlobalScope(@"
                        interface I
                        {
                            [ItemNotNull]
                            IEnumerable<string> P { get; set; }
                        }

                        class C : I
                        {
                            // implicitly inherits decoration from interface
                            IEnumerable<string> I.P { get; set; }

                            // requires explicit decoration
                            public IEnumerable<string> P { get; set; }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(ItemNullabilityRule.RuleName);
        }
        public void When_property_is_not_debuggable_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new MemberSourceCodeBuilder()
                    .Using(typeof (IEnumerable<>).Namespace)
                    .Using(typeof (DebuggerNonUserCodeAttribute).Namespace)
                    .InDefaultClass(@"
                        [DebuggerNonUserCode]
                        IEnumerable<string> P { get; set; }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_return_value_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        namespace N
                        {
                            class C
                            {
                                string M() { throw new NotImplementedException(); }
                            }
                        }
                    "))
                .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                    .IncludingMember(new ExternalAnnotationFragmentBuilder()
                        .Named("M:N.C.M")
                        .NotNull()))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_return_value_type_is_generic_nullable_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        class C<T> where T : struct
                        {
                            T? M() { throw new NotImplementedException(); }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(NullabilityRule.RuleName);
        }
        public void When_return_value_type_is_reference_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new MemberSourceCodeBuilder()
                    .InDefaultClass(@"
                        string M() { throw new NotImplementedException(); }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(NullabilityRule.RuleName);
        }
        public void When_indexer_property_type_in_implicit_interface_is_not_annotated_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .Using(typeof (IEnumerable<>).Namespace)
                    .InGlobalScope(@"
                        namespace N
                        {
                            interface I
                            {
                                [ItemCanBeNull]
                                IEnumerable<int?> this[char p] { get; set; }
                            }

                            class C : I
                            {
                                // implicitly inherits decoration from interface
                                IEnumerable<int?> I.this[char p]
                                {
                                    get { throw new NotImplementedException(); }
                                    set { throw new NotImplementedException(); }
                                }

                                public IEnumerable<int?> this[char p]
                                {
                                    get { throw new NotImplementedException(); }
                                    set { throw new NotImplementedException(); }
                                }
                            }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(ItemNullabilityRule.RuleName);
        }
        public void When_return_value_type_is_enum_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new MemberSourceCodeBuilder()
                    .Using(typeof (BindingFlags).Namespace)
                    .InDefaultClass(@"
                        BindingFlags M() { throw new NotImplementedException(); }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_property_item_type_is_generic_value_type_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .Using(typeof (IEnumerable<>).Namespace)
                    .InGlobalScope(@"
                        class C<T> where T : struct
                        {
                            IEnumerable<T> P { get; set; }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_return_value_type_is_generic_value_type_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        class C<T> where T : struct
                        {
                            T M() { throw new NotImplementedException(); }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_property_type_is_lazy_it_must_be_reported()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new MemberSourceCodeBuilder()
                    .InDefaultClass(@"
                    Lazy<string> P { get; set; }
                "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.Problems.Should().HaveCount(1);
            result.Problems[0].Resolution.Name.Should().Be(ItemNullabilityRule.RuleName);
        }
        public void When_method_is_anonymous_named_by_compiler_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<NullabilityRule>()
                .OnAssembly(new ClassSourceCodeBuilder()
                    .InGlobalScope(@"
                        class C1
                        {
                            private void Test()
                            {
                                C2.M(delegate       // no syntax exists to decorate this anonymous method
                                {
                                    throw new NotImplementedException();
                                });
                            }
                        }
                        public class C2
                        {
                            public static void M([NotNull] Func<int?> callback)
                            {
                            }
                        }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }
        public void When_property_type_is_task_it_must_be_skipped()
        {
            // Arrange
            FxCopRuleValidator validator = new FxCopNullabilityRuleValidatorBuilder()
                .ForRule<ItemNullabilityRule>()
                .OnAssembly(new MemberSourceCodeBuilder()
                    .Using(typeof (Task).Namespace)
                    .InDefaultClass(@"
                        public Task P { get; set; }
                    "))
                .Build();

            // Act
            FxCopRuleValidationResult result = validator.Execute();

            // Assert
            result.ProblemText.Should().Be(FxCopRuleValidationResult.NoProblemsText);
        }