Ejemplo n.º 1
0
        public void GetValueWithExceptionTest()
        {
            // Arrange
            string objectId  = "objId1";
            var    recipient = new Recipient();
            var    request   = new PropertyGetRequest()
            {
                objectId   = objectId,
                propertyId = ObjectDescriptor.GetPropertyId <IRegisteredObject>(nameof(IRegisteredObject.StringValueProperty))
            };

            recipient.Register(objectId, _regObjectMock.Object);
            _regObjectMock.SetupGet(o => o.StringValueProperty).Throws(new NotImplementedException());

            // Act
            var response = recipient.Request(request) as ExceptionResponse;

            // Assert
            _serviceMock.Verify();
            _regObjectMock.Verify();

            Assert.AreEqual(ResponseType.exception, response.responseType);
            Assert.IsTrue(response.exception.Message.Contains(objectId) &&
                          response.exception.Message.Contains(nameof(IRegisteredObject.StringValueProperty)));
        }
Ejemplo n.º 2
0
        public void SetValueWithoutExceptionTest()
        {
            // Arrange
            string objectId      = "objId1";
            string expectedValue = "toBeExpected";

            _regObjectMock.Setup(o => o.StringValueProperty).Returns(expectedValue);
            var recipient = new Recipient();
            var request   = new PropertySetRequest()
            {
                objectId   = objectId,
                propertyId = ObjectDescriptor.GetPropertyId <IRegisteredObject>(nameof(IRegisteredObject.StringValueProperty)),
                value      = expectedValue
            };

            // Act
            recipient.Register(objectId, _regObjectMock.Object);
            var response = recipient.Request(request) as PropertySetResponse;

            // Assert
            _serviceMock.Verify();
            _regObjectMock.Verify();

            Assert.AreEqual(expectedValue, _regObjectMock.Object.StringValueProperty);

            Assert.AreEqual(ResponseType.propertySet, response.responseType);
            Assert.AreEqual(request.objectId, response.objectId);
            Assert.AreEqual(request.propertyId, response.propertyId);
        }
        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);
        }