Multiple Interface Mocking

7 posts, 0 answers
  1. Chris
    Chris avatar
    21 posts
    Member since:
    Oct 2012

    Posted 10 Oct 2012 Link to this post

    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:
    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);
           }
    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.

  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 12 Oct 2012 Link to this post

    Hi Chris,

    Thanks again for contacting us. 

    However, I would request you to create a sample project and send it over to me so that I can debug further down your issue and send you a solution as soon as possible. 


    Kind Regards
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft R3 2016 release webinar banner
  4. Chris
    Chris avatar
    21 posts
    Member since:
    Oct 2012

    Posted 15 Oct 2012 Link to this post

    I have created a very very basic project that I think should help to illustrate the question. The forum won't let me upload a .zip file though....is there an email address I should use or should I create a support ticket?

  5. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 16 Oct 2012 Link to this post

    Hi Chris,
    Thanks again for the sample.

    You can send it to mehfuz dot hossain at telerik dot com (made it spam safe). I will check it out and keep you posted on the possible solution.

    Kind Regards
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Chris
    Chris avatar
    21 posts
    Member since:
    Oct 2012

    Posted 18 Oct 2012 Link to this post

    all done sent it a few days ago.
  7. Chris
    Chris avatar
    21 posts
    Member since:
    Oct 2012

    Posted 22 Oct 2012 Link to this post

    Any progress on this question? Is there anything I can do to help? Have I made the question clear or can I provide more information to help clarify the question?
  8. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 22 Oct 2012 Link to this post

    Hi Chris,

    Thanks again for the heads up. I am working on the issue and hopefully will send you an update here in a day or two.


    Kind Regards
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft R3 2016 release webinar banner