ChannelAdam .NET Library Updates & Deprecations

Overview

The release of .NET 5.0 in November 2020 marked a significant milestone for the .NET ecosystem.

As such, I have updated the ChannelAdam .NET libraries to:

  1. multi-target both .NET 5.0 and .NET Standard 2.0 - as per my guidance on .NET 5.0 for library developers;
  2. enable Nullable Reference Types and update the code base accordingly to be semantically correct in that regard; and
  3. deprecate libraries that have features that are no longer supported by Microsoft or the library dependencies.

Updated Libraries

The following 18 ChannelAdam .NET libraries now have been updated to multi-target .NET 5.0, .NET Standard 2.x (and if any, their previously supported .NET Standard 1.x versions) and enable Nullable Reference Types.

The ChannelAdam.Nancy libraries also have been updated to target .NET 5.0, .NET Standard 2.0 and Nancy v2.0.0, but also now have been deprecated, as Nancy is no longer being maintained.

Deprecated Libraries

The following 6 libraries now have been deprecated.

The ChannelAdam Test Framework xUnit Library

Overview

This is an open source, .NET library that provides helpers for using xUnit (and Moq) on top of the ChannelAdam Test Framework Library.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.TestFramework.Xunit NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.TestFramework.Xunit

Usage

 1using ChannelAdam.TestFramework.Xunit.Abstractions;
 2...
 3    [TestFixture]
 4    public class MyUnitTests : MoqTestFixture
 5    {
 6        Mock<IMyService> _mockMyService;
 7
 8        [Test]
 9        public void MyTestMethodWithMockObjects()
10        {
11            // ARRANGE
12            _mockMyService = base.MyMockRepository.Create<IMyService>();
13            _mockMyService.Setup(...)
14                .Returns(...);
15
16            // ACT
17            ...
18
19            // ASSERT
20            LogAssert...
21
22            Logger.Log("Verifying all mock expectations were met");
23            MyMockRepository.VerifyAll();
24        }
25
26        [Test]
27        public void MyTestMethod()
28        {
29            // ARRANGE
30            bool isOrderLateExpected = false;
31
32            // ACT
33            Logger.Log("About to do the ACT part of blah blah... so the test output reads like a story");
34            bool isOrderLateActual = true;
35
36            // ASSERT
37            LogAssert.AreEqual("isOrderLate", isOrderLateExpected, isOrderLateActual);
38            // Test Output: "Asserting isOrderLate is equal to: false"
39        }
40    }

See MakingSoap12UnitSteps.cs for an MSTest V2 example of using the TestEasy base class directly without Moq.

Reference

MoqTestFixture inherits from the ChannelAdam Test Framework Moq Library MoqTestFixture class to provide Moq MockRepository functionality on top of its own extension of TestEasy.

Please see the ChannelAdam Test Framework Library documentation for more information about TestEasy.

The ChannelAdam XML Library

Overview

An open source, .NET Standard 2.0 library that provides helpful XML functionality that makes XML validation, serialisation and type conversion easy.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.Xml NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.Xml

Usage

 1using ChannelAdam.Xml;
 2...
 3
 4    [XmlRoot(Namespace = "uri:normal:namespace")]
 5    public class ObjectForXmlStuff
 6    {
 7        public string MyStringProperty { get; set; }
 8
 9        [XmlElement(Namespace = "uri:different:namespace")]
10        public string MyStringPropertyWithDifferentNamespace { get; set; }
11
12        public int MyIntProperty { get; set; }
13    }
14
15    public class Stuff
16    {
17        public void SerialiseAndDeserialseXml()
18        {
19            var xmlObject = new ObjectForXmlStuff();
20            xmlObject.MyStringProperty = "hello";
21
22            string xml = xmlObject.SerialiseToXml();
23
24            var xmlObject2 = xml.DeserialiseFromXml<ObjectForXmlStuff>();
25        }
26    }

See XmlSerialisationUnitTestSteps.cs for more examples.

Reference

The ChannelAdam Test Framework Library

Overview

This is an open source, .NET Standard 1.3 library that provides the abstract base class foundations for automated testing - designed to make it easier to implement test cases and to read their output.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.TestFramework NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.TestFramework

Usage

This library is intended for use by other Test Framework implementation libraries that are then to be used by application developers, such as:

Reference

Logger

Logging useful information to the output of a test is extremely important.

The Simple Logger interface in the ChannelAdam Logging Library provides a very simple Log method that is intended for usage in scenarios such writing test output.

Log and then Assert

I cannot emphasise enough how important it is to log useful to the output of a test. Developers and analysts almost should be able to read the output of a test like a story. Analysts especially should review the test outputs and be satisfied that the test was implemented correctly - almost as if they performed the test themselves. Therefore, when an assertion is performed, we want the test output to actually tell us that an assertion is taking place and provide a information about what is being asserted.

The Log Asserter interface provides all the usual assertion methods that you are familiar with, and the first parameter of all of the methods is a string that will be outputted to an ISimpleLogger (provided in the constructor) before performing the actual assertion. This string is intended to provide the reader of the test output with a human-readable description of what is being asserted, often times just the name of the field/property being asserted, or something more descriptive for say an IsTrue or IsFalse method.

Test Easy Base Class for Tests

Logging, assertions and testing for exceptions are 3 of some fundamental features common to most automated test suites. Wouldn’t it be nice to be able to perform that functionality easily and keep your test code to a minimum?

The TestEasy base class for tests provides those abilities.

This class provides the following helpful properties.

  • ISimpleLogger Logger - for logging to the test output
  • ILogAsserter LogAssert - your handy-dandy log asserter
  • ExpectedExceptionDescriptor ExpectedException - describes the exception that is expected to occur for a specific test case
  • Exception ActualException - for storing the actual exception that occurred

When the ActualException property is set, the details are automatically logged to the test output.

TestEasy also contains the following helpful methods:

  • void Try(Action action) - performs the given action and catches exceptions into ActualException
  • void Try(Func<Task> action) - performs the given asynchronous action that returns a Task, waits for it finish, and catches exceptions into ActualException
  • void AssertNoExceptionOccurred() - asserts that no ActualException exists/occurred
  • void AssertExpectedException(Type expectedExceptionType) - asserts that type of the value of ActualException is the given expected type
  • void AssertExpectedException() - asserts that the ActualException is equivalent to that described by the ExpectedException descriptor.

When the ActualException is an System.AggregateException, the assertion will pass if there is at least one inner exception equivalent to the ExpectedException descriptor.

Expected Exception Descriptor

The ExpectedException property is implemented by the ExpectedExceptionDescriptor class. This class describes the exception that is expected to occur.

There are 2 properties in ExpectedExceptionDescriptor that are specifically used in the AssertExpectedException() method:

  • string MessageShouldContainText - which describes the substring that the ActualException.Message property should contain
  • Type ExpectedType - which describes the System.Type that ActualException should be.

Either or both of these properties can be set. When set, the details are automatically logged to the test output.

The ChannelAdam Test Framework XML Library

Overview

This is an open source, .NET Standard 2.0 library that provides helpers for comparing text and flat files (using XMLUnit.NET), optionally in conjunction with one of the ChannelAdam Test Framework Libraries:

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.TestFramework.Xml NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.TestFramework.Xml

Usage

 1using ChannelAdam.TestFramework.Xml;
 2...
 3    [TextFixture]
 4    public class MyUnitTests : MoqTestFixture
 5    {
 6        private XmlTester _xmlTester;
 7
 8        [SetUp]
 9        public Setup()
10        {
11            _xmlTester = new XmlTester(base.LogAssert);
12        }
13
14        [Test]
15        public void MyTestMethod()
16        {
17            // ARRANGE
18            _xmlTester.ArrangeExpectedXml(@"<a><b>hi</b></a>");
19
20            // ACT
21            Logger.Log("About to do the ACT part of blah blah... so the test output reads like a story");
22            _xmlTester.ArrangeActualXml(@"<a><c>c</c></a>");
23
24            // ASSERT
25            Logger.Log("Comparing...");
26            LogAssert.IsTrue("XML samples are different", _xmlTester.IsEqual());
27            // OR
28            _xmlTester.AssertActualXmlEqualsExpectedXml();
29            // The test output will have a helpful Diff.
30        }
31    }

See XmlTestingUnitSteps.cs for an example of using the XmlTester helper.

Reference

XML Tester

The XmlTester class is used in tests for asserting whether the actual XML is similar enough to the given expected XML.

Under the covers, it uses the XMLUnit.NET open source library to identify differences.

The XmlTester class has the following properties:

  • XElement ActualXml
  • XElement ExpectedXml
  • Diff Differences

