Skip to content

Instantly share code, notes, and snippets.

@MelbourneDeveloper
Last active July 29, 2021 07:42
Show Gist options
  • Select an option

  • Save MelbourneDeveloper/b8adb08622b2352e6d303db4794caa96 to your computer and use it in GitHub Desktop.

Select an option

Save MelbourneDeveloper/b8adb08622b2352e6d303db4794caa96 to your computer and use it in GitHub Desktop.
Null Object Pattern Example
#nullable enable
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestProject4
{
public interface IDependency { void DoSomething(); }
public class NullDependency : IDependency
{
public void DoSomething() { }
}
public class Example
{
readonly IDependency dependency;
public Example(IDependency? dependency = null)
{
this.dependency = dependency ?? new NullDependency();
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
new Example();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment