110,561
社区成员
发帖
与我相关
我的任务
分享
[TestMethod, Isolated]
public void SwapAllInstances_TwoFutureInstances_AllInstancesAreFakes()
{
var fake = Isolate.Fake.Instance<Product>();
Isolate.WhenCalled(()=> fake.CalculatePrice(0)).WillReturn(100);
// Here we are setting the same behavior on all instances.
// The behavior we set on fake will apply to all instances, so both product1 and product2 will have the same behavior.
Isolate.Swap.AllInstances<Product>().With(fake);
Product product1 = new Product();
Product product2 = new Product();
// Assert that the behavior applied to all instances.
Assert.AreEqual(100, product1.CalculatePrice(0));
Assert.AreEqual(100, product2.CalculatePrice(0));
}