• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TestDataBuilders.ClassSourceCodeBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CodeContractNullability.Test.TestDataBuilders.ClassSourceCodeBuilder的典型用法代码示例。如果您正苦于以下问题:C# ClassSourceCodeBuilder类的具体用法?C# ClassSourceCodeBuilder怎么用?C# ClassSourceCodeBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClassSourceCodeBuilder类属于CodeContractNullability.Test.TestDataBuilders命名空间,在下文中一共展示了ClassSourceCodeBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ClassSourceCodeBuilder

        public void When_deriving_constructed_arrays_from_externally_annotated_interface_with_open_array_types_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .InGlobalScope(@"
                    public interface I<T>
                    {
                        T[] P { get; }
                        T[] M(T[] p, int i);
                    }
                    public class C : I<string>
                    {
                        public string[] P { get { throw new NotImplementedException(); } }
                        public string[] M(string[] p, int i) { throw new NotImplementedException(); }
                    }
                ")
                .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                    .IncludingMember(new ExternalAnnotationFragmentBuilder()
                        .Named("P:I`1.P")
                        .NotNull())
                    .IncludingMember(new ExternalAnnotationFragmentBuilder()
                        .Named("M:I`1.M(`0[],System.Int32)")
                        .NotNull()
                        .WithParameter(new ExternalAnnotationParameterBuilder()
                            .Named("p")
                            .NotNull())))
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:31,代码来源:Bugfixes.cs


示例2: When_base_property_inherits_item_annotation_from_interface_it_must_be_skipped

        public void When_base_property_inherits_item_annotation_from_interface_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = 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 and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:30,代码来源:PropertyCollectionSpecs.cs


示例3: When_base_parameter_inherits_annotation_from_interface_it_must_be_skipped

        public void When_base_parameter_inherits_annotation_from_interface_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = 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 and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:28,代码来源:ParameterSpecs.cs


示例4: When_indexer_parameter_in_base_class_is_annotated_it_must_be_skipped

        public void When_indexer_parameter_in_base_class_is_annotated_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .Using(typeof (IEnumerable<>).Namespace)
                .InGlobalScope(@"
                    abstract class B
                    {
                        public abstract int this[[ItemNotNull] IEnumerable<string> p] { get; set; }
                    }

                    abstract class D1 : B { }

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

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:28,代码来源:ParameterCollectionSpecs.cs


示例5: When_field_in_nested_class_is_externally_annotated_it_must_be_skipped

        public void When_field_in_nested_class_is_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = 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 and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:25,代码来源:ExternalAnnotationMemberNamingSpecs.cs


示例6: When_attributes_are_internal_in_external_assembly_they_must_not_be_found

        public void When_attributes_are_internal_in_external_assembly_they_must_not_be_found()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .WithoutNullabilityAttributes()
                .WithReferenceToExternalAssemblyFor(@"
                    using System;

                    namespace OtherAssembly
                    {
                        internal class NotNullAttribute : Attribute { }
                        internal class CanBeNullAttribute : Attribute { }
                        internal class ItemNotNullAttribute : Attribute { }
                        internal class ItemCanBeNullAttribute : Attribute { }
                    }")
                .InGlobalScope(@"
                    class C
                    {
                        int? f;
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:26,代码来源:AttributeDiscoverySpecs.cs


示例7: When_base_method_inherits_annotation_from_interface_it_must_be_skipped

        public void When_base_method_inherits_annotation_from_interface_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = 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 and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:29,代码来源:MethodReturnValueSpecs.cs


示例8: When_method_is_anonymous_named_by_compiler_it_must_be_skipped

        public void When_method_is_anonymous_named_by_compiler_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = 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 and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:28,代码来源:MethodReturnValueCollectionSpecs.cs


示例9: When_field_is_annotated_with_not_nullable_it_must_be_skipped

        public void When_field_is_annotated_with_not_nullable_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .WithNullabilityAttributes(new NullabilityAttributesBuilder()
                    .InCodeNamespace("N.M"))
                .InGlobalScope(@"
                    class C
                    {
                        [N.M.NotNull] // Using fully qualified namespace
                        string f;
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:18,代码来源:FieldSpecs.cs


示例10: When_attributes_are_in_different_namespace_it_must_add_namespace_import

        public void When_attributes_are_in_different_namespace_it_must_add_namespace_import()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .WithNullabilityAttributes(new NullabilityAttributesBuilder()
                    .InCodeNamespace("NA"))
                .InGlobalScope(@"
                    class C
                    {
                        <annotate/> int? [|f|];
                    }
                ")
                .ExpectingImportForNamespace("NA")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:18,代码来源:AttributeDiscoverySpecs.cs


示例11: ClassSourceCodeBuilder

        public void When_generic_parameters_in_generic_method_in_generic_nested_classes_are_externally_annotated_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .Using(typeof (KeyValuePair<,>).Namespace)
                .InGlobalScope(@"
                    namespace TestSystem
                    {
                        public class OuterClass<TOuter1, TOuter2>
                        {
                            public class InnerClass<TInner>
                            {
                                public TMethod1 TestMethod<TMethod1, TMethod2>(TOuter2 testOuter2,
                                    TInner testInner, TMethod2 testMethod2, KeyValuePair<TMethod1, TOuter1> pair)
                                {
                                    throw new NotImplementedException();
                                }
                            }
                        }
                    }
                ")
                .ExternallyAnnotated(new ExternalAnnotationsBuilder()
                    .IncludingMember(new ExternalAnnotationFragmentBuilder()
                        .Named(
                            "M:TestSystem.OuterClass`2.InnerClass`1.TestMethod``2(`1,`2,``1,System.Collections.Generic.KeyValuePair{``0,`0})")
                        .CanBeNull()
                        .WithParameter(new ExternalAnnotationParameterBuilder()
                            .Named("testOuter2")
                            .CanBeNull())
                        .WithParameter(new ExternalAnnotationParameterBuilder()
                            .Named("testInner")
                            .CanBeNull())
                        .WithParameter(new ExternalAnnotationParameterBuilder()
                            .Named("testMethod2")
                            .CanBeNull())
                        .WithParameter(new ExternalAnnotationParameterBuilder()
                            .Named("pair")
                            .CanBeNull())))
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:43,代码来源:ExternalAnnotationMemberNamingSpecs.cs


示例12: When_attributes_are_in_global_namespace_they_must_be_found

        public void When_attributes_are_in_global_namespace_they_must_be_found()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .WithNullabilityAttributes(new NullabilityAttributesBuilder()
                    .InGlobalNamespace())
                .InGlobalScope(@"
                    namespace N
                    {
                        class C
                        {
                            <annotate/> int? [|f|];
                        }
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:20,代码来源:AttributeDiscoverySpecs.cs


示例13: When_containing_type_is_decorated_with_conditional_its_members_must_be_skipped

        public void When_containing_type_is_decorated_with_conditional_its_members_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = 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 and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:21,代码来源:MethodReturnValueSpecs.cs


示例14: When_field_is_annotated_with_item_nullable_it_must_be_skipped

        public void When_field_is_annotated_with_item_nullable_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .WithNullabilityAttributes(new NullabilityAttributesBuilder()
                    .InCodeNamespace("N1"))
                .Using(typeof (IEnumerable<>).Namespace)
                .InGlobalScope(@"
                    namespace N2
                    {
                        using ICBN = N1.ItemCanBeNullAttribute;

                        class C
                        {
                            [ICBN()] // Using type/namespace alias
                            IEnumerable<string> f;
                        }
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:24,代码来源:FieldCollectionSpecs.cs


示例15: When_indexer_property_type_in_implicit_interface_is_not_annotated_it_must_be_reported_and_fixed

        public void When_indexer_property_type_in_implicit_interface_is_not_annotated_it_must_be_reported_and_fixed()
        {
            // Arrange
            ParsedSourceCode source = 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(); }
                            }

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

            // Act and assert
            VerifyNullabilityFix(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:36,代码来源:PropertyCollectionSpecs.cs


示例16: When_attributes_are_public_nested_they_must_be_found

        public void When_attributes_are_public_nested_they_must_be_found()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .WithNullabilityAttributes(new NullabilityAttributesBuilder()
                    .NestedInTypes(new[]
                    {
                        "public class X",
                        "public class Nested"
                    }))
                .InGlobalScope(@"
                    class C
                    {
                        <annotate/> int? [|f|];
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:21,代码来源:AttributeDiscoverySpecs.cs


示例17: When_attributes_are_public_nested_in_private_class_they_must_not_be_found

        public void When_attributes_are_public_nested_in_private_class_they_must_not_be_found()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .WithNullabilityAttributes(new NullabilityAttributesBuilder()
                    .NestedInTypes(new[]
                    {
                        "public class X",
                        "private class Nested"
                    }))
                .InGlobalScope(@"
                    class C
                    {
                        int? f;
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:21,代码来源:AttributeDiscoverySpecs.cs


示例18: When_attributes_are_public_in_external_assembly_it_must_add_namespace_import

        public void When_attributes_are_public_in_external_assembly_it_must_add_namespace_import()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .WithoutNullabilityAttributes()
                .WithReferenceToExternalAssemblyFor(@"
                    using System;

                    namespace OtherAssembly
                    {
                        public class NotNullAttribute : Attribute { }
                        public class CanBeNullAttribute : Attribute { }
                        public class ItemNotNullAttribute : Attribute { }
                        public class ItemCanBeNullAttribute : Attribute { }
                    }")
                .InGlobalScope(@"
                    class C
                    {
                        <annotate/> int? [|f|];
                    }
                ")
                .ExpectingImportForNamespace("OtherAssembly")
                .Build();

            // Act and assert
            VerifyNullabilityFix(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:27,代码来源:AttributeDiscoverySpecs.cs


示例19: When_attributes_are_not_defined_it_must_not_report_any_diagnostics

        public void When_attributes_are_not_defined_it_must_not_report_any_diagnostics()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .WithoutNullabilityAttributes()
                .InGlobalScope(@"
                    class C
                    {
                        int? f;
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:16,代码来源:AttributeDiscoverySpecs.cs


示例20: When_return_value_type_is_generic_value_type_it_must_be_skipped

        public void When_return_value_type_is_generic_value_type_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new ClassSourceCodeBuilder()
                .InGlobalScope(@"
                    class C<T> where T : struct
                    {
                        T M() { throw new NotImplementedException(); }
                    }
                ")
                .Build();

            // Act and assert
            VerifyNullabilityDiagnostic(source);
        }
开发者ID:imanushin,项目名称:ResharperCodeContractNullability,代码行数:15,代码来源:MethodReturnValueSpecs.cs



注:本文中的CodeContractNullability.Test.TestDataBuilders.ClassSourceCodeBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TestDataBuilders.MemberSourceCodeBuilder类代码示例发布时间:2022-05-24
下一篇:
C# CodeCompletion.TypeScope类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap