예제 #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());
        }
예제 #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());
        }
예제 #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 })));
        }
예제 #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)));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }