Esempio n. 1
0
        /// <summary>
        /// Converts parameters, that are domain objects into their corresponding DTOs.
        /// </summary>
        /// <param name="parameters">Parameters with domain objects.</param>
        /// <returns></returns>
        private BodyParameters ConvertToDtoBodyParameters(BodyParameters parameters)
        {
            if (parameters == null)
            {
                return(null);
            }

            var convertedParameters = new BodyParameters();

            foreach (var bodyParameter in parameters.GetParameters())
            {
                var parameter = bodyParameter.Value;

                if (parameter == null)
                {
                    convertedParameters.AddNullParameter(bodyParameter.Key);
                    continue;
                }

                if (_dtoResolver.HasDataTransferObjectAssociated(parameter.GetType()))
                {
                    var dtoType    = _dtoResolver.GetDataTransferObjectRecursive(parameter.GetType());
                    var methodInfo = _mapper.GetType().GetMethods()
                                     .Single(x => x.Name == "Map" &&
                                             x.GetParameters().Length == 1 &&
                                             x.GetGenericArguments().Length == 1);
                    var method = methodInfo.MakeGenericMethod(dtoType);
                    parameter = Convert.ChangeType(
                        method.Invoke(_mapper, new object[] { parameter }),
                        dtoType);
                }

                convertedParameters.AddOptionalParameter(bodyParameter.Key, parameter);
            }

            return(convertedParameters);
        }
Esempio n. 2
0
        public void CanRecognizeDomainObject()
        {
            var isDomainObject = _resolver.HasDataTransferObjectAssociated(typeof(ClassC <>));

            isDomainObject.Should().BeTrue();
        }