, NUnit.Mocks, NMock Moq [, , ]. , , , NUnit.Mocks .
, , , , :
. ,
public interface IWebSiteConfiguration
{
CodeType getCodeByCodeNameAndType (
string codeString,
CatalogType catalogType);
}
. ""
public class WebSiteConfiguration : IWebSiteConfiguration { }
.
, c. . , , [ ]. c. ctor "IWebSiteConfiguration", . ,
public class MyClass
{
public MyClass () { }
public void DoSomething ()
{
code = WebSiteConfiguration.Instance.getCodeByCodeNameAndType (
"some.string",
someCatalog)
}
}
public class MyClass
{
private readonly IWebSiteConfiguration _config = null;
public MyClass () : this (WebSiteConfiguration.Instance) { }
public MyClass (IWebSiteConfiguration config)
{
_config = config;
}
public void DoSomething ()
{
code = _config.getCodeByCodeNameAndType ("some.string", someCatalog)
}
}
unit test, , .
[Test]
public void Test ()
{
IWebSiteConfiguration mockConfig = null;
MyClass myClass = new MyClass (mockConfig);
myClass.DoSomething ();
}
Injection Dependency [DI]. "" [, -] , , [, ].
, :)