Exemple #1
0
        public CodeModelCsaf()
        {
            _innerTypes = new HashSet <CompositeType>();

            var stringType = New <PrimaryType>(KnownPrimaryType.String, new
            {
                Name = "string"
            });

            _resourceType = New <CompositeType>(new
            {
                SerializedName = "Resource",
            });
            _resourceType.Name.FixedValue = "Microsoft.Rest.Azure.Resource";
            _resourceType.Add(New <Property>(new { Name = "location", SerializedName = "location", ModelType = stringType }));
            _resourceType.Add(New <Property>(new { Name = "id", SerializedName = "id", ModelType = stringType }));
            _resourceType.Add(New <Property>(new { Name = "name", SerializedName = "name", ModelType = stringType }));
            _resourceType.Add(New <Property>(new { Name = "type", SerializedName = "type", ModelType = stringType }));
            _resourceType.Add(New <Property>(new { Name = "tags", SerializedName = "tags", ModelType = New <DictionaryType>(new { ValueType = stringType, NameFormat = "System.Collections.Generic.IDictionary<string, {0}>" }) }));

            _subResourceType = New <CompositeType>(new
            {
                SerializedName = "SubResource"
            });
            _subResourceType.Name.FixedValue = "Microsoft.Rest.Azure.SubResource";
            _subResourceType.Add(New <Property>(new { Name = "id", SerializedName = "id", ModelType = stringType }));
        }
		public override object CreateMock(MockFactory mockFactory, CompositeType typesToMock, string name, MockStyle mockStyle, object[] constructorArgs)
		{
			_typesToMock = typesToMock;

			_typesToMock.Add(typeof(IMockObject));

			var reflectiveInterceptor = new ReflectiveInterceptor(mockFactory, typesToMock, name, mockStyle);

			var proxy = CreateMock(reflectiveInterceptor, constructorArgs);

			if (_typesToMock.PrimaryType.IsInterface)
				((InterfaceMockBase) proxy).Name = name;

			return proxy;
		}
Exemple #3
0
        public override object CreateMock(MockFactory mockFactory, CompositeType typesToMock, string name, MockStyle mockStyle, object[] constructorArgs)
        {
            _typesToMock = typesToMock;

            _typesToMock.Add(typeof(IMockObject));

            var reflectiveInterceptor = new ReflectiveInterceptor(mockFactory, typesToMock, name, mockStyle);

            var proxy = CreateMock(reflectiveInterceptor, constructorArgs);

            if (_typesToMock.PrimaryType.IsInterface)
            {
                ((InterfaceMockBase)proxy).Name = name;
            }

            return(proxy);
        }
Exemple #4
0
        /// <summary>
        /// Adds the parameter groups to operation parameters.
        /// </summary>
        /// <param name="codeModelient"></param>
        public static void AddParameterGroups(CodeModel codeModel)
        {
            if (codeModel == null)
            {
                throw new ArgumentNullException("codeModel");
            }

            HashSet <CompositeType> generatedParameterGroups = new HashSet <CompositeType>();

            foreach (Method method in codeModel.Methods)
            {
                //Copy out flattening transformations as they should be the last
                List <ParameterTransformation> flatteningTransformations = method.InputParameterTransformation.ToList();
                method.InputParameterTransformation.Clear();

                //This group name is normalized by each languages code generator later, so it need not happen here.
                IEnumerable <ParameterGroup> parameterGroups = ExtractParameterGroups(method);

                List <Parameter> parametersToAddToMethod      = new List <Parameter>();
                List <Parameter> parametersToRemoveFromMethod = new List <Parameter>();

                foreach (ParameterGroup parameterGroup in parameterGroups)
                {
                    CompositeType parameterGroupType =
                        generatedParameterGroups.FirstOrDefault(item => item.Name.RawValue == parameterGroup.Name);

                    if (parameterGroupType == null)
                    {
                        IEnumerable <Method> methodsWhichUseGroup = GetMethodsUsingParameterGroup(codeModel.Methods, parameterGroup);

                        parameterGroupType = New <CompositeType>(parameterGroup.Name, new
                        {
                            Documentation = GenerateParameterGroupModelText(methodsWhichUseGroup)
                        });
                        generatedParameterGroups.Add(parameterGroupType);

                        //Add to the service client
                        codeModel.Add(parameterGroupType);
                    }

                    foreach (Property property in parameterGroup.ParameterMapping.Keys)
                    {
                        Property matchingProperty = parameterGroupType.Properties.FirstOrDefault(
                            item => item.Name.RawValue == property.Name.RawValue &&
                            item.IsReadOnly == property.IsReadOnly &&
                            item.DefaultValue.RawValue == property.DefaultValue.RawValue &&
                            item.SerializedName.RawValue == property.SerializedName.RawValue);
                        if (matchingProperty == null)
                        {
                            parameterGroupType.Add(property);
                        }
                    }

                    bool isGroupParameterRequired = parameterGroupType.Properties.Any(p => p.IsRequired);

                    //Create the new parameter object based on the parameter group type
                    Parameter newParameter = New <Parameter>(new
                    {
                        Name           = parameterGroup.Name,
                        IsRequired     = isGroupParameterRequired,
                        Location       = ParameterLocation.None,
                        SerializedName = string.Empty,
                        ModelType      = parameterGroupType,
                        Documentation  = "Additional parameters for the operation"
                    });
                    parametersToAddToMethod.Add(newParameter);

                    //Link the grouped parameters to their parent, and remove them from the method parameters
                    foreach (Property property in parameterGroup.ParameterMapping.Keys)
                    {
                        Parameter p = parameterGroup.ParameterMapping[property];

                        var parameterTransformation = new ParameterTransformation
                        {
                            OutputParameter = p
                        };

                        parameterTransformation.ParameterMappings.Add(new ParameterMapping
                        {
                            InputParameter         = newParameter,
                            InputParameterProperty = property.GetClientName()
                        });
                        method.InputParameterTransformation.Add(parameterTransformation);
                        parametersToRemoveFromMethod.Add(p);
                    }
                }
                method.Remove(p => parametersToRemoveFromMethod.Contains(p));
                method.AddRange(parametersToAddToMethod);

                // Copy back flattening transformations if any
                flatteningTransformations.ForEach(t => method.InputParameterTransformation.Add(t));
            }
        }