Beispiel #1
0
        public void EventEvaluationTest()
        {
            var mockInvoker = new Mock <IInvoker>();

            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IEventInterface).GetMethod("add_ValueEvent")), It.Is <object[]>(p => p.Length == 1 && p[0] is Func <int, int>)))
            .Verifiable();
            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IEventInterface).GetMethod("remove_ValueEvent")), It.Is <object[]>(p => p.Length == 1 && p[0] is Func <int, int>)))
            .Verifiable();
            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IEventInterface).GetMethod("add_ReferenceEvent")), It.Is <object[]>(p => p.Length == 1 && p[0] is Func <object, object>)))
            .Verifiable();
            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IEventInterface).GetMethod("remove_ReferenceEvent")), It.Is <object[]>(p => p.Length == 1 && p[0] is Func <object, object>)))
            .Verifiable();
            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IEventInterface).GetMethod("add_VoidEvent")), It.Is <object[]>(p => p.Length == 1 && p[0] is Action)))
            .Verifiable();
            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IEventInterface).GetMethod("remove_VoidEvent")), It.Is <object[]>(p => p.Length == 1 && p[0] is Action)))
            .Verifiable();
            var invoker = mockInvoker.Object;

            var proxy = ProxyBuilder.Create <IEventInterface>(invoker.Invoke);

            proxy.ValueEvent     += ValueMethod;
            proxy.ValueEvent     -= ValueMethod;
            proxy.ReferenceEvent += ReferenceMethod;
            proxy.ReferenceEvent -= ReferenceMethod;
            proxy.VoidEvent      += VoidMethod;
            proxy.VoidEvent      -= VoidMethod;

            mockInvoker.Verify();
        }
Beispiel #2
0
        public void EnumMethodInvocationTest()
        {
            var mockInvoker = new Mock <IInvoker>();

            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m.Name == "ReturnEnum"), It.Is <object[]>(p => p.Length == 1 && (TestEnum)p[0] == TestEnum.One)))
            .Returns(TestEnum.Two);
            var invoker = mockInvoker.Object;

            var proxy = ProxyBuilder.Create <IEnum <TestEnum> >(invoker.Invoke);

            Assert.AreEqual(TestEnum.Two, proxy.ReturnEnum(TestEnum.One));
        }
Beispiel #3
0
        public bool XenStoreWrite(string path, string value)
        {
            XenClientGuestServiceProxy XenClientGuestService;

            ProxyBuilder.Create(out XenClientGuestService, DbusEndpointUriComponents.Create(EndpointBuilder));
            try
            {
                return(XenClientGuestService.ProxyInterface.XenStoreWrite(path, value));
            }
            finally
            {
                XenClientGuestService.Close();
            }
        }
Beispiel #4
0
        public void GenericMethodInvocationTest()
        {
            var mockInvoker = new Mock <IInvoker>();

            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m.Name == "MethodOfT"), It.Is <object[]>(p => p.Length == 1 && (int)p[0] == 1)))
            .Returns(5);
            //mockInvoker.Setup(mock => mock.Invoke(It.Is<MethodInfo>(m => m.Name == "BaseMethod"), It.Is<object[]>(p => p.Length == 1 && (int)p[0] == 1)))
            //    .Returns(5);
            //mockInvoker.Setup(mock => mock.Invoke(It.Is<MethodInfo>(m => m.Name == "DerivedMethod"), It.Is<object[]>(p => p.Length == 1 && (int)p[0] == 1)))
            //    .Returns(5);
            var invoker = mockInvoker.Object;

            var proxy = ProxyBuilder.Create <IGenericDerived>(invoker.Invoke);

            Assert.AreEqual(5, proxy.MethodOfT(1));
            //Assert.AreEqual(5, proxy.BaseMethod(1));
            //Assert.AreEqual(5, proxy.DerivedMethod(1));
        }
Beispiel #5
0
        public void MethodInvocationTest()
        {
            var mockInvoker = new Mock <IInvoker>();

            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IMethodInterface).GetMethod("GetValue")), It.Is <object[]>(p => p.Length == 2 && (int)p[0] == 1 && (float)p[1] == 2f)))
            .Returns(5);
            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IMethodInterface).GetMethod("GetReference")), It.Is <object[]>(p => p.Length == 2 && p[0] == o1 && p[1] == o2)))
            .Returns(o3);
            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IMethodInterface).GetMethod("GetVoid")), It.Is <object[]>(p => p.Length == 0)))
            .Returns(null)
            .Verifiable();
            var invoker = mockInvoker.Object;

            var proxy = ProxyBuilder.Create <IMethodInterface>(invoker.Invoke);

            Assert.AreEqual(5, proxy.GetValue(1, 2f));
            Assert.AreEqual(o3, proxy.GetReference(o1, o2));
            proxy.GetVoid();

            mockInvoker.Verify();
        }
Beispiel #6
0
        public void PropertyEvaluationTest()
        {
            var mockInvoker = new Mock <IInvoker>();

            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IPropertyInterface).GetMethod("get_Value")), It.Is <object[]>(p => p.Length == 0)))
            .Returns(5);
            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IPropertyInterface).GetMethod("set_Value")), It.Is <object[]>(p => p.Length == 1 && (int)p[0] == 123)))
            .Verifiable();
            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IPropertyInterface).GetMethod("get_Reference")), It.Is <object[]>(p => p.Length == 0)))
            .Returns(o1);
            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(IPropertyInterface).GetMethod("set_Reference")), It.Is <object[]>(p => p.Length == 1 && p[0] == o2)))
            .Verifiable();
            var invoker = mockInvoker.Object;

            var proxy = ProxyBuilder.Create <IPropertyInterface>(invoker.Invoke);

            Assert.AreEqual(5, proxy.Value);
            proxy.Value = 123;
            Assert.AreEqual(o1, proxy.Reference);
            proxy.Reference = o2;

            mockInvoker.Verify();
        }
Beispiel #7
0
 private void CreateSignalProxies()
 {
     ProxyBuilder.Create(out ConfigSignal, DbusEndpointUriComponents.Create(EndpointBuilder));
     ProxyBuilder.Create(out StateSignal, DbusEndpointUriComponents.Create(EndpointBuilder));
     ProxyBuilder.Create(out HostSignal, DbusEndpointUriComponents.Create(EndpointBuilder));
     ProxyBuilder.Create(out UpdateSignal, DbusEndpointUriComponents.Create(EndpointBuilder));
     ProxyBuilder.Create(out USBSignal, DbusEndpointUriComponents.Create(EndpointBuilder));
     ProxyBuilder.Create(out RequestSignal, DbusEndpointUriComponents.Create(EndpointBuilder));
 }