Allows to create interfaces for non-mockable classes.
- .NET Framework 4.5
Install the NuGet package using the command below:
Install-Package Ninject.Extensions.Perspectives
...or search for Ninject.Extensions.Perspectives
in the NuGet index.
If you want to test classes without interfaces. This package is the best you can get.
For example take the System.IO.Path
class:
-
Create a new interface called
IPath.cs
and added the (same) methods you need of the original class.interface IPath { string GetRandomFileName(); }
-
Add a perspective binding:
using Ninject.Extensions.Perspectives; ... // Bindings kernel.Bind<IPath>().ToPerspective(typeof(Path)); // Resolve var path = kernel.Get<IPath>(); // Use var randomFileName = path.GetRandomFileName();
-
Have fun.
- Statics (e.g.
System.IO.Path
) - Instances (e.g.
System.Net.Sockets.Socket
) - Generics (e.g.
System.Collections.Generic.List<>
)