How to use ExampleBaseWrap class of NSpec.Tests package

Best NSpec code snippet using NSpec.Tests.ExampleBaseWrap

Run NSpec automation tests on LambdaTest cloud grid

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

describe_ContextCollection.cs

Source: describe_ContextCollection.cs Github

copy
1using FluentAssertions;
2using NSpec.Domain;
3using NSpec.Tests.WhenRunningSpecs.Exceptions;
4using NUnit.Framework;
5using System.Linq;
6
7namespace NSpec.Tests
8{
9    [TestFixture]
10    [Category("ContextCollection")]
11    public class describe_ContextCollection
12    {
13        private ContextCollection contexts;
14
15        [SetUp]
16        public void setup()
17        {
18            contexts = new ContextCollection();
19
20            var context = new Context();
21
22            context.AddExample(new ExampleBaseWrap());
23
24            context.AddExample(new ExampleBaseWrap(pending: true));
25
26            context.AddExample(new ExampleBaseWrap { Exception = new KnownException() });
27
28            context.Tags.Add(Tags.Focus);
29
30            contexts.Add(context);
31        }
32
33        [Test]
34        public void should_aggregate_examples()
35        {
36            contexts.Examples().Count().Should().Be(3);
37        }
38
39        [Test]
40        public void is_marked_with_focus()
41        {
42            contexts.AnyTaggedWithFocus().Should().BeTrue();
43        }
44
45        [Test]
46        public void should_aggregate_failures()
47        {
48            contexts.Failures().Count().Should().Be(1);
49        }
50
51        [Test]
52        public void should_aggregate_pendings()
53        {
54            contexts.Pendings().Count().Should().Be(1);
55        }
56
57        [Test]
58        public void should_trim_skipped_contexts()
59        {
60            contexts.Add(new Context());
61            contexts[0].AddExample(new ExampleBaseWrap());
62            contexts[0].Examples[0].HasRun = true;
63            contexts.Count().Should().Be(2);
64            contexts.TrimSkippedContexts();
65            contexts.Count().Should().Be(1);
66        }
67    }
68}
Full Screen

ExampleBaseWrap.cs

Source: ExampleBaseWrap.cs Github

copy
1using NSpec.Domain;
2using System;
3using System.Reflection;
4
5namespace NSpec.Tests
6{
7    /// <summary>
8    /// Abstract framework ExampleBase class implements functionalities common to both sync and async example implementations.
9    /// This thin wrapper allows to test those functionalities.
10    /// </summary>
11    class ExampleBaseWrap : ExampleBase
12    {
13        public ExampleBaseWrap(string name = "", bool pending = false)
14            : base(name, pending: pending)
15        {
16        }
17        public override void Run(nspec nspec)
18        {
19            throw new NotImplementedException();
20        }
21
22        public override void RunPending(nspec nspec)
23        {
24            throw new NotImplementedException();
25        }
26
27        public override bool IsAsync
28        {
29            get { throw new NotImplementedException(); }
30        }
31
32        public override MethodInfo BodyMethodInfo
33        {
34            get { throw new NotImplementedException(); }
35        }
36    }
37}
38
Full Screen

describe_ExampleBase.cs

Source: describe_ExampleBase.cs Github

copy
1using FluentAssertions;
2using NSpec.Domain;
3using NUnit.Framework;
4using System;
5
6namespace NSpec.Tests
7{
8    [TestFixture]
9    [Category("Example")]
10    public class when_parsing_expressions
11    {
12        [Test]
13        public void should_clear_quotes()
14        {
15            new Example(() => Assert.That("hello", Is.EqualTo("hello"))).Spec
16                .Should().Be("That hello, EqualTo hello");
17        }
18
19        // no 'specify' available for AsyncExample, hence no way to test that on AsyncExample
20    }
21
22    [TestFixture]
23    [Category("Example")]
24    public class describe_ExampleBase
25    {
26        [Test]
27        public void should_concatenate_its_contexts_name_into_a_full_name()
28        {
29            var context = new Context("context name");
30
31            var example = new ExampleBaseWrap("example name");
32
33            context.AddExample(example);
34
35            example.FullName().Should().Be("context name. example name.");
36        }
37
38        [Test]
39        public void should_be_marked_as_pending_if_parent_context_is_pending()
40        {
41            var context = new Context("pending context", null, isPending: true);
42
43            var example = new ExampleBaseWrap("example name");
44
45            context.AddExample(example);
46
47            example.Pending.Should().BeTrue();
48        }
49
50        [Test]
51        public void should_be_marked_as_pending_if_any_parent_context_is_pending()
52        {
53            var parentContext = new Context("parent pending context", null, isPending: true);
54            var context = new Context("not pending");
55            var example = new ExampleBaseWrap("example name");
56
57            parentContext.AddContext(context);
58
59            context.AddExample(example);
60
61            example.Pending.Should().BeTrue();
62        }
63    }
64}
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

Most used methods in ExampleBaseWrap

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
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)