Пример #1
0
 public LocalitySearchRequest(string cityName, int?limit)
     : base("Address", "searchSettlements")
 {
     this.methodProperties = new MethodProperties
     {
         CityName = cityName,
         Limit    = limit
     };
 }
 public WarehouseSearchRequest(string cityRef, int?limit, int?page)
     : base("AddressGeneral", "getWarehouses")
 {
     this.methodProperties = new MethodProperties
     {
         CityRef = cityRef,
         Limit   = limit,
         Page    = page
     };
 }
        public void AddMethodUnderTest(CodeTypeDeclaration classDeclaration,
                                       MethodProperties methodProperties,
                                       Type classType)
        {
            var testMethodName = $"{methodProperties.Name}{TestMethodNameExtension}";
            var method         = GetCodeMemberMethod(testMethodName, true);

            method.AddComment(Arrange);
            DeclareParameters(method, methodProperties.Parameters);
            DeclareMemberInstance(method, classType);
            method.AddEmptyLine();

            method.AddComment(Act);
            InvokeMethodWithParameters(method, methodProperties);

            classDeclaration.Members.Add(method);
            method.AddEmptyLine();
            method.AddComment(Assert);
        }
        private void InvokeMethodWithParameters(CodeMemberMethod method, MethodProperties methodProperties)
        {
            var methodParameters = methodProperties.Parameters
                                   .OrderBy(p => p.Position)
                                   .Select(p => BuildCodeExpression(p.Name))
                                   .ToArray();

            var methodCall = new CodeMethodInvokeExpression(new CodeArgumentReferenceExpression(TargetPropertyName),
                                                            methodProperties.Name,
                                                            methodParameters);

            if (methodProperties.ReturnType == typeof(void))
            {
                method.Statements.Add(methodCall);
            }
            else
            {
                method.Statements.Add(new CodeVariableDeclarationStatement(methodProperties.ReturnType,
                                                                           ActualPropertyName, methodCall));
            }
        }
 /// <summary>
 ///     Adds the named event property backed by the named accessor method.
 ///     <para />
 ///     The accessor method is expected to be a public method with no parameters
 ///     for simple event properties, or with a single integer parameter for indexed
 ///     event properties, or with a single String parameter for mapped event properties.
 /// </summary>
 /// <param name="name">is the event property name</param>
 /// <param name="accessorMethod">is the accessor method name.</param>
 public void AddMethodProperty(
     string name,
     string accessorMethod)
 {
     MethodProperties.Add(new LegacyMethodPropDesc(name, accessorMethod));
 }