public void When_raising_event_on_inner_mock_args_arrive_in_handler() { object received = null; var parentMock = new Mock <IParent> { DefaultValue = DefaultValue.Mock }; parentMock.Object.Adder.Done += (_, actual) => received = actual; var sent = new DoneArgs(); parentMock.Raise(m => m.Adder.Done += null, sent); Assert.Same(sent, received); }
public void RaisesEventWithActionLambdaOneArg() { var mock = new Mock <IAdder <int> >(); mock.Setup(m => m.Do("foo")).Raises <string>(m => m.Done += null, s => new DoneArgs { Value = s }); DoneArgs args = null; mock.Object.Done += (sender, e) => args = e; mock.Object.Do("foo"); Assert.IsNotNull(args); Assert.AreEqual("foo", args.Value); }
public void RaisesEventWithActionLambdaEightArgs() { var mock = new Mock <IAdder <int> >(); mock.Setup(m => m.Do("foo", 5, true, "bar", 5, 6, 7, 8)) .Raises(m => m.Done += null, (string s, int i, bool b, string s1, int arg5, int arg6, int arg7, int arg8) => new DoneArgs { Value = s + i + b + s1 + arg5 + arg6 + arg7 + arg8 }); DoneArgs args = null; mock.Object.Done += (sender, e) => args = e; mock.Object.Do("foo", 5, true, "bar", 5, 6, 7, 8); Assert.IsNotNull(args); Assert.AreEqual("foo5Truebar5678", args.Value); }
public void RaisesEventWithActionLambdaFourArgs() { var mock = new Mock <IAdder <int> >(); mock.Setup(m => m.Do("foo", 5, true, "bar")) .Raises(m => m.Done += null, (string s, int i, bool b, string s1) => new DoneArgs { Value = s + i + b + s1 }); DoneArgs args = null; mock.Object.Done += (sender, e) => args = e; mock.Object.Do("foo", 5, true, "bar"); Assert.IsNotNull(args); Assert.AreEqual("foo5Truebar", args.Value); }
public void RaisesEventWithActionLambdaTwoArgs() { var mock = new Mock <IAdder <int> >(); mock.Setup(m => m.Do("foo", 5)) .Raises(m => m.Done += null, (string s, int i) => new DoneArgs { Value = s + i }); DoneArgs args = null; mock.Object.Done += (sender, e) => args = e; mock.Object.Do("foo", 5); Assert.IsNotNull(args); Assert.AreEqual("foo5", args.Value); }
public void RaisesEventWithActionLambdaThreeArgs() { var mock = new Mock <IAdder <int> >(); mock.Setup(m => m.Do("foo", 5, true)) .Raises(m => m.Done += null, (string s, int i, bool b) => new DoneArgs { Value = s + i + b }); DoneArgs args = null; mock.Object.Done += (sender, e) => args = e; mock.Object.Do("foo", 5, true); Assert.NotNull(args); Assert.Equal("foo5True", args.Value); }