Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using HWSysManagerLib;
- bool ProcessBias(HWSysManager systemManager, string hwPath)
- {
- int handle = systemManager.OpenConfiguration(hwPath);
- ...
- // some magic goes here
- // return result
- }
- public interface IHWSysManager
- {
- int OpenConfiguration(string hwPath);
- }
- public class HWSysManagerImpl : IHWSysManager
- {
- private HWSysManager _hwSysManager; //Initialize from constructor
- public int OpenConfiguration(string hwPath)
- {
- return _hwSysManager.openConfiguration(hwPath);
- }
- }
- bool ProcessBias(IHWSysManager systemManager, string hwPath)
- {
- int handle = systemManager.OpenConfiguration(hwPath);
- ...
- // some magic goes here
- // return result
- }
- var fakeManager = Isolate.Fake.Instance<HWSysManager>();
- Isolate.WhenCalled(() => fakeManager.OpenConfiguration("")).WillReturn(0);
- Isolate.WhenCalled(() => fakeManager.OpenConfiguration("")).DoInstead(
- context =>
- {
- //Your simulation
- });
- class HWSysManager
- {
- public virtual int ExampleReturnIntMethod(int a)
- {
- var someInt = 0;
- return someInt;
- }
- public void TestMethod()
- {
- Mock<HWSysManager> hwSysManager = new Mock<HWSysManager>();
- hwSysManager.Setup(x => x.ExampleReturnInMethod(It.IsAny<int> ())).Returns(10); //if parameter is any of int, return 10 in this case
- }
- var hwSysInstance = hwSysManager.Object;
- var result = hwSysInstance.ExampleReturnInMethod(2); //result will be 10 in this case - as we have mocked
- public interface HwsysManager
- {
- int OpenConfiguration(string hwPath);
- }
- public void TestMethod()
- {
- Mock<HwsysManager> hwsysManager = new Mock<HwsysManager>();
- hwsysManager.Setup(x => x.OpenConfiguration(It.IsAny<string>())).Returns(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement