Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SomeClassFromDomainLayer
- {
- //some code
- #region private properties
- private IContext Context
- {
- get
- {
- if(_context==null)
- {
- _context = AppEnvironment.Kernel.Get<IContext>();
- }
- return _context;
- }
- }
- #endregion
- //some code
- }
- public class ContextNinjectModule : NinjectModule
- {
- public override void Load()
- {
- this.Bind<IContext>().To<RealContext>();
- }
- }
- public class TestContextNinjectModule : NinjectModule
- {
- public override void Load()
- {
- // делегат в ToMethod принимает параметр типа IContext -- это тип NInject'а,
- // не путайте с вашим собственным интерфейсом!
- this.Bind<IContext>().ToMethod(c => Substitute.For<IContext>());
- }
- }
- public void SomeTest
- {
- var context = module.Get<IContext>();
- context.SomeMethod().Returns(42);
- var classUnderTest = new ClassUnderTest(context);
- classUnderTest.Foo();
- context.Received().SomeMethod();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement