コード例 #1
0
        private void MultipleBindingTest(Mock <IParentInterface> mock)
        {
            _counter1 = 0;
            _counter2 = 0;
            _message  = null;

            EventInvoker <ValueEventArgs> invoker = mock.Expects.Exactly(2).EventBinding <ValueEventArgs>(_ => _.CustomEvent += null);

            Assert.AreEqual(null, _message);
            mock.MockObject.CustomEvent += ListenerCounter1;

            invoker.Invoke(new ValueEventArgs {
                Value = "first"
            });
            Assert.AreEqual("first", _message);

            mock.MockObject.CustomEvent += ListenerCounter2;

            invoker.Invoke(new ValueEventArgs {
                Value = "second"
            });
            Assert.AreEqual("second", _message);

            mock.Expects.One.EventBinding(_ => _.CustomEvent -= null);

            mock.MockObject.CustomEvent -= ListenerCounter1;

            invoker.Invoke(new ValueEventArgs {
                Value = "third"
            });
            Assert.AreEqual("third", _message);

            Assert.AreEqual(2, _counter1);
            Assert.AreEqual(2, _counter2);
        }
コード例 #2
0
        private void MultipleBindingTest(Mock <IParentInterface> mock)
        {
            _counter1 = 0;
            _counter2 = 0;
            _message  = null;

            EventInvoker invoker = mock.Expects.Exactly(2).EventBinding(_ => _.StandardEvent1 += null);

            Assert.AreEqual(null, _message);
            mock.MockObject.StandardEvent1 += ListenerCounter1;

            invoker.Invoke();
            Assert.AreEqual("first", _message);

            mock.MockObject.StandardEvent1 += ListenerCounter2;

            invoker.Invoke();
            Assert.AreEqual("second", _message);

            mock.Expects.One.EventBinding(_ => _.StandardEvent1 -= null);

            mock.MockObject.StandardEvent1 -= ListenerCounter1;

            invoker.Invoke();
            Assert.AreEqual("second", _message);

            Assert.AreEqual(2, _counter1);
            Assert.AreEqual(2, _counter2);
        }
コード例 #3
0
        /// <inheritdoc/>
        public IQuik Create(QuikClientOptions options)
        {
            var pendingResultContainer = new PendingResultContainer();
            var eventTypeProvider      = new EventTypeProvider();
            var serializer             = new QuikJsonSerializer(pendingResultContainer, eventTypeProvider);
            var typeConverter          = new CachingQuikTypeConverter();
            var idProvider             = new UniqueIdProvider();
            var dateTimeProvider       = new CurrentDateTimeProvider();
            var messageFactory         = new MessageFactory(idProvider, dateTimeProvider);

            var quikEvents   = new QuikEvents();
            var eventHandler = new EventInvoker(quikEvents);
            var quikClient   = new QuikClient(eventHandler, serializer, pendingResultContainer, options,
                                              _loggerFactory.CreateLogger <QuikClient>());

            var quik = new Quik(
                quikClient,
                new Functions.QuikFunctions(
                    new ServiceFunctions(messageFactory, quikClient, typeConverter),
                    new TableRowFunctions(messageFactory, quikClient, typeConverter),
                    new ClassFunctions(messageFactory, quikClient, typeConverter),
                    new WorkstationFunctions(messageFactory, quikClient, typeConverter),
                    new CandleFunctions(messageFactory, quikClient, typeConverter),
                    new LabelFunctions(messageFactory, quikClient, typeConverter),
                    new OrderBookFunctions(messageFactory, quikClient, typeConverter),
                    new QuotesTableParametersFunctions(messageFactory, quikClient, typeConverter),
                    new DebugFunctions(messageFactory, quikClient, typeConverter),
                    new CustomFunctions(messageFactory, quikClient, typeConverter)),
                quikEvents);

            quikClient.SetEventSender(quik);
            quikEvents.SetEventSender(quik);

            return(quik);
        }
コード例 #4
0
        private void ThrowErrorOnInvokeTest(Mock <IParentInterface> mock)
        {
            //Factory.SuppressUnexpectedAndUnmetExpectations();

            EventInvoker invoker = mock.Expects.One.EventBinding(_ => _.StandardEvent1 += ThrowListener);

            mock.MockObject.StandardEvent1 += ThrowListener;

            try
            {
                invoker.Invoke();

                Assert.Fail("exception should be thrown.");
            }
            catch (Exception err)
            {
#if SILVERLIGHT
                string message = @"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: message 3
   at NMockTests.MockTests.ExpectsTests.IMethodSyntaxTestsSL.EventBindingTests.ThrowListener(Object sender, EventArgs e)";
#else
#if NetFx35
                string message = @"System.InvalidOperationException: message 3
   at NMockTests.MockTests.ExpectsTests.IMethodSyntaxTests35.EventBindingTests.ThrowListener(Object sender, EventArgs e)";
#else
                string message = @"System.InvalidOperationException: message 3
   at NMockTests.MockTests.ExpectsTests.IMethodSyntaxTests.EventBindingTests.ThrowListener(Object sender, EventArgs e)";
#endif
#endif
                if (!err.ToString().StartsWith(message))
                {
                    Assert.Fail("wrong error message. got: " + err);
                }
            }
        }
コード例 #5
0
 public static void AddInvoker(EventName eventName, EventInvoker invoker)
 {
     invokers[eventName].Add(invoker);
     foreach (UnityAction <float> listener in listeners[eventName])
     {
         invoker.AddListener(eventName, listener);
     }
 }
コード例 #6
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        EventInvoker eventInvoker = (EventInvoker)target;

        // ボタン作成
        if (GUILayout.Button("InvokeEvent"))
        {
            eventInvoker.InvokeEvent();
        }
    }
コード例 #7
0
 private void OnEnable()
 {
     self = target as EventInvoker;
     focusedBackgroundStyle = new GUIStyle
     {
         normal = { background = TextureFactory.SolidColor(new Color32(44, 93, 135, 255)) }
     };
     selectedBackgroundStyle = new GUIStyle
     {
         normal = { background = TextureFactory.SolidColor(new Color32(77, 77, 77, 255)) }
     };
 }
コード例 #8
0
        private void RemoveHandlerAndInvokeTest(Mock <IParentInterface> mock)
        {
            _message = null;

            EventInvoker invoker = mock.Expects.One.EventBinding(_ => _.StandardEvent1 -= Listener1);

            mock.MockObject.StandardEvent1 -= Listener1;

            invoker.Invoke();

            Assert.IsNull(_message);
        }
コード例 #9
0
        private void AddHandlerAndInvokeTest(Mock <IParentInterface> mock)
        {
            _message = null;

            EventInvoker invoker = mock.Expects.One.EventBinding(_ => _.StandardEvent1 += Listener1);

            mock.MockObject.StandardEvent1 += Listener1;

            invoker.Invoke();

            Assert.AreEqual("message 1", _message);
        }
コード例 #10
0
        public void ExceptionsInEventHandlersAreNotWrappedInInternalExceptions()
        {
            Mock <IEventProvider>    eventProvider    = Mocks.CreateMock <IEventProvider>();
            Mock <IExceptionThrower> exceptionThrower = Mocks.CreateMock <IExceptionThrower>();

            EventInvoker invoker = eventProvider.Expects.One.EventBinding(e => e.Event += null);

            exceptionThrower.Expects.One.Method(e => e.ThrowException()).Will(Throw.Exception(new ApplicationException("got you!")));

            eventProvider.MockObject.Event += delegate { exceptionThrower.MockObject.ThrowException(); };

            Expect.That(invoker.Invoke).Throws <ApplicationException>();
        }
コード例 #11
0
        private void InvokedHandlerUnbindsTest(Mock <IParentInterface> mock)
        {
            EventInvoker <EventArgs>      invoker1 = mock.Expects.One.EventBinding <EventArgs>(_ => _.StandardEvent2 += null);
            EventInvoker <ValueEventArgs> invoker2 = mock.Expects.One.EventBinding <ValueEventArgs>(_ => _.CustomEvent += null);

            mock.Expects.One.EventBinding(_ => _.StandardEvent2 -= null);
            mock.Expects.One.EventBinding(_ => _.CustomEvent    -= null);

            mock.MockObject.StandardEvent2 += Unbinder1;
            mock.MockObject.CustomEvent    += Unbinder2;

            invoker1.Invoke(mock.MockObject, new EventArgs());
            invoker2.Invoke(mock.MockObject, new ValueEventArgs());
        }
コード例 #12
0
        private void AddHandlerAnonymousBindingTest(Mock <IParentInterface> mock)
        {
            int          i        = 0;
            EventInvoker invoker1 = mock.Expects.One.EventBinding(e => e.StandardEvent1 += (s, args) => { });
            EventInvoker invoker2 = mock.Expects.One.EventBinding(e => e.StandardEvent2 += (s, args) => { });

            mock.MockObject.StandardEvent1 += (s, args) => { i++; };
            mock.MockObject.StandardEvent2 += (s, args) => { i++; };

            invoker1.Invoke();
            invoker2.Invoke();

            Assert.AreEqual(2, i);
        }
コード例 #13
0
        public void ExceptionFromEventIsTheRightType()
        {
            Mock <IEventProvider>    eventProvider    = Mocks.CreateMock <IEventProvider>();
            Mock <IExceptionThrower> exceptionThrower = Mocks.CreateMock <IExceptionThrower>();

            EventInvoker invoker  = eventProvider.Expects.One.EventBinding(e => e.Event += null);
            EventInvoker invoker2 = eventProvider.Expects.One.EventBinding(e => e.Event2 += null);

            exceptionThrower.Expects.One.MethodWith(_ => _.ThrowException()).Will(Throw.Exception(new TimeoutException()));

            Presenter p = new Presenter(eventProvider.MockObject, exceptionThrower.MockObject);

            Expect.That(invoker.Invoke).Throws <TimeoutException>();
        }
コード例 #14
0
        private void RemoveHandlerAndInvokeTest(Mock <IParentInterface> mock)
        {
            _message = null;

            EventInvoker <ValueEventArgs> invoker = mock.Expects.One.EventBinding <ValueEventArgs>(_ => _.CustomEvent -= Listener);

            mock.MockObject.CustomEvent -= Listener;

            invoker.Invoke(new ValueEventArgs {
                Value = "message 2"
            });

            Assert.IsNull(_message);
        }
コード例 #15
0
        private void AddHandlerEmptyDelegateBindingTest(Mock <IParentInterface> mock)
        {
            int          i        = 0;
            EventInvoker invoker1 = mock.Expects.One.EventBinding(e => e.StandardEvent1 += delegate { });
            EventInvoker invoker2 = mock.Expects.One.EventBinding(e => e.StandardEvent2 += delegate { });

            mock.MockObject.StandardEvent1 += delegate { i++; };
            mock.MockObject.StandardEvent2 += delegate { i++; };

            invoker1.Invoke();
            invoker2.Invoke();

            Assert.AreEqual(2, i);
        }
コード例 #16
0
        private void AddHandlerAndInvokeTest(Mock <IParentInterface> mock)
        {
            _message = null;

            EventInvoker <ValueEventArgs> invoker = mock.Expects.One.EventBinding <ValueEventArgs>(_ => _.CustomEvent += Listener);

            mock.MockObject.CustomEvent += Listener;

            invoker.Invoke(new ValueEventArgs {
                Value = "message 1"
            });

            Assert.AreEqual("message 1", _message);
        }
コード例 #17
0
        public void TestInitialize()
        {
            _mockView = _factory.CreateMock <IContactManagementView>();

            //store the result of EventBinding into an "Invoker"
            //this EventBinding is using the default EventArgs
            _initEvent = _mockView.Expects.One.EventBinding(v => v.Init += null);

            //notice how this EventBinding requires a specific type of EventArgs
            _loadEvent = _mockView.Expects.One.EventBinding <ContactEventArgs>(v => v.Load += null);

            _presenter = new ContactManagementPresenter(_mockView.MockObject);

            _presenter.BindEventsInternal();
        }
コード例 #18
0
        private void AddHandlerEmptyDelegateBindingTest(Mock <IParentInterface> mock)
        {
            int i = 0;

            EventInvoker <EventArgs>      invoker1 = mock.Expects.One.EventBinding <EventArgs>(e => e.StandardEvent2 += delegate { });
            EventInvoker <ValueEventArgs> invoker2 = mock.Expects.One.EventBinding <ValueEventArgs>(e => e.CustomEvent += delegate { });

            mock.MockObject.StandardEvent2 += delegate { i++; };
            mock.MockObject.CustomEvent    += delegate { i++; };

            invoker1.Invoke(new EventArgs());
            invoker2.Invoke(new ValueEventArgs());

            Assert.AreEqual(2, i);
        }
コード例 #19
0
        private void AddHandlerNullBindingTest(Mock <IParentInterface> mock)
        {
            _message = null;

            EventInvoker invoker1 = mock.Expects.One.EventBinding(e => e.StandardEvent1 += null);
            EventInvoker invoker2 = mock.Expects.One.EventBinding(e => e.StandardEvent2 += null);

            mock.MockObject.StandardEvent1 += Listener2;
            mock.MockObject.StandardEvent2 += Listener1;

            invoker1.Invoke();
            Assert.AreEqual("message 2", _message);

            invoker2.Invoke();
            Assert.AreEqual("message 1", _message);
        }
コード例 #20
0
        private void AddHandlerNullBindingTest(Mock <IParentInterface> mock)
        {
            _message = null;

            EventInvoker <EventArgs>      invoker1 = mock.Expects.One.EventBinding <EventArgs>(e => e.StandardEvent2 += null);
            EventInvoker <ValueEventArgs> invoker2 = mock.Expects.One.EventBinding <ValueEventArgs>(e => e.CustomEvent += null);

            mock.MockObject.StandardEvent2 += Listener3;
            mock.MockObject.CustomEvent    += Listener;

            invoker1.Invoke(new EventArgs());
            Assert.AreEqual("message 3", _message);

            invoker2.Invoke(new ValueEventArgs {
                Value = "message 1"
            });
            Assert.AreEqual("message 1", _message);
        }
コード例 #21
0
 public static void RemoveInvoker(EventName eventName, EventInvoker invoker)
 {
     invokers[eventName].Remove(invoker);
 }
コード例 #22
0
 public NotifyChanged(string name)
 {
     this.name    = name;
     eventInvoker = new EventInvoker(nameof(INotifyPropertyChanged.PropertyChanged));
 }
コード例 #23
0
 public HasEvent()
 {
     myInvoker = new EventInvoker(this, () => OnEnvent);
 }