public void ApplyTo_SetNewObjectToNullProperty_NestedPropertyShouldNotBeNull()
        {
            // Arrange
            dynamic incomingRequest = new ExpandoObject();

            incomingRequest.Id          = Guid.NewGuid();
            incomingRequest.ValueBool   = true;
            incomingRequest.ValueInt    = 19;
            incomingRequest.ValueString = "not null";

            incomingRequest.ValueThis    = new ExpandoObject();
            incomingRequest.ValueThis.Id = Guid.NewGuid();

            var originObject = new Entity
            {
                Id          = Guid.Empty,
                ValueBool   = false,
                ValueInt    = 20,
                ValueString = null,
                ValueThis   = null
            };

            // Act
            _reflectionHelper.ApplyTo((ExpandoObject)incomingRequest, ref originObject);

            // Assert
            Assert.IsNotNull(originObject.ValueThis);
        }
Beispiel #2
0
        public T ApplyPatchOperation <T>(T item, string jsonBody)
        {
            dynamic request;

            try
            {
                request = JsonConvert.DeserializeObject <ExpandoObject>(jsonBody);
            }
            catch (JsonReaderException e)
            {
                throw new ArgumentException("JSON argument has invalid format.", nameof(jsonBody), e);
            }

            _reflectionHelper.ApplyTo(request, ref item);

            return(item);
        }