The XmlTester class has the following Arrange methods:

  • void ArrangeActualXml(Assembly assembly, string resourceName) - to arrange the actual XML from an embedded resource in the given assembly
  • void ArrangeActualXml(XElement xmlElement) - to arrange the actual XML from a given XElement
  • void ArrangeActualXml(object valueToSerialise) - to arrange the actual XML by serialising the given object
  • void ArrangeActualXml(object valueToSerialise, XmlRootAttribute xmlRootAttribute) - to arrange the actual XML by serialising the given object and applying the given XmlRootAttribute during the serialisation
  • void ArrangeActualXml(object valueToSerialise, XmlAttributeOverrides xmlAttributeOverrides) - to arrange the actual XML by serialising the given object and applying the given XmlAttributeOverrides during the serialisation
  • void ArrangeActualXml(string xmlValue) - to arrange the actual XML from the given XML string
  • void ArrangeExpectedXml(Assembly assembly, string resourceName) - to arrange the expected XML from an embedded resource in the given assembly
  • void ArrangeExpectedXml(XElement xmlElement) - to arrange the expected XML from a given XElement
  • void ArrangeExpectedXml(object valueToSerialise) - to arrange the expected XML by serialising the given object
  • void ArrangeExpectedXml(object valueToSerialise, XmlRootAttribute xmlRootAttribute) - to arrange the expected XML by serialising the given object and applying the given XmlRootAttribute during the serialisation
  • void ArrangeExpectedXml(object valueToSerialise, XmlAttributeOverrides xmlAttributeOverrides) - to arrange the expected XML by serialising the given object and applying the given XmlAttributeOverrides during the serialisation
  • void ArrangeExpectedXml(string xmlValue) - to arrange the expected XML from the given XML string

The XmlTester class has the following Assert methods:

  • virtual void AssertActualXmlEqualsExpectedXml() - to assert the actual XML against the expected XML
  • virtual void AssertActualXmlEqualsExpectedXml(IXmlFilter xmlFilter) - to assert the actual XML against the expected XML, ignoring items listed in the given IXmlFilter (see below)
  • bool IsEqual() - determines if the given actual and expected XML is equivalent
  • bool IsEqual(XNode expected, XNode actual) - determines if the given actual and expected XNode XML is equivalent
  • virtual bool IsEqual(XmlNode expected, XmlNode actual) - determines if the given actual and expected XmlNode XML is equivalent

Ignoring / Filtering XML Elements

The AssertActualXmlEqualsExpectedXml(IXmlFilter xmlFilter) override allows you to specify an IXmlFilter interface which allows you to specify a list of the local names of XML elements to ignore in comparisons, and/or a list of XPath expressions to ignore in comparisons.

Examples

For a quick example, please see the Behaviour Specification for the XmlTester class and the XML tester code

XML Filter

The XmlFilter class allows you to specify a list of the local names of XML elements to ignore in comparisons, and/or a list of XPath expressions to ignore in comparisons.

Two constructor methods allow you to easily specify these lists.

  • XmlFilter(IList<string> elementLocalNamesToIgnore)
  • XmlFilter(IList<string> elementLocalNamesToIgnore, IList<string> xpathsToIgnore)

XML Asserter

The XmlAsserter class provides utility methods for performing assertions on XML values. It has the following methods:

  • void XPathValueEquals(string description, string xpath, XNode rootElement, string expected) - to assert that the given XPath of the provided XNode has the given expected string value
  • void XPathValueEquals(string description, string xpath, XNode rootElement, XmlNamespaceManager namespaceManager, string expected) - uses the provided namespace manager to assert that the given XPath of the provided XNode has the given expected string value
  • void XPathValuesAreEqual(string description, string xpath, XNode expectedElements, XNode actualElements) - to assert that the value of the XPath in the given actual XNode equals the corresponding value in the given expected XNode
  • void XPathValuesAreEqual(string description, string expectedXpath, XNode expectedElements, string actualXpath, XNode actualElements) - to assert that the value of the actual XPath in the actual XNode is the same as the value of the expected XPath in the expected XNode
  • void XPathValuesAreEqual(string description, string expectedXpath, XNode expectedElements, XmlNamespaceManager expectedNamespaceManager, string actualXpath, XNode actualElements, XmlNamespaceManager actualNamespaceManager) - to assert that the value of the actual XPath in the actual XNode is the same as the value of the expected XPath in the expected XNode, using the provided XML namespace managers
  • void AreEqual(XElement expectedXml, XElement actualXml) - to assert that the given expected XElement is equivalent to the actual XElement
  • void AreEqual(XElement expectedXml, XElement actualXml, IXmlFilter xmlFilter) - to assert that the given expected XElement is equivalent to the actual XElement - using the given IXmlFilter

Mapping Testers

There are 3 map tester classes to be used depending on the type of input and output of your map:

The MappingFromXmlToXmlTester class has the following method overrides for arranging the input XML.

  • void ArrangeInputXml(Assembly assembly, string resourceName) - to arrange the input XML from an embedded resource in the given assembly
  • void ArrangeInputXml(XElement xmlElement) - to arrange the input XML from a given XElement
  • void ArrangeInputXml(object valueToSerialise) - to arrange the input XML by serialising the given object
  • void ArrangeInputXml(object valueToSerialise, XmlRootAttribute xmlRootAttribute) - to arrange the input XML by serialising the given object and applying the given XmlRootAttribute during the serialisation
  • void ArrangeInputXml(object valueToSerialise, XmlAttributeOverrides xmlAttributeOverrides) - to arrange the input XML by serialising the given object and applying the given XmlAttributeOverrides during the serialisation
  • void ArrangeInputXml(string xmlValue) - to arrange the input XML from the given XML string
  • void ArrangeExpectedOutputXml(Assembly assembly, string resourceName) - to arrange the expected output XML from an embedded resource in the given assembly
  • void ArrangeExpectedOutputXml(XElement xmlElement) - to arrange the expected output XML from a given XElement
  • void ArrangeExpectedOutputXml(object valueToSerialise) - to arrange the expected output XML by serialising the given object
  • void ArrangeExpectedOutputXml(object valueToSerialise, XmlRootAttribute xmlRootAttribute) - to arrange the expected output XML by serialising the given object and applying the given XmlRootAttribute during the serialisation
  • void ArrangeExpectedOutputXml(object valueToSerialise, XmlAttributeOverrides xmlAttributeOverrides) - to arrange the expected output XML by serialising the given object and applying the given XmlAttributeOverrides during the serialisation
  • void ArrangeExpectedOutputXml(string xmlValue) - to arrange the expected output XML from the given XML string

Input can be arranged from an embedded resource, XElement, object that is XML serialisable (for which you can also override the root XML namespace when serialised) or simply a string.

This same pattern is followed for arranging the expected output of the map, and for arranging the contents of flat files with the other map tester classes.

Assert - Compare the Actual Output Against the Expected Output

The MappingFromXmlToXmlTester class has the following method overrides for asserting the actual output from the map against the expected output that was arranged.

  • void AssertActualOutputXmlEqualsExpectedOutputXml()
  • AssertActualOutputXmlEqualsExpectedOutputXml(IXmlFilter xmlFilter) (see below)

All the comparison and logging and formatting of any differences is done for you. Easy!

Ignoring / Filtering XML Elements

The AssertActualOutputXmlEqualsExpectedOutputXml(IXmlFilter xmlFilter) override allows you to specify an IXmlFilter which allows you to specify a list of the local names of XML elements to ignore in comparisons, and/or a list of XPath expressions to ignore in comparisons.

Two constructor methods on XmlFilter allow you to easily specify these lists.

  • XmlFilter(IList<string> elementLocalNamesToIgnore)
  • XmlFilter(IList<string> elementLocalNamesToIgnore, IList<string> xpathsToIgnore)

The ChannelAdam Test Framework MSTest V2 Library

Overview

This is an open source, .NET Standard 1.3 library that provides helpers for using MSTest V2 (and Moq) on top of the ChannelAdam Test Framework Library.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.TestFramework.MSTestV2 NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.TestFramework.MSTestV2

Usage

 1using ChannelAdam.TestFramework.MSTestV2.Abstractions;
 2...
 3    [TestClass]
 4    public class MyUnitTests : MoqTestFixture
 5    {
 6        Mock<IMyService> _mockMyService;
 7
 8        [TestMethod]
 9        public void MyTestMethodWithMockObjects()
10        {
11            // ARRANGE
12            _mockMyService = base.MyMockRepository.Create<IMyService>();
13            _mockMyService.Setup(...)
14                .Returns(...);
15
16            // ACT
17            ...
18
19            // ASSERT
20            LogAssert...
21
22            Logger.Log("Verifying all mock expectations were met");
23            MyMockRepository.VerifyAll();
24        }
25
26        [TestMethod]
27        public void MyTestMethod()
28        {
29            // ARRANGE
30            bool isOrderLateExpected = false;
31
32            // ACT
33            Logger.Log("About to do the ACT part of blah blah... so the test output reads like a story");
34            bool isOrderLateActual = true;
35
36            // ASSERT
37            LogAssert.AreEqual("isOrderLate", isOrderLateExpected, isOrderLateActual);
38            // Test Output: "Asserting isOrderLate is equal to: false"
39        }
40    }

See MakingSoap12UnitSteps.cs for an example of using the TestEasy base class directly without Moq.

Reference

MoqTestFixture inherits from the ChannelAdam Test Framework Moq Library MoqTestFixture class to provide Moq MockRepository functionality on top of its own extension of TestEasy.

Please see the ChannelAdam Test Framework Library documentation for more information about TestEasy.

The ChannelAdam Test Framework NUnit Library

Overview

This is an open source, .NET Standard 1.6 library that provides helpers for using NUnit (and Moq) on top of the ChannelAdam Test Framework Library.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.TestFramework.NUnit NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.TestFramework.NUnit

Usage

 1using ChannelAdam.TestFramework.NUnit.Abstractions;
 2...
 3    [TestFixture]
 4    public class MyUnitTests : MoqTestFixture
 5    {
 6        Mock<IMyService> _mockMyService;
 7
 8        [Test]
 9        public void MyTestMethodWithMockObjects()
10        {
11            // ARRANGE
12            _mockMyService = base.MyMockRepository.Create<IMyService>();
13            _mockMyService.Setup(...)
14                .Returns(...);
15
16            // ACT
17            ...
18
19            // ASSERT
20            LogAssert...
21
22            Logger.Log("Verifying all mock expectations were met");
23            MyMockRepository.VerifyAll();
24        }
25
26        [Test]
27        public void MyTestMethod()
28        {
29            // ARRANGE
30            bool isOrderLateExpected = false;
31
32            // ACT
33            Logger.Log("About to do the ACT part of blah blah... so the test output reads like a story");
34            bool isOrderLateActual = true;
35
36            // ASSERT
37            LogAssert.AreEqual("isOrderLate", isOrderLateExpected, isOrderLateActual);
38            // Test Output: "Asserting isOrderLate is equal to: false"
39        }
40    }

See MakingSoap12UnitSteps.cs for an MSTest V2 example of using the TestEasy base class directly without Moq.

Reference

MoqTestFixture inherits from the ChannelAdam Test Framework Moq Library MoqTestFixture class to provide Moq MockRepository functionality on top of its own extension of TestEasy.

Please see the ChannelAdam Test Framework Library documentation for more information about TestEasy.

The ChannelAdam Test Framework Text Library

Overview

This is an open source, .NET Standard 1.3 library that provides helpers for comparing text and flat files (using DiffPlex), optionally in conjunction with one of the ChannelAdam Test Framework Libraries:

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.TestFramework.Text NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.TestFramework.Text

Usage

 1using ChannelAdam.TestFramework.Text;
 2...
 3    [TextFixture]
 4    public class MyUnitTests : MoqTestFixture
 5    {
 6        private TextTester _textTester;
 7
 8        [SetUp]
 9        public Setup()
10        {
11            _textTester = new TextTester(base.LogAssert);
12        }
13
14        [Test]
15        public void MyTestMethod()
16        {
17            // ARRANGE
18            _textTester.ArrangeExpectedText("The brown bull");
19
20            // ACT
21            Logger.Log("About to do the ACT part of blah blah... so the test output reads like a story");
22            _textTester.ArrangeActualText("The red bull");
23
24            // ASSERT
25            Logger.Log("Comparing...");
26            LogAssert.IsTrue("Text samples are different", _textTester.IsEqual());
27            // OR
28            _textTester.AssertActualTextEqualsExpectedText();
29            // The test output will have a helpful Diff.
30        }
31    }

See TextTestingUnitSteps.cs for an example of using the TextTester helper - especially to see how to filter and override differences.

Reference

TextTester

The TextTester class is used in tests for asserting whether actual text is similar enough to the given expected text.

Under the covers, it uses the DiffPlex open source library to identify differences.

