예제 #1
0
        public void AddsHandler()
        {
            var mock = new EventfulMock();

            mock.Behaviors.Add(new EventBehavior());
            mock.Behaviors.Add(StuntBehavior.Create((m, n) => m.CreateValueReturn(null)));

            EventHandler handler = (_, __) => { };

            mock.Empty += handler;

            Assert.True(mock.AsMock().State.TryGetValue <Delegate>(nameof(IEventful.Empty), out var e));
            Assert.Contains(handler, e.GetInvocationList());
        }
예제 #2
0
        public void RaisesEventHandlerIfRaiserInContextOnAdd()
        {
            var mock = new EventfulMock();

            mock.Behaviors.Add(new EventBehavior());
            mock.Behaviors.Add(StuntBehavior.Create((m, n) => m.CreateValueReturn(null)));

            var          called  = false;
            EventHandler handler = (_, __) => called = true;

            mock.Empty += handler;

            CallContext <EventRaiser> .SetData(EventRaiser.Empty);

            mock.Empty += null;

            Assert.True(called);
        }
예제 #3
0
        public void RaisesEventArgsIfRaiserInContextOnAdd()
        {
            var mock = new EventfulMock();

            mock.Behaviors.Add(new EventBehavior());
            mock.Behaviors.Add(StuntBehavior.Create((m, n) => m.CreateValueReturn(null)));

            var expected = new Args();
            var actual   = default(Args);
            EventHandler <Args> handler = (sender, args) => actual = args;

            mock.WithArgs += handler;

            CallContext <EventRaiser> .SetData(new EventArgsEventRaiser(expected));

            mock.WithArgs += null;

            Assert.Same(expected, actual);
        }
예제 #4
0
        public void RaisesActionIfRaiserInContextOnAdd()
        {
            var mock = new EventfulMock();

            mock.Behaviors.Add(new EventBehavior());
            mock.Behaviors.Add(StuntBehavior.Create((m, n) => m.CreateValueReturn(null)));

            var          expected = 5;
            var          actual   = 0;
            Action <int> handler  = i => actual = i;

            mock.Action += handler;

            CallContext <EventRaiser> .SetData(new CustomEventRaiser(new object[] { expected }));

            mock.Action += null;

            Assert.Equal(expected, actual);
        }
예제 #5
0
        public void RaisesPropertyChangedIfRaiserInContextOnAdd()
        {
            var mock = new EventfulMock();

            mock.Behaviors.Add(new EventBehavior());
            mock.Behaviors.Add(StuntBehavior.Create((m, n) => m.CreateValueReturn(null)));

            var expected = new PropertyChangedEventArgs("Foo");
            var actual   = default(PropertyChangedEventArgs);
            PropertyChangedEventHandler handler = (sender, args) => actual = args;

            mock.PropertyChanged += handler;

            CallContext <EventRaiser> .SetData(new EventArgsEventRaiser(expected));

            mock.PropertyChanged += null;

            Assert.Same(expected, actual);
        }
예제 #6
0
        public void RaisesCustomDelegateIfRaiserInContextOnAdd()
        {
            var mock = new EventfulMock();

            mock.Behaviors.Add(new EventBehavior());
            mock.Behaviors.Add(StuntBehavior.Create((m, n) => m.CreateValueReturn(null)));

            var(id, name)   = (5, "foo");
            var(id2, name2) = (0, "");

            CustomDelegate handler = (i, n) => { id2 = i; name2 = n; };

            mock.Custom += handler;

            CallContext <EventRaiser> .SetData(new CustomEventRaiser(new object[] { id, name }));

            mock.Custom += null;

            Assert.Equal(id, id2);
            Assert.Equal(name, name2);
        }