示例#1
0
        public void EventObservableFactoryTest_SingleEvent()
        {
            String eventMessage     = "Hey, do something";
            String retrievedMessage = "";

            EventMock eventMock = new EventMock();
            // TestA is the event name we mocked out in EventMock
            IObservable <EventPattern <EventArgs> > evtSource =
                EventHandlerFactory.GetEventObservable <EventMock>(eventMock, "TestA");

            // Select the Message passed to the event from the event source observable
            IObservable <String> source = evtSource.Select(x => ((TestAEventArgs)x.EventArgs).Message);

            // Observer to subscribe to the event observable
            // and retrieve  message
            IObserver <String> observer = Observer.Create <String>(x => retrievedMessage = x);

            // Wire up the source Event to the observer
            source.Subscribe(observer);

            // Trigger Event
            eventMock.OnTestA(new TestAEventArgs(eventMessage));

            Assert.That(eventMessage, Is.EqualTo(retrievedMessage));
        }
示例#2
0
        public void TestNoSubscription()
        {
            var hub  = this.GetEventHub();
            var args = new EventMock(10);

            hub.Raise(args);
        }
示例#3
0
        // The contents of this class were created by the Mocklis code-generator.
        // Any changes you make will be overwritten if the contents are re-generated.

        public TestClass()
        {
            Property = new PropertyMock <int>(this, "TestClass", "ITestClass", "Property", "Property", Strictness.VeryStrict);
            Item     = new IndexerMock <int, string>(this, "TestClass", "ITestClass", "this[]", "Item", Strictness.VeryStrict);
            MyMethod = new FuncMethodMock <string, string>(this, "TestClass", "ITestClass", "MyMethod", "MyMethod", Strictness.VeryStrict);
            MyEvent  = new EventMock <EventHandler>(this, "TestClass", "ITestClass", "MyEvent", "MyEvent", Strictness.VeryStrict);
        }
示例#4
0
        public void EventObservableFactoryTest_NonExistingEvent()
        {
            String retrievedMessage = "";
            String noEvent          = "No Event, So no message";

            EventMock eventMock = new EventMock();
            // TestNullEvent does not exist
            IObservable <EventPattern <EventArgs> > evtSource =
                EventHandlerFactory.GetEventObservable <EventMock>(eventMock, "TestNullEvent");

            // Select the Message passed to the event from the event source observable
            IObservable <String> source = evtSource.Select(x => ((TestAEventArgs)x.EventArgs).Message);

            // Wire up the source Event to the observer
            source.Subscribe(
                x => Assert.Fail("Unexpected subscription event"),
                ex => Assert.Fail("Error subscribing to source"),
                () => retrievedMessage = noEvent
                );

            // Trigger Event
            eventMock.OnTestA(new TestAEventArgs("We are not listening to this event"));

            Assert.That(noEvent, Is.EqualTo(retrievedMessage));
        }
        public void TestHandlerUnsubscribingItself()
        {
            var hub  = this.GetAsyncEventHub();
            var args = new EventMock(10);

            int             beforeHandlerCalled = 0;
            Action <IEvent> beforeHandler       = (e => beforeHandlerCalled++);

            hub.Subscribe(beforeHandler);

            int             unsubscribingHandlerCalled = 0;
            Action <IEvent> unsubscribingHandler       = null;

            unsubscribingHandler = (e => { unsubscribingHandlerCalled++; hub.Unsubscribe(unsubscribingHandler); });
            hub.Subscribe(unsubscribingHandler);

            int             afterHandlerCalled = 0;
            Action <IEvent> afterHandler       = (e => afterHandlerCalled++);

            hub.Subscribe(afterHandler);

            hub.Raise(args);
            hub.Raise(args);
            this.app.Stop();
            beforeHandlerCalled.Should().Be(2, "before event handler should be called exactly twice");
            unsubscribingHandlerCalled.Should().Be(1, "unsubscribing event handler should not be called after the second raise since it has unsubscribed itself during the first");
            afterHandlerCalled.Should().Be(2, "after event handler should be called exactly twice");
        }
示例#6
0
        // The contents of this class were created by the Mocklis code-generator.
        // Any changes you make will be overwritten if the contents are re-generated.

        public MockMembers()
        {
            MyEvent        = new EventMock <EventHandler>(this, "MockMembers", "IMembers", "MyEvent", "MyEvent", Strictness.Lenient);
            Item           = new IndexerMock <int, string>(this, "MockMembers", "IMembers", "this[]", "Item", Strictness.Lenient);
            DoStuff        = new ActionMethodMock(this, "MockMembers", "IMembers", "DoStuff", "DoStuff", Strictness.Lenient);
            Calculate      = new FuncMethodMock <(int value1, int value2), int>(this, "MockMembers", "IMembers", "Calculate", "Calculate", Strictness.Lenient);
            StringProperty = new PropertyMock <string>(this, "MockMembers", "IMembers", "StringProperty", "StringProperty", Strictness.Lenient);
        }
        // The contents of this class were created by the Mocklis code-generator.
        // Any changes you make will be overwritten if the contents are re-generated.

        public MockPropertiesWithChangeNotification()
        {
            StringProperty   = new PropertyMock <string>(this, "MockPropertiesWithChangeNotification", "IProperties", "StringProperty", "StringProperty", Strictness.Lenient);
            IntProperty      = new PropertyMock <int>(this, "MockPropertiesWithChangeNotification", "IProperties", "IntProperty", "IntProperty", Strictness.Lenient);
            BoolProperty     = new PropertyMock <bool>(this, "MockPropertiesWithChangeNotification", "IProperties", "BoolProperty", "BoolProperty", Strictness.Lenient);
            DateTimeProperty = new PropertyMock <System.DateTime>(this, "MockPropertiesWithChangeNotification", "IProperties", "DateTimeProperty", "DateTimeProperty", Strictness.Lenient);
            PropertyChanged  = new EventMock <PropertyChangedEventHandler>(this, "MockPropertiesWithChangeNotification", "INotifyPropertyChanged", "PropertyChanged", "PropertyChanged", Strictness.Lenient);
        }
示例#8
0
 protected TestClass()
 {
     NormalProperty            = new PropertyMock <string?>(this, "TestClass", "ITestClass", "NormalProperty", "NormalProperty", Strictness.Lenient);
     Item                      = new IndexerMock <string?, string?>(this, "TestClass", "ITestClass", "this[]", "Item", Strictness.Lenient);
     NonNullableEvent          = new EventMock <EventHandler>(this, "TestClass", "ITestClass", "NonNullableEvent", "NonNullableEvent", Strictness.Lenient);
     Method3                   = new FuncMethodMock <(string?p1, string?p2), string?>(this, "TestClass", "ITestClass", "Method3", "Method3", Strictness.Lenient);
     ValueTypeProperty         = new PropertyMock <int>(this, "TestClass", "ITestClass", "ValueTypeProperty", "ValueTypeProperty", Strictness.Lenient);
     NullableValueTypeProperty = new PropertyMock <int?>(this, "TestClass", "ITestClass", "NullableValueTypeProperty", "NullableValueTypeProperty", Strictness.Lenient);
 }
        // The contents of this class were created by the Mocklis code-generator.
        // Any changes you make will be overwritten if the contents are re-generated.

        public TestClass()
        {
            DataReceived = new EventMock <EventHandler <DuplexConnectionDataEventArgs> >(this, "TestClass", "IDuplexConnection", "DataReceived", "DataReceived", Strictness.Lenient);
            TextReceived = new EventMock <EventHandler <DuplexConnectionTextEventArgs> >(this, "TestClass", "IDuplexConnection", "TextReceived", "TextReceived", Strictness.Lenient);
            SendData     = new ActionMethodMock <byte[]>(this, "TestClass", "IDuplexConnection", "SendData", "SendData", Strictness.Lenient);
            SendText     = new ActionMethodMock <string>(this, "TestClass", "IDuplexConnection", "SendText", "SendText", Strictness.Lenient);
            Close        = new FuncMethodMock <string, Task <string> >(this, "TestClass", "IDuplexConnection", "Close", "Close", Strictness.Lenient);
            Run          = new FuncMethodMock <Task>(this, "TestClass", "IDuplexConnection", "Run", "Run", Strictness.Lenient);
            SubProtocol  = new PropertyMock <string>(this, "TestClass", "IDuplexConnection", "SubProtocol", "SubProtocol", Strictness.Lenient);
        }
示例#10
0
        public void TestUninitialize()
        {
            var hub    = this.GetEventHub();
            var args   = new EventMock(10);
            int called = 0;
            Action <EventMock> handler = (e => called++);

            hub.Subscribe(handler);
            hub.Raise(args);
            called.Should().Be(1, "event handler should be called exactly once after the first raise");
        }
示例#11
0
		public void ExecuteNotGenericWithNotNull()
		{
			bool executed = false;

			var eventMock = new EventMock();
			eventMock.TestEvent += (s, e) => { executed = true; };

			eventMock.InvokeEvent();

			Assert.IsTrue(executed);
		}
示例#12
0
		public void ExecuteGenericWithNotNull()
		{
			bool executed = false;

			var eventMock = new EventMock<EventArgsMock>();
			eventMock.TestEvent += (s, e) => { executed = e.Message == "Test"; };

			eventMock.InvokeEvent(new EventArgsMock("Test"));

			Assert.IsTrue(executed);
		}
示例#13
0
        public void ExecuteGenericWithNotNull()
        {
            bool executed = false;

            var eventMock = new EventMock <EventArgsMock>();

            eventMock.TestEvent += (s, e) => { executed = e.Message == "Test"; };

            eventMock.InvokeEvent(new EventArgsMock("Test"));

            Assert.IsTrue(executed);
        }
示例#14
0
        public void ExecuteNotGenericWithNotNull()
        {
            bool executed = false;

            var eventMock = new EventMock();

            eventMock.TestEvent += (s, e) => { executed = true; };

            eventMock.InvokeEvent();

            Assert.IsTrue(executed);
        }
示例#15
0
        public void TestParentAndChildSubscription()
        {
            var hub    = this.GetEventHub();
            var args   = new EventMock(10);
            int called = 0;
            Action <EventMock> handler = (e => called++);

            hub.Subscribe(handler);
            hub.Subscribe <EventMockChild>(handler);
            hub.Raise(args);
            called.Should().Be(1, "event handler should be called exactly once");
        }
示例#16
0
        public void TestDoubleSubscription()
        {
            var             hub     = this.GetEventHub();
            var             args    = new EventMock(10);
            int             called  = 0;
            Action <IEvent> handler = (e => called++);

            hub.Subscribe(handler);
            hub.Subscribe(handler);
            hub.Raise(args);
            called.Should().Be(2, "event handler should be called exactly twice");
        }
示例#17
0
        public void TestUnsubscribe()
        {
            var hub    = this.GetAsyncEventHub();
            var args   = new EventMock(10);
            int called = 0;
            Action <EventMock> handler = (e => called++);

            hub.Subscribe(handler);
            hub.Unsubscribe(handler);
            hub.Raise(args);
            this.app.Stop();
            called.Should().Be(0, "event handler should not be called after the unsubscription");
        }
示例#18
0
        public void TestDoubleRaise()
        {
            var             hub     = this.GetAsyncEventHub();
            var             args    = new EventMock(10);
            int             called  = 0;
            Action <IEvent> handler = (e => called++);

            hub.Subscribe(handler);
            hub.Raise(args);
            hub.Raise(args);
            this.app.Stop();
            called.Should().Be(2, "event handler should be called exactly twice after the second raise");
        }
示例#19
0
        public void TestEventInterface()
        {
            var hub    = this.GetEventHub();
            var args   = new EventMock(10);
            int called = 0;

            hub.Subscribe <IEvent>(e =>
            {
                e.Should().BeSameAs(args, "the passed arguments should be the same as provided");
                called++;
            });
            hub.Raise(args);
            called.Should().Be(1, "event handler should be called exactly once");
        }
 protected TestClass()
 {
     NullableProperty = new PropertyMock <string?>(this, "TestClass", "ITestClass", "NullableProperty", "NullableProperty", Strictness.Lenient);
     NormalProperty   = new PropertyMock <string>(this, "TestClass", "ITestClass", "NormalProperty", "NormalProperty", Strictness.Lenient);
     Item             = new IndexerMock <int, string?>(this, "TestClass", "ITestClass", "this[]", "Item", Strictness.Lenient);
     Item0            = new IndexerMock <bool, string>(this, "TestClass", "ITestClass", "this[]", "Item0", Strictness.Lenient);
     Item1            = new IndexerMock <string?, string?>(this, "TestClass", "ITestClass", "this[]", "Item1", Strictness.Lenient);
     Item2            = new IndexerMock <(int i, string?s), string>(this, "TestClass", "ITestClass", "this[]", "Item2", Strictness.Lenient);
     NonNullableEvent = new EventMock <EventHandler>(this, "TestClass", "ITestClass", "NonNullableEvent", "NonNullableEvent", Strictness.Lenient);
     NullableEvent    = new EventMock <EventHandler>(this, "TestClass", "ITestClass", "NullableEvent", "NullableEvent", Strictness.Lenient);
     Method1          = new FuncMethodMock <string?, string>(this, "TestClass", "ITestClass", "Method1", "Method1", Strictness.Lenient);
     Method2          = new FuncMethodMock <string, string?>(this, "TestClass", "ITestClass", "Method2", "Method2", Strictness.Lenient);
     Method3          = new FuncMethodMock <(string p1, string?p2), string>(this, "TestClass", "ITestClass", "Method3", "Method3", Strictness.Lenient);
 }
示例#21
0
        // The contents of this class were created by the Mocklis code-generator.
        // Any changes you make will be overwritten if the contents are re-generated.

        public MockMembers()
        {
            MyEvent             = new EventMock <EventHandler>(this, "MockMembers", "IEvents", "MyEvent", "MyEvent", Strictness.Lenient);
            SpecialEvent        = new EventMock <EventHandler <SpecialEventArgs> >(this, "MockMembers", "IEvents", "SpecialEvent", "SpecialEvent", Strictness.Lenient);
            SimpleAction        = new ActionMethodMock(this, "MockMembers", "IMethods", "SimpleAction", "SimpleAction", Strictness.Lenient);
            ActionWithParameter = new ActionMethodMock <int>(this, "MockMembers", "IMethods", "ActionWithParameter", "ActionWithParameter", Strictness.Lenient);
            SimpleFunc          = new FuncMethodMock <int>(this, "MockMembers", "IMethods", "SimpleFunc", "SimpleFunc", Strictness.Lenient);
            FuncWithParameter   = new FuncMethodMock <int, int>(this, "MockMembers", "IMethods", "FuncWithParameter", "FuncWithParameter", Strictness.Lenient);
            StringProperty      = new PropertyMock <string>(this, "MockMembers", "IProperties", "StringProperty", "StringProperty", Strictness.Lenient);
            IntProperty         = new PropertyMock <int>(this, "MockMembers", "IProperties", "IntProperty", "IntProperty", Strictness.Lenient);
            BoolProperty        = new PropertyMock <bool>(this, "MockMembers", "IProperties", "BoolProperty", "BoolProperty", Strictness.Lenient);
            DateTimeProperty    = new PropertyMock <DateTime>(this, "MockMembers", "IProperties", "DateTimeProperty", "DateTimeProperty", Strictness.Lenient);
            Item  = new IndexerMock <int, string>(this, "MockMembers", "IIndexers", "this[]", "Item", Strictness.Lenient);
            Item0 = new IndexerMock <bool, DateTime>(this, "MockMembers", "IIndexers", "this[]", "Item0", Strictness.Lenient);
        }
示例#22
0
        public void TestEventImmediate()
        {
            this.app.GetConfig <DelayedEventsConfig>().DefaultBehavior = EventBehavior.Delayed;
            var hub    = this.app.GetDelayedEventHub();
            var args   = new EventMock(10);
            int called = 0;

            hub.Subscribe <EventMock>(e =>
            {
                e.Should().BeSameAs(args, "the passed arguments should be the same as provided");
                called++;
            });
            hub.RaiseImmediate(args);
            called.Should().Be(1, "event handler should be called exactly once");
        }
        public void RunShouldStartCreatedWatching()
        {
            var requestEvent = new EventMock();
            var requestFile  = $"{_watchpath}1/MovementRequest_V.XML";

            DeleteMovementDirectory($"{_watchpath}1");
            var eventAggregator = new Mock <IEventAggregator>();

            eventAggregator.Setup(e => e.GetEvent <PubSubEvent <StorageSimulator.Core.Events.MovementRequestEvent> >()).Returns(requestEvent);
            var config = new Mock <IStorageSimulatorConfig>();

            config.Setup(c => c.CommunicationPath).Returns($"{_watchpath}1");
            var service = new WatchRequestService(eventAggregator.Object, config.Object);

            service.Run();
            CreateMovementRequest(requestFile);

            Task.Delay(45).Wait();
            eventAggregator.Verify(e => e.GetEvent <PubSubEvent <StorageSimulator.Core.Events.MovementRequestEvent> >());
            requestEvent.PublishCalled.Should().BeTrue();
        }
示例#24
0
        public void EventObservableFactoryTest_EventList()
        {
            List <String> eventNames = new List <String>()
            {
                "TestA", "TestB"
            };
            List <String> eventMessages = new List <String>()
            {
                "Hey, do something", "Now do something else"
            };
            List <String> retrievedMessages = new List <String>();

            EventMock eventMock = new EventMock();
            // TestA is the event name we mocked out in EventMock
            List <IObservable <EventPattern <EventArgs> > > evtSources =
                EventHandlerFactory.GetEventObservable <EventMock>(eventMock, eventNames);

            // Select the Message passed to the event from the event source observable
            IObservable <String> sourceA = evtSources[0].Select(x => ((TestAEventArgs)x.EventArgs).Message);
            IObservable <String> sourceB = evtSources[1].Select(x => ((TestBEventArgs)x.EventArgs).Message);


            // Observer to subscribe to the event observable
            // and retrieve  message
            // Note that the order of events determines the order of retrieved messages
            IObserver <String> observer = Observer.Create <String>(x => retrievedMessages.Add(x));

            // Wire up the source Event to the observer
            sourceA.Subscribe(observer);
            sourceB.Subscribe(observer);

            // Trigger EventA then Event B
            eventMock.OnTestA(new TestAEventArgs(eventMessages[0]));
            eventMock.OnTestB(new TestBEventArgs(eventMessages[1]));

            Assert.That(eventMessages[0], Is.EqualTo(retrievedMessages[0]));
            Assert.That(eventMessages[1], Is.EqualTo(retrievedMessages[1]));
        }
 public MissingEventStepRemoveTests()
 {
     _eventMock        = new EventMock <EventHandler>(new object(), "TestClass", "ITest", "Event", "Event1", Strictness.Lenient);
     _missingEventStep = MissingEventStep <EventHandler> .Instance;
 }
示例#26
0
        // The contents of this class were created by the Mocklis code-generator.
        // Any changes you make will be overwritten if the contents are re-generated.

        public MockEvents()
        {
            MyEvent         = new EventMock <EventHandler>(this, "MockEvents", "IEvents", "MyEvent", "MyEvent", Strictness.Lenient);
            SpecialEvent    = new EventMock <EventHandler <Helpers.SpecialEventArgs> >(this, "MockEvents", "IEvents", "SpecialEvent", "SpecialEvent", Strictness.Lenient);
            PropertyChanged = new EventMock <PropertyChangedEventHandler>(this, "MockEvents", "INotifyPropertyChanged", "PropertyChanged", "PropertyChanged", Strictness.Lenient);
        }
示例#27
0
        // The contents of this class were created by the Mocklis code-generator.
        // Any changes you make will be overwritten if the contents are re-generated.

        public TestClass()
        {
            MyEvent = new EventMock <EventHandler <T> >(this, "TestClass", "ITestClass", "MyEvent", "MyEvent", Strictness.Lenient);
        }
示例#28
0
		public void ExecuteGenericWithNull()
		{
			var eventMock = new EventMock<EventArgsMock>();
			eventMock.InvokeEvent(new EventArgsMock("Test"));
		}
示例#29
0
		public void ExecuteNotGenericWithNull()
		{
			var eventMock = new EventMock();
			eventMock.InvokeEvent();
		}
示例#30
0
        public void ExecuteGenericWithNull()
        {
            var eventMock = new EventMock <EventArgsMock>();

            eventMock.InvokeEvent(new EventArgsMock("Test"));
        }
示例#31
0
 protected TestClass()
 {
     NonNullableEvent = new EventMock <EventHandler>(this, "TestClass", "ITestClass", "NonNullableEvent", "NonNullableEvent", Strictness.Lenient);
     NullableEvent    = new EventMock <EventHandler>(this, "TestClass", "ITestClass", "NullableEvent", "NullableEvent", Strictness.Lenient);
 }
        // The contents of this class were created by the Mocklis code-generator.
        // Any changes you make will be overwritten if the contents are re-generated.

        public TestClass()
        {
            Normal = new EventMock <EventHandler>(this, "TestClass", "ITestClass", "Normal", "Normal", Strictness.Lenient);
        }
示例#33
0
        public void ExecuteNotGenericWithNull()
        {
            var eventMock = new EventMock();

            eventMock.InvokeEvent();
        }