Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }