I am sure I am doing something wrong but I can't for the life of me figure it out.... (of course it doesn't help that I can't debug the application reliably with the profiler enabled....)
So here is my challenge and hopefully someone can help me with it...
I have the following production method:
This method is using Ninject (as an internal property to this class (DependencyInjector is of type IKernel) to get the appropriate object to use for result....
I am trying to unit test this method with the following method:
Unfortunately its not working.. I am encountering my custom exception inside the if block (although when I look at result it equals null as I am attempting to debug (which is not working right due to the profiler being enabled).
I am just trying to verify that a call to my production method with a certain templated type then results in a call to get with the same type.
Any thoughts?
So here is my challenge and hopefully someone can help me with it...
I have the following production method:
public TResult CreateEmptyEntity<TResult>() where TResult : IBlockEntity { var result = DependencyInjector.Get<TResult>(); var setupEntity = (result as IBlockEntitySetup); if (setupEntity == null) { throw new EntitySetupNotSupportedException( "Entity type requested does not support construction through this method."); } return result = setupEntity.CreateEmptyEntity‎<TResult>(); }This method is using Ninject (as an internal property to this class (DependencyInjector is of type IKernel) to get the appropriate object to use for result....
I am trying to unit test this method with the following method:
[TestFixture] public class ProtocolABlockTranslatorTestBase { protected ProtocolABlockTranslator Target; protected IKernel KernelMock; [SetUp] public void BaseInitializer() { KernelMock = new StandardKernel(); Target = Mock.Create<ProtocolABlockTranslator>(Constructor.Mocked, Behavior.CallOriginal); } } [TestFixture] public class CreateEmptyEntityTests : ProtocolABlockTranslatorTestBase { [SetUp] public void MyInitialization() { } [Test] public void Test0010DependencyInjectionGetMethodCalledOnceWithCorrectType() { KernelMock.Bind<ITowerConfiguration>().To<MockedTowerConfigSetup>(); Mock.Arrange(() => KernelMock.Get<ITowerConfiguration>()).OccursOnce(); Target.DependencyInjector = KernelMock; Target.CreateEmptyEntity<ITowerConfiguration>(); Mock.Assert(KernelMock); } }Unfortunately its not working.. I am encountering my custom exception inside the if block (although when I look at result it equals null as I am attempting to debug (which is not working right due to the profiler being enabled).
I am just trying to verify that a call to my production method with a certain templated type then results in a call to get with the same type.
Any thoughts?