public void SubscribeWithArgsTest()
        {
            // Arrange
            string objectId        = "objId1";
            var    expectedRequest = new SubscribeRequest()
            {
                objectId = objectId,
                eventId  = ObjectDescriptor.GetEventId <IRegisteredObject>(nameof(IRegisteredObject.NotifyOnDataChanged))
            };
            SubscribeRequest actualRequest = null;

            _clientMock.Setup(o => o.Request(It.IsAny <SubscribeRequest>())).Returns <SubscribeRequest>(req =>
            {
                actualRequest = req;

                return(new SubscribeResponse()
                {
                    objectId = objectId,
                    eventId = ObjectDescriptor.GetEventId <IRegisteredObject>(nameof(IRegisteredObject.NotifyOnDataChanged))
                });
            });
            var objProxy = RuntimeProxy.Create <IRegisteredObject>(objectId, _clientMock.Object);

            // Act
            objProxy.NotifyOnDataChanged += (s, e) => { };

            // Assert
            _clientMock.VerifyAll();
            Assert.AreEqual(expectedRequest.objectId, actualRequest.objectId);
            Assert.AreEqual(expectedRequest.eventId, actualRequest.eventId);
        }
        public void InvokeVoidReturnParamsTest()
        {
            // Arrange
            string objectId = "obj1Id";
            var    proxyObj = RuntimeProxy.Create <IRegisteredObject>(objectId, _clientMock.Object);

            object[] args = null;
            _clientMock.Setup(o => o.Request(It.IsAny <InvokeRequest>())).Returns <InvokeRequest>(req =>
            {
                args = new object[]
                {
                    (req.methodArgs[0] as object[])[0],
                    (req.methodArgs[0] as object[])[1]
                };
                return(new InvokeResponse()
                {
                    objectId = objectId,
                    methodId = ObjectDescriptor.GetMethodId <IRegisteredObject>(nameof(IRegisteredObject.VoidReturnMethod)),
                    result = null
                });
            });

            // Act
            proxyObj.VoidReturnMethod("string", 2.0);

            // Assert
            _clientMock.VerifyAll();
            Assert.AreEqual("string", args[0]);
            Assert.AreEqual(2.0, args[1]);
        }
        public void PropertySetValue()
        {
            // Arrange
            string objectId      = "obj1Id";
            var    proxyObj      = RuntimeProxy.Create <IRegisteredObject>(objectId, _clientMock.Object);
            string expectedValue = "actual value";
            string actualValue   = null;

            _clientMock.Setup(o => o.Request(It.IsAny <PropertySetRequest>())).Returns <PropertySetRequest>(req =>
            {
                actualValue = req.value as string;
                return(new PropertySetResponse()
                {
                    objectId = objectId,
                    propertyId = ObjectDescriptor.GetPropertyId <IRegisteredObject>(nameof(IRegisteredObject.StringValueProperty))
                });
            });

            // Act
            proxyObj.StringValueProperty = expectedValue;

            // Assert
            _clientMock.VerifyAll();
            Assert.AreEqual(expectedValue, actualValue);
        }
        public void SubscribeNoArgsWithExceptionTest()
        {
            // Arrange
            string objectId = "objId1";

            _clientMock.Setup(o => o.Request(It.IsAny <IRequest>())).Returns <IRequest>(req =>
            {
                throw new NotImplementedException();
            });
            var objProxy = RuntimeProxy.Create <IRegisteredObject>(objectId, _clientMock.Object);

            // Act
            objProxy.NotifyOnNonDataChanged += (s, e) => { };

            // Assert
            _clientMock.VerifyAll();
        }
        public void UnsubscribeNoArgsWithResponseExceptionTest()
        {
            // Arrange
            string objectId = "objId1";

            _clientMock.Setup(o => o.Request(It.IsAny <IRequest>())).Returns <IRequest>(req =>
            {
                return(new ExceptionResponse()
                {
                    exception = new RecipientBindingException()
                });
            });
            var objProxy = RuntimeProxy.Create <IRegisteredObject>(objectId, _clientMock.Object);

            // Act
            objProxy.NotifyOnNonDataChanged -= (s, e) => { };

            // Assert
            _clientMock.VerifyAll();
        }
        public void UnsubscribeNoArgsWithWrongEventIdTest()
        {
            // Arrange
            string objectId = "objId1";

            _clientMock.Setup(o => o.Request(It.IsAny <IRequest>())).Returns <IRequest>(req =>
            {
                return(new UnsubscribeResponse()
                {
                    objectId = objectId,
                    eventId = "wrongEventId"
                });
            });
            var objProxy = RuntimeProxy.Create <IRegisteredObject>(objectId, _clientMock.Object);

            // Act
            objProxy.NotifyOnNonDataChanged -= (s, e) => { };

            // Assert
            _clientMock.VerifyAll();
        }