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 Initialize()
        {
            var response = new ConnectionResponse
            {
                CommunicationToken    = Guid.NewGuid(),
                ConnectionEstablished = true
            };

            logger             = new Mock <ILogger>();
            proxyObjectFactory = new Mock <IProxyObjectFactory>();
            proxy = new Mock <IProxyObject>();

            proxy.Setup(p => p.Connect(It.IsAny <Guid>())).Returns(response);
            proxy.Setup(o => o.State).Returns(CommunicationState.Opened);
            proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny <string>())).Returns(proxy.Object);

            sut = new RuntimeProxy("net.pipe://random/address/here", proxyObjectFactory.Object, logger.Object, default(Interlocutor));
            sut.Connect(Guid.NewGuid());
        }
        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();
        }