I'm trying to unit test an object that uses a generic static factory class. I'm not really at liberty to write out the factory.
I have to use Microsoft Fakes to shim it. (I think) Never used it before. My question is that it is a generic factory method used three times and needs to return 3 different sets of results. Mock has the ability to seqence a method and return different results each time. Does Fakes have this ability?
public static ReadOnlyCollection<T> Build<T>(IObjectA objA, IObjectB objB) where T : class
Inside the object it calls this method 3 times with different interfaces
IEnumerable<Base1> list = Factory.Build<Base1>(objA, objB);
IEnumerable<Interface1> list= Factory.Build<Interface1>(objA, objB);
IEnumerable<Interface2> list= Factory.Build<Interface2>(objA, objB);
How would the test method look for something like that?
using(ShimsContext.Create()) {
Mock<Base1> mockObj1 = new Mock<Base1>();
//manager.Setup(t=> t.)
Mock<Interface1> mockObj2= new Mock<Interface1>();
//manager.Setup(t=> t.)
Fakes.ShimFactory.BuildOf1IObjectAIObjectB<Base1>((objA, objB) => new List<Base1>() { mockObj1.Object }.AsReadOnly());
Fakes.ShimFactory.BuildOf1IObjectAIObjectB<Interface1>((objA, objB) => new
List<Interface1>() { mockobj2.Object }.AsReadOnly());
MyObjectThatUsesTheFactory = new MyObjectThatUsesTheFactory();
//test
}
Thanks for any pointers!
Aucun commentaire:
Enregistrer un commentaire