Example #1
0
        private void TestAdvancedProxyImplementation()
        {
            try
            {
                Type result = TypeService.BuildProxyImplementation(typeof(IPerformanceMonitorService));

                DummyCommunicationService dummyCommService = new DummyCommunicationService();

                var constructorParams = new object[2];
                constructorParams[0] = dummyCommService;

                IPerformanceMonitorService instance = (IPerformanceMonitorService)Activator.CreateInstance(result, constructorParams);

                TimeSpan      timeSpan = new TimeSpan(23532534);
                List <string> testColl = new List <string>();
                testColl.Add("item 1");
                string testOutput;
                instance.SubscribeCpuUsageNotification(timeSpan, out testOutput, testColl);
            }
            catch (Exception ex)
            {
                // because of buggy unit test environment
                throw;
            }
        }
Example #2
0
        public void TestMethodSpecialInterfaceClassMapping()
        {
            var t = typeof(IOCTalk.Test.Common.Service.MyTestService);

            DummyCommunicationService dummyComm = new DummyCommunicationService();

            TalkCompositionHost hostContainer = new TalkCompositionHost();

            hostContainer.RegisterLocalSessionService <IMyTestService>();
            hostContainer.RegisterRemoteService <IMyRemoteTestService>();
            hostContainer.RegisterExposedSubInterfaceForType <IMapTestMainInterface, MapTestMain>();
            hostContainer.RegisterExposedSubInterfaceForType <IMapTestDerivedInterface, MapTestDerived>();
            hostContainer.AddReferencedAssemblies();

            hostContainer.InitGenericCommunication(dummyComm);

            Common.Session.Session session = new Common.Session.Session(dummyComm, 123, "Unit Test Dummy Session");

            var result = hostContainer.CreateSessionContractInstance(session);

            Type resultTypeMain = hostContainer.GetInterfaceImplementationType(typeof(IMapTestMainInterface).FullName);

            Assert.Equal(typeof(MapTestMain), resultTypeMain);

            Type resultTypeDerived = hostContainer.GetInterfaceImplementationType(typeof(IMapTestDerivedInterface).FullName);

            Assert.Equal(typeof(MapTestDerived), resultTypeDerived);
        }
Example #3
0
        public void TestMethodSubscribeSessionStateChange()
        {
            AdvancedImportService.CreatedCount = 0;

            DummyCommunicationService dummyComm = new DummyCommunicationService();

            TalkCompositionHost hostContainer = new TalkCompositionHost();

            //hostContainer.RegisterLocalSessionService<IAdvancedSessionStateChangeService>();
            hostContainer.RegisterLocalSharedService <IAdvancedSessionStateChangeService>();
            hostContainer.RegisterRemoteService <IMyTestService>();
            hostContainer.AddReferencedAssemblies();

            hostContainer.InitGenericCommunication(dummyComm);

            Common.Session.Session session = new Common.Session.Session(dummyComm, 123, "Unit Test Dummy Session");

            var contract = hostContainer.CreateSessionContractInstance(session);

            dummyComm.RaiseSessionCreated(session, contract);

            Assert.Equal(1, AdvancedImportService.CreatedCount);

            dummyComm.RaiseSessionTerminated(session, contract);

            Assert.Equal(0, AdvancedImportService.CreatedCount);
        }
Example #4
0
        public void CircularDependencyRegognitionTest()
        {
            DummyCommunicationService dummyComm = new DummyCommunicationService();

            TalkCompositionHost hostContainer = new TalkCompositionHost();

            hostContainer.RegisterLocalSharedService <ICircularDependencyTest1>();
            hostContainer.RegisterLocalSharedServices <ICircularDependencyTest2>();
            hostContainer.AddReferencedAssemblies();

            Assert.Throws <CircularServiceReferenceException>(() => hostContainer.InitGenericCommunication(dummyComm));
        }
Example #5
0
        public void TestMethodImplementationMapping2()
        {
            DummyCommunicationService dummyComm = new DummyCommunicationService();

            LocalShareContext localShareContext = new LocalShareContext();

            localShareContext.RegisterLocalSharedService <IMyLocalService, MyLocalService>();

            localShareContext.Init();

            var myService = localShareContext.GetExport <IMyLocalService>();

            Assert.Equal(typeof(MyLocalService), myService.GetType());
        }
Example #6
0
        public void TestMethodMultipleLocalImports()
        {
            MyLocalService.InstanceCount    = 0;
            OtherLocalService.InstanceCount = 0;

            DummyCommunicationService dummyComm = new DummyCommunicationService();

            TalkCompositionHost hostContainer = new TalkCompositionHost();

            hostContainer.RegisterLocalSharedService <IMultipleLocalImportsService>();
            hostContainer.RegisterLocalSharedServices <IMultipleImplementation>();
            hostContainer.AddReferencedAssemblies();

            hostContainer.InitGenericCommunication(dummyComm);

            var multiImportsService = hostContainer.GetExport <IMultipleLocalImportsService>();

            Assert.Equal(2, multiImportsService.LocalImplementations.Length);
        }
Example #7
0
        public void TestMethodBuildDataTransferInterfaceImplementation()
        {
            var t = typeof(IOCTalk.Test.Common.Service.MyTestService);

            DummyCommunicationService dummyComm = new DummyCommunicationService();

            TalkCompositionHost hostContainer = new TalkCompositionHost();

            hostContainer.RegisterLocalSessionService <IMyTestService>();
            hostContainer.RegisterRemoteService <IMyRemoteTestService>();
            hostContainer.AddReferencedAssemblies();

            hostContainer.InitGenericCommunication(dummyComm);

            Common.Session.Session session = new Common.Session.Session(dummyComm, 123, "Unit Test Dummy Session");

            var result = hostContainer.CreateSessionContractInstance(session);

            Type resultType = hostContainer.GetInterfaceImplementationType(typeof(IDataTransferTest).FullName);
        }
Example #8
0
        public void TestMethodMutualLocalImports()
        {
            MyLocalService.InstanceCount    = 0;
            OtherLocalService.InstanceCount = 0;

            DummyCommunicationService dummyComm = new DummyCommunicationService();

            TalkCompositionHost hostContainer = new TalkCompositionHost();

            hostContainer.RegisterLocalSessionService <IMyLocalService>();
            hostContainer.RegisterLocalSessionService <IOtherLocalService>();
            hostContainer.AddReferencedAssemblies();

            hostContainer.InitGenericCommunication(dummyComm);

            Common.Session.Session session = new Common.Session.Session(dummyComm, 123, "Unit Test Dummy Session");

            var result = hostContainer.CreateSessionContractInstance(session);

            Assert.Equal(1, MyLocalService.InstanceCount);
            Assert.Equal(1, OtherLocalService.InstanceCount);
        }
Example #9
0
        private void TestAdvancedProxyImplementationOutParams()
        {
            Type result = TypeService.BuildProxyImplementation(typeof(ITestServiceSpecialOutPrams));

            DummyCommunicationService dummyCommService = new DummyCommunicationService();

            var constructorParams = new object[2];

            constructorParams[0] = dummyCommService;

            ITestServiceSpecialOutPrams instance = (ITestServiceSpecialOutPrams)Activator.CreateInstance(result, constructorParams);

            //int? nullableInt;
            //instance.GetData(out nullableInt);


            var invokeMethod = new InvokeMethodInfo(typeof(ITestServiceSpecialOutPrams), nameof(ITestServiceSpecialOutPrams.GetData));

            var invokeMethodDeserialize = new InvokeMethodInfo(invokeMethod.InterfaceMethod.DeclaringType, invokeMethod.QualifiedMethodName);


            Assert.NotNull(invokeMethodDeserialize);
        }
Example #10
0
        public void TestMethodInitCompositionContainer()
        {
            var t = typeof(IOCTalk.Test.Common.Service.MyTestService);

            DummyCommunicationService dummyComm = new DummyCommunicationService();

            TalkCompositionHost hostContainer = new TalkCompositionHost();

            hostContainer.RegisterLocalSessionService <IMyTestService>();
            hostContainer.RegisterRemoteService <IMyRemoteTestService>();
            hostContainer.AddReferencedAssemblies();

            hostContainer.InitGenericCommunication(dummyComm);

            Common.Session.Session session = new Common.Session.Session(dummyComm, 123, "Unit Test Dummy Session");

            SessionContract contract = (SessionContract)hostContainer.CreateSessionContractInstance(session);

            Assert.Equal(contract.Session, session);

            object proxyTypeObj = hostContainer.GetInterfaceImplementationInstance(session, typeof(IMyRemoteTestService).FullName);

            Assert.IsAssignableFrom <IMyRemoteTestService>(proxyTypeObj);
        }