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());
        }
        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());
        }
        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 })));
        }
        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)));
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        public void Services_WithInitialization_ShouldHaveServiceRegistered()
        {
            ServiceDispatcher serviceDispatcher = new ServiceDispatcher(new TestPlatformProvider());

            serviceDispatcher.Initialize();

            Assert.Equal(2, serviceDispatcher.Services.Count);
            Assert.True(serviceDispatcher.Services.ContainsKey("service1"));
            Assert.True(serviceDispatcher.Services.ContainsKey("service2"));
            Assert.Equal(4, serviceDispatcher.Services["service1"].Count());
            Assert.True(serviceDispatcher.Services["service1"].Contains("serviceMethod1"));
            Assert.True(serviceDispatcher.Services["service1"].Contains("serviceMethod2"));
            Assert.True(serviceDispatcher.Services["service1"].Contains("serviceMethod3"));
            Assert.True(serviceDispatcher.Services["service1"].Contains("serviceMethod4"));
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }