Esempio n. 1
0
        public void Dispatch_ServiceShouldReturnValue()
        {
            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();

            serviceDispatcher.Subscribe <IService1>(service1);
            Assert.Equal(3, serviceDispatcher.Dispatch <IService1, int>(s => s.ServiceMethod3(1, 2)).Single());
        }
Esempio n. 2
0
        public void DispatchReflection_ServiceShouldReturnValue()
        {
            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();

            serviceDispatcher.Subscribe <IService1>(service1);
            Assert.Equal(3, serviceDispatcher.Dispatch("service1", "serviceMethod3", new object[] { 1, 2 }).Cast <int>().Single());
        }
Esempio n. 3
0
        public void DispatchReflection_NamedService_ServiceShouldReturnValue()
        {
            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 instance1 = new Service1("Instance1");
            Service1 instance2 = new Service1("Instance2");

            serviceDispatcher.Subscribe <IService1>(instance1);
            serviceDispatcher.Subscribe <IService1>(instance2);
            Assert.Equal(3, Convert.ToInt32(serviceDispatcher.Dispatch("service1", "Instance1", "serviceMethod3", new object[] { 1, 2 })));
        }
Esempio n. 4
0
        public void Dispatch_NamedService_ServiceShouldReturnValue()
        {
            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 instance1 = new Service1("Instance1");
            Service1 instance2 = new Service1("Instance2");

            serviceDispatcher.Subscribe <IService1>(instance1);
            serviceDispatcher.Subscribe <IService1>(instance2);
            Assert.Equal(3, serviceDispatcher.Dispatch <IService1, int>("Instance1", s => s.ServiceMethod3(1, 2)));
        }
Esempio n. 5
0
        public void DispatchReflection_ServiceShouldHaveBeenCalledWithDifferentParameterType()
        {
            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();

            serviceDispatcher.Subscribe <IService1>(service1);
            serviceDispatcher.Dispatch("service1", "serviceMethod2", new object[] { 42L });

            Assert.Equal(42, service1.ServiceMethod2Result);
        }
Esempio n. 6
0
        public void Dispatch_ServiceShouldHaveBeenCalledWithParameter()
        {
            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();

            serviceDispatcher.Subscribe <IService1>(service1);
            serviceDispatcher.Dispatch <IService1>(s => s.ServiceMethod2(42));

            Assert.Equal(42, service1.ServiceMethod2Result);
        }
Esempio n. 7
0
        public void DispatchReflection_ServiceShouldHaveBeenCalled()
        {
            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();

            serviceDispatcher.Subscribe <IService1>(service1);
            serviceDispatcher.Dispatch("service1", "serviceMethod1", null);

            Assert.True(service1.ServiceMethod1Called);
        }
Esempio n. 8
0
        public void Dispatch_NoSubscribedService_ServiceShouldNotHaveBeenCalled()
        {
            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();

            serviceDispatcher.Subscribe <IService1>(service1);
            serviceDispatcher.Unsubscribe <IService1>(service1);
            serviceDispatcher.Dispatch <IService1>(s => s.ServiceMethod1());

            Assert.False(service1.ServiceMethod1Called);
        }
Esempio n. 9
0
        public void ShouldSuccessfullySubscribeWithMultipleSubscribedServices()
        {
            EventHandler event1Handler = (o, e) => { };

            IServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();
            Service2 service2 = new Service2();

            serviceDispatcher.Subscribe <IService1>(service1);
            serviceDispatcher.SubscribeEvent <IService1>(s => s.Event1 += event1Handler, s => s.Event1 -= event1Handler);
            serviceDispatcher.Subscribe <IService2>(service2);
        }
Esempio n. 10
0
        public void DispatchReflection_NamedService_ServiceShouldHaveBeenCalled()
        {
            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 instance1 = new Service1("Instance1");
            Service1 instance2 = new Service1("Instance2");

            serviceDispatcher.Subscribe <IService1>(instance1);
            serviceDispatcher.Subscribe <IService1>(instance2);
            serviceDispatcher.Dispatch("service1", "Instance1", "serviceMethod1", null);

            Assert.True(instance1.ServiceMethod1Called);
            Assert.False(instance2.ServiceMethod1Called);
        }
Esempio n. 11
0
        public void EventShouldBeRaisedWithParameter()
        {
            string event2Raised = string.Empty;
            EventHandler <string> event2Handler = (o, e) => { event2Raised = e; };

            IServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();

            serviceDispatcher.Subscribe <IService1>(service1);
            serviceDispatcher.SubscribeEvent <IService1>(s => s.Event2 += event2Handler, s => s.Event2 -= event2Handler);

            service1.RaiseEvent2("Event2");

            Assert.Equal("Event2", event2Raised);
        }
Esempio n. 12
0
        public void EventShouldBeRaised()
        {
            bool         event1Raised  = false;
            EventHandler event1Handler = (o, e) => { event1Raised = true; };

            IServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();

            serviceDispatcher.Subscribe <IService1>(service1);
            serviceDispatcher.SubscribeEvent <IService1>(s => s.Event1 += event1Handler, s => s.Event1 -= event1Handler);

            service1.RaiseEvent1();

            Assert.True(event1Raised);
        }
Esempio n. 13
0
        public void EventShouldNotBeRaisedAfterEventUnsubscribe()
        {
            bool         event1Raised  = false;
            EventHandler event1Handler = (o, e) => { event1Raised = true; };

            IServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();

            serviceDispatcher.Subscribe <IService1>(service1);
            EventRegistration eventRegistration = serviceDispatcher.SubscribeEvent <IService1>(s => s.Event1 += event1Handler, s => s.Event1 -= event1Handler);

            serviceDispatcher.UnsubscribeEvent <IService1>(eventRegistration);

            service1.RaiseEvent1();

            Assert.False(event1Raised);
        }
Esempio n. 14
0
        public void DispatchReflection_ServiceShouldBeCalledWithVariousDataTypes()
        {
            DataTypeTest dataTypeTest = new DataTypeTest("StringValue", 1L, 2.2f, 3.3d, new string[] { "1", "2", "3" }, new long[] { 1, 2, 3 }, new List <string>()
            {
                "1", "2", "3"
            }, new List <long>()
            {
                1, 2, 3
            }, new Dictionary <string, string>()
            {
                { "Key1", "Value1" }, { "Key2", "Value2" }
            });

            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Service1 service1 = new Service1();

            serviceDispatcher.Subscribe <IService1>(service1);
            serviceDispatcher.Dispatch("service1", "serviceMethod4", new object[] { dataTypeTest.StringValue, dataTypeTest.LongValue, dataTypeTest.FloatValue, dataTypeTest.DoubleValue, dataTypeTest.StringArray, dataTypeTest.LongArray, dataTypeTest.StringEnumerable, dataTypeTest.LongEnumerable, dataTypeTest.StringDictionary });
            Assert.Equal(dataTypeTest, service1.ServiceMethod4Result);
        }