How to use Moq to satisfy a MEF import dependency for unit testing?

前端 未结 2 452
耶瑟儿~
耶瑟儿~ 2021-01-13 15:49

This is my interface

public interface IWork
{
    string GetIdentifierForItem(Information information);
}

and my class

publ         


        
2条回答
  •  攒了一身酷
    2021-01-13 16:15

    This is how it may be done, after setting up the mocks

    1) Creating a CompositionContainer, that holds the imports.

    2) Adding Mocks to the container.

    container.ComposeExportedValue(mock.Object);
    

    3) Create an instance of tested class

    4) Compose mocks to the import

    container.ComposeParts(instance);
    

提交回复
热议问题