How to use should_disregard_methods_from_concrete_ancestor method of NSpec.Tests.grandChild class

Best NSpec code snippet using NSpec.Tests.grandChild.should_disregard_methods_from_concrete_ancestor

Run NSpec automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

describe_DomainExtensions.cs

Source: describe_DomainExtensions.cs Github

copy
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using NSpec.Domain.Extensions;
5using NUnit.Framework;
6using System.Threading.Tasks;
7using System.Reflection;
8using FluentAssertions;
9
10namespace NSpec.Tests
11{
12    [TestFixture]
13    [Category("DomainExtensions")]
14    public class describe_DomainExtensions
15    {
16        abstract class indirectAbstractAncestor : nspec
17        {
18            void indirect_ancestor_method() { }
19        }
20
21        class concreteAncestor : indirectAbstractAncestor
22        {
23            void concrete_ancestor_method() { }
24        }
25
26        abstract class abstractAncestor : concreteAncestor
27        {
28            void ancestor_method() { }
29        }
30
31        abstract class abstractParent : abstractAncestor
32        {
33            void parent_method() { }
34        }
35
36        class child : abstractParent
37        {
38            public void public_child_method() { }
39            void private_child_method() { }
40            void helper_method_with_paramter(int i) { }
41            void NoUnderscores() { }
42
43            public async Task public_async_child_method() { await Task.Delay(0); }
44            public async Task<long> async_method_with_result() { await Task.Delay(0); return 0L; }
45            public async void async_void_method() { await Task.Delay(0); }
46            async Task private_async_child_method() { await Task.Delay(0); }
47            async Task async_helper_method_with_paramter(int i) { await Task.Delay(0); }
48            async Task NoUnderscoresAsync() { await Task.Delay(0); }
49        }
50
51        class grandChild : child
52        {
53        }
54
55        [Test]
56        public void should_include_direct_private_methods()
57        {
58            ShouldContain("private_child_method");
59        }
60
61        [Test]
62        public void should_include_direct_async_private_methods()
63        {
64            AsyncShouldContain("private_async_child_method");
65        }
66
67        [Test]
68        public void should_include_direct_public_methods()
69        {
70            ShouldContain("public_child_method");
71        }
72
73        [Test]
74        public void should_include_direct_async_public_methods()
75        {
76            AsyncShouldContain("public_async_child_method");
77        }
78
79        [Test]
80        public void should_include_async_methods_with_result()
81        {
82            AsyncShouldContain("async_method_with_result");
83        }
84
85        [Test]
86        public void should_include_async_void_methods()
87        {
88            AsyncShouldContain("async_void_method");
89        }
90
91        [Test]
92        public void should_disregard_methods_with_parameters()
93        {
94            ShouldNotContain("helper_method_with_paramter", typeof(child));
95        }
96
97        [Test]
98        public void should_disregard_async_methods_with_parameters()
99        {
100            AsyncShouldNotContain("async_helper_method_with_paramter", typeof(child));
101        }
102
103        [Test]
104        public void should_disregard_methods_with_out_underscores()
105        {
106            ShouldNotContain("NoUnderscores", typeof(child));
107        }
108
109        [Test]
110        public void should_disregard_async_methods_with_out_underscores()
111        {
112            AsyncShouldNotContain("NoUnderscoresAsync", typeof(child));
113        }
114
115        [Test]
116        public void should_include_methods_from_abstract_parent()
117        {
118            ShouldContain("parent_method");
119        }
120
121        [Test]
122        public void should_include_methods_from_direct_abstract_ancestor()
123        {
124            ShouldContain("ancestor_method");
125        }
126
127        [Test]
128        public void should_disregard_methods_from_concrete_ancestor()
129        {
130            ShouldNotContain("concrete_ancestor_method", typeof(child));
131        }
132
133        [Test]
134        public void should_disregard_methods_from_indirect_abstract_ancestor()
135        {
136            ShouldNotContain("indirect_ancestor_method", typeof(child));
137        }
138
139        [Test]
140        public void should_disregard_methods_from_concrete_parent()
141        {
142            ShouldNotContain("private_child_method", typeof(grandChild));
143        }
144
145        [Test]
146        public void should_disregard_async_methods_from_concrete_parent()
147        {
148            AsyncShouldNotContain("private_async_child_method", typeof(grandChild));
149        }
150
151        public void ShouldContain(string name)
152        {
153            var methodInfos = DomainExtensions.Methods(typeof(child));
154
155            methodInfos.Any(m => m.Name == name).Should().Be(true);
156        }
157
158        public void ShouldNotContain(string name, Type type)
159        {
160            var methodInfos = DomainExtensions.Methods(type);
161
162            methodInfos.Any(m => m.Name == name).Should().Be(false);
163        }
164
165        public void AsyncShouldContain(string name)
166        {
167            var methodInfos = typeof(child).AsyncMethods();
168
169            methodInfos.Any(m => m.Name == name).Should().Be(true);
170        }
171
172        public void AsyncShouldNotContain(string name, Type type)
173        {
174            var methodInfos = type.AsyncMethods();
175
176            methodInfos.Any(m => m.Name == name).Should().Be(false);
177        }
178
179        class Foo1{}
180
181        abstract class Foo2 : Foo1{}
182
183        class Foo3 : Foo2{}
184
185        abstract class Foo4 : Foo3{}
186
187        abstract class Foo5 : Foo4{}
188
189        class Foo6 : Foo5{}
190
191        [Test,
192         TestCase(typeof(Foo1), new [] {typeof(Foo1)}),
193         TestCase(typeof(Foo2), new [] {typeof(Foo2)}),
194         TestCase(typeof(Foo3), new [] {typeof(Foo2), typeof(Foo3)}),
195         TestCase(typeof(Foo4), new [] {typeof(Foo4)}),
196         TestCase(typeof(Foo5), new [] {typeof(Foo4), typeof(Foo5)}),
197         TestCase(typeof(Foo6), new [] {typeof(Foo4), typeof(Foo5), typeof(Foo6)})]
198        public void should_build_immediate_abstract_class_chain(Type type, Type[] chain)
199        {
200            IEnumerable<Type> generatedChain = type.GetAbstractBaseClassChainWithClass();
201
202            generatedChain.SequenceEqual(chain).Should().BeTrue();
203        }
204
205        class Bar1{}
206
207        class Bar11 : Bar1{}
208
209        class Bar2<TBaz1>{}
210
211        class Bar21 : Bar2<Bar1>{}
212
213        class Bar3<TBaz1, TBaz2>{}
214
215        class Bar31 : Bar3<Bar1, Bar1>{}
216
217        class Bar32 : Bar3<Bar1, Bar2<Bar1>>{}
218
219        [Test,
220         TestCase(typeof(Bar11), "Bar1"),
221         TestCase(typeof(Bar21), "Bar2<Bar1>"),
222         TestCase(typeof(Bar31), "Bar3<Bar1, Bar1>"),
223         TestCase(typeof(Bar32), "Bar3<Bar1, Bar2<Bar1>>")]
224        public void should_generate_pretty_type_names(Type derivedType, string expectedNameForBaseType)
225        {
226            string name = derivedType.GetTypeInfo().BaseType.CleanName();
227
228            name.Should().Be(expectedNameForBaseType);
229        }
230    }
231}
232
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)