Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void FakeSaveWithMessage(Transaction t) {
- t.Message = "I drink goats blood";
- }
- public delegate void FakeSave(Transaction t);
- public void SampleTestFunction() {
- ...
- Expect.Call(delegate { _dao.Save(t); }).Do(new FakeSave(FakeSaveWithMessage));
- ...
- }
- Expect.Call(delegate { _dao.Save(t); }).Do(delegate(Transaction t2) { t2.Message = "I drink goats blood"; });
- Expect.Call(delegate { _dao.Save(t); }).Do(delegate { t.Message = "I drink goats blood"; });
- public delegate void FakeSave(Transaction t);
- ...
- Expect.Call(delegate { _dao.Save(t); }).Do( new FakeSave(delegate(Transaction t2) { t.Message = expected_msg; }));
- private void MyMethod()
- {
- }
- 1) Delegate d = delegate() { }; // Cannot convert anonymous method to type ‘System.Delegate’ because it is not a delegate type
- 2) Delegate d2 = MyMethod; // Cannot convert method group ‘MyMethod’ to non-delegate type ‘System.Delegate’
- 3) Delegate d3 = (WaitCallback)MyMethod; // No overload for ‘MyMethod’ matches delegate ‘System.Threading.WaitCallback’
- 4) Delegate d4 = (MethodInvoker)MyMethod; // Works because we cast to a delegate type of the same signature.
- 5) Delegate d5 = (Action)delegate { }; // Works for same reason as d4.
- 6) Action d6 = MyMethod; // Delegate inference at work here. New Action delegate is created and assigned.
- Expect.Call(delegate { _dao.Save(t); }).Do(new EventHandler(delegate(Transaction t2) { t2.CheckInInfo.CheckInMessage = "I drink goats blood"; }));
- public delegate void UnitTestingDelegate<T>(T thing);
- Expect.Call(delegate { _dao.Save(t); }).Do((Delegate)delegate { t.Message = "I drink goats blood"; });
Add Comment
Please, Sign In to add comment