This may already be answered and I am just not searching for the right keywords but I will ask it again....
Within my Architecture I have 2 Interfaces (one public lets call it ISpecificBlockEntity which implements IBlockEntity, and one internal IBlockEntitySetup).
I then have an object that implements both of these interfaces. Within my code I have the following generic method:
as you can see I don't want the functionality available in IBlockEntitySetup exposed outside of my library so I made that interface internal (the method shown in the entry point into the library).
What I need to do is mock an object for result (which is easy Mock.Create<ISpecificBlockEntity>()), and mock that same object as an IBlockEntitySetup so I can arrange the CreateEmptyEntity method to do nothing (and so setupEntity does not return null).
Here is the unit test for reference....
This isn't working, it says the profiler must be enabled to mock/asset target IBlockEntitySetup.CreateEmptyEntity() method.
I have also tried replacing mockedTowerSetup with (mockedTower as IBlockEntitySetup) in the arrange statement, but then I get a Not Implemented exception (which is odd since it should be mocked.....).
Debugging for whatever reason isn't working right even with the profiler disabled....
Is there anyway to do this? Am I coming at this from the wrong direction? Any help is greatly appreciated.
Within my Architecture I have 2 Interfaces (one public lets call it ISpecificBlockEntity which implements IBlockEntity, and one internal IBlockEntitySetup).
I then have an object that implements both of these interfaces. Within my code I have the following generic method:
public
TResult CreateEmptyEntity<TResult>() where TResult : IBlockEntity
{
var result = DependencyInjector.InjectEntity<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>();
}
as you can see I don't want the functionality available in IBlockEntitySetup exposed outside of my library so I made that interface internal (the method shown in the entry point into the library).
What I need to do is mock an object for result (which is easy Mock.Create<ISpecificBlockEntity>()), and mock that same object as an IBlockEntitySetup so I can arrange the CreateEmptyEntity method to do nothing (and so setupEntity does not return null).
Here is the unit test for reference....
[Test]
public
void
Test0010DependencyInjectionGetMethodCalledOnceWithCorrectType()
{
var mockedTower = Mock.Create<ITowerConfiguration>();
var mockedTowerSetup = mockedTower
as
IBlockEntitySetup;
Mock.Arrange(() => mockedTowerSetup.CreateEmptyEntity<ITowerConfiguration>()).DoNothing();
Mock.Arrange(() => InjectorMock.InjectEntity<ITowerConfiguration>()).Returns(mockedTowerSetup
as
ITowerConfiguration).OccursOnce();
Target.CreateEmptyEntity<ITowerConfiguration>();
Mock.Assert(Target);
}
I have also tried replacing mockedTowerSetup with (mockedTower as IBlockEntitySetup) in the arrange statement, but then I get a Not Implemented exception (which is odd since it should be mocked.....).
Debugging for whatever reason isn't working right even with the profiler disabled....
Is there anyway to do this? Am I coming at this from the wrong direction? Any help is greatly appreciated.