How to use CollectionEqualsTests class of NUnit.Framework.Constraints package

Best Nunit code snippet using NUnit.Framework.Constraints.CollectionEqualsTests

Run Nunit automation tests on LambdaTest cloud grid

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

CollectionEqualsTests.cs

Source: CollectionEqualsTests.cs Github

copy
1// *****************************************************
2// Copyright 2007, Charlie Poole
3//
4// Licensed under the Open Software License version 3.0
5// *****************************************************
6
7using System;
8using System.Collections;
9using System.Collections.Generic;
10using NUnit.Framework;
11using NUnit.Framework.Internal;
12using NUnit.TestUtilities.Collections;
13using Env = NUnit.Env;
14
15namespace NUnit.Framework.Constraints
16{
17    [TestFixture]
18    class CollectionEqualsTests
19    {
20        [Test]
21        public void CanMatchTwoCollections()
22        {
23            ICollection expected = new SimpleObjectCollection(1, 2, 3);
24            ICollection actual = new SimpleObjectCollection(1, 2, 3);
25
26            Assert.That(actual, Is.EqualTo(expected));
27        }
28
29        public void CanMatchTwoLists()
30        {
31            //IList expected = new List<int>();
32        }
33
34        [Test]
35        public void CanMatchAnArrayWithACollection()
36        {
37            ICollection collection = new SimpleObjectCollection(1, 2, 3);
38            int[] array = new int[] { 1, 2, 3 };
39
40            Assert.That(collection, Is.EqualTo(array));
41            Assert.That(array, Is.EqualTo(collection));
42        }
43
44        [Test]
45        public void FailureMatchingArrayAndCollection()
46        {
47            int[] expected = new int[] { 1, 2, 3 };
48            ICollection actual = new SimpleObjectCollection(1, 5, 3);
49
50            var ex = Assert.Throws<AssertionException>(() => Assert.That(actual, Is.EqualTo(expected)));
51            Assert.That(ex.Message, Is.EqualTo(
52                "  Expected is <System.Int32[3]>, actual is <NUnit.TestUtilities.Collections.SimpleObjectCollection> with 3 elements" + Env.NewLine +
53                "  Values differ at index [1]" + Env.NewLine +
54                TextMessageWriter.Pfx_Expected + "2" + Env.NewLine +
55                TextMessageWriter.Pfx_Actual + "5" + Env.NewLine));
56        }
57
58        [Test]
59        [TestCaseSource( "IgnoreCaseData" )]
60        public void HonorsIgnoreCase( IEnumerable expected, IEnumerable actual )
61        {
62            Assert.That( expected, Is.EqualTo( actual ).IgnoreCase );
63        }
64
65        private static readonly object[] IgnoreCaseData =
66        {
67            new object[] {new SimpleObjectCollection("x", "y", "z"),new SimpleObjectCollection("x", "Y", "Z")},
68            new object[] {new[] {'A', 'B', 'C'}, new object[] {'a', 'b', 'c'}},
69            new object[] {new[] {"a", "b", "c"}, new object[] {"A", "B", "C"}},
70            new object[] {new Dictionary<int, string> {{ 1, "a" }}, new Dictionary<int, string> {{ 1, "A" }}},
71            new object[] {new Dictionary<int, char> {{ 1, 'A' }}, new Dictionary<int, char> {{ 1, 'a' }}},
72            new object[] {new List<char> {'A', 'B', 'C'}, new List<char> {'a', 'b', 'c'}},
73            new object[] {new List<string> {"a", "b", "c"}, new List<string> {"A", "B", "C"}},
74        };
75
76    }
77}
78
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)