The TextTester class has the following properties:

  • string ActualText
  • string ExpectedText
  • DiffPaneModel Differences
  • Action<DiffPaneModel> TextDifferenceFilter - a filter for the diff (see below)

The TextTester class has the following Arrange methods:

  • void ArrangeActualText(Assembly assembly, string resourceName) - to arrange the actual text from an embedded resource in the given assembly
  • void ArrangeActualText(string text) - to arrange the actual text from the given string
  • void ArrangeExpectedText(Assembly assembly, string resourceName) - to arrange the expected text from an embedded resource in the given assembly
  • void ArrangeExpectedText(string text) - to arrange the expected text from the given string

The TextTester class has the following Assert methods:

  • virtual void AssertActualTextEqualsExpectedText() - to assert the actual text against the expected text
  • bool IsEqual() - determines if the given actual and expected text is equivalent
  • virtual bool IsEqual(string expected, string actual) - determines if the given actual and expected text is equivalent

All the comparison and logging and formatting of any differences is done for you. Easy!

Ignoring / Filtering Text Differences

The TextTester class provides 3 mechanisms for hooking into the DiffPlex DiffPaneModel difference result, allowing you to manipulate it before a final decision is made as
to whether or not the actual text is similar enough to the expected text.

  • An event that is raised with the differences
1    /// <summary>
2    /// Occurs when a text difference is detected, allowing a listener to filter the differences and
3    /// change the Line[x].Type to ChangeType.UnChanged so that the difference is no longer treated as a difference.
4    /// </summary>
5    /// <remarks>
6    /// This event or the TextDifferenceFilter property can be used for this purpose.
7    /// </remarks>
8    public event EventHandler<TextDifferenceDetectedEventArgs> TextDifferenceDetectedEvent;
  • An action delegate method that is called with the differences
1    /// <summary>
2    /// Gets or sets the Action delegate to be invoked when a text difference is detected, allowing differences to be filtered out by
3    /// changing the Line[x].Type to ChangeType.UnChanged - so that a difference is no longer treated as a difference.
4    /// </summary>
5    /// <value>The Action delegate.</value>
6    /// <remarks>
7    /// This property or TextDifferenceDetectedEvent can be used for this purpose.
8    /// </remarks>
9    public Action<DiffPaneModel> TextDifferenceFilter { get; set; }
  • A virtual method that allows you to inherit from the tester class and override the differences when they are detected.
1    protected virtual void OnTextDifferenceDetected(DiffPaneModel differences)

For a quick example, please see the Behaviour Specification for the TextTester class and the associated text tester code.

Mapping Tester

The MappingFromFlatFileToFlatFileTester class provides a wrapper around TextTester specifically for the purpose of testing the mapping from one flat file to another.

The ChannelAdam Transient Fault Handling Library

Overview

An open source, .NET Standard 1.0 library that provides an abstraction for implementing retry policies.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.TransientFaultHandling NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.TransientFaultHandling

Usage

See Sample Retry Policy Adapter for an example of implementing an IRetryPolicyFunction.

Reference

Some handy interfaces to describe retry policies.

The ChannelAdam Weak Events Library

Overview

An open source, .NET Standard 2.0 library for events that enforces a weak reference to the event handler.

You may need a Weak Event Pattern in specific circumstances to prevent memory leaks in your event listeners.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.WeakEvents NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.WeakEvents

Usage

 1using ChannelAdam.Events;
 2...
 3
 4public class ExampleEventOwner
 5{
 6    private WeakEvent<EventArgs> _myEvent = new WeakEvent<EventArgs>();
 7
 8    public IWeakEvent<EventArgs> MyEvent
 9    {
10        get { return _myEvent; }
11    }
12
13    ...
14
15    protected virtual void OnMyEvent()
16    {
17        _myEvent.Invoke(this, EventArgs.Empty);
18    }
19}
20
21
22public class ExampleEventSubscriber : ChannelAdam.Disposing.DisposableWithDestructor
23{
24    private ExampleEventOwner _eventOwner;
25
26    public ExampleEventSubscriber()
27    {
28        _eventOwner = new ExampleEventOwner()
29        _eventOwner.MyEvent.Subscribe(MyEventHandler);
30    }
31
32    private void MyEventHandler(object sender, EventArgs e)
33    {
34        // MyEvent occurred
35    }
36
37    protected override void DisposeManagedResources()
38    {
39        _eventOwner?.MyEvent?.Unsubscribe(MyEventHandler);
40    }
41}

Reference