internal static CodeTypeDeclaration GenerateScopeEnumeration(IEnumerable <Scope> scopes) { CodeTypeDeclaration decl = new CodeTypeDeclaration(EnumName); decl.IsEnum = true; decl.Comments.AddRange(DecoratorUtil.CreateSummaryComment(EnumDescription)); // Add the enumeration members. List <string> usedWords = new List <string>(); foreach (Scope scope in scopes) { // Create a enum name string valueName = GetValueName(scope); string safeName = GeneratorUtils.GetEnumValueName(valueName, usedWords); // Create the value and add the StringValue attribute. var newMember = new CodeMemberField(typeof(int), safeName); var stringValueRef = new CodeTypeReference(typeof(StringValueAttribute)); var stringValueAttribute = new CodeAttributeDeclaration(stringValueRef); stringValueAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(scope.ID))); newMember.CustomAttributes.Add(stringValueAttribute); // Add the description. newMember.Comments.AddRange(DecoratorUtil.CreateSummaryComment(scope.Description)); usedWords.Add(safeName); decl.Members.Add(newMember); } return(decl); }
public void DecorateClass(IResource resource, string className, CodeTypeDeclaration resourceClass, ResourceClassGenerator generator, string serviceClassName, IEnumerable <IResourceDecorator> allDecorators) { foreach (IMethod method in resource.Methods.Values) { foreach (IDiscoveryParameter parameter in method.Parameters.Values) { if (parameter.EnumValues.IsNullOrEmpty()) { continue; // Not an enumeration type. } // Check whether the type already exists. if (DecoratorUtil.FindFittingEnumeration( resourceClass, parameter.EnumValues, parameter.EnumValueDescriptions) != null) { continue; } // Create and add the enumeration. resourceClass.Members.Add(GenerateEnum( resourceClass, parameter.Name, parameter.Description, parameter.EnumValues, parameter.EnumValueDescriptions)); } } }
public void GetPropertyInfoProp() { // Regression test for (internal). Use a decorated factory since // propertyInfo.pProperty should be the decorated object. var decoratorUtil = new DecoratorUtil( new ProxyGenerationOptions(new DebugEngineProxyHook())); // Needs at least one aspect or else decorator is not assigned to Self. IDecorator factoryDecorator = decoratorUtil.CreateFactoryDecorator( new ProxyGenerator(), new NoopAspect()); DebugAsyncProperty.Factory decoratedPropertyFactory = factoryDecorator.Decorate(propertyFactory); IGgpAsyncDebugProperty decoratedDebugProperty = decoratedPropertyFactory.Create(mockVarInfo); DEBUG_PROPERTY_INFO propertyInfo; decoratedDebugProperty.GetPropertyInfo(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP, out propertyInfo); Assert.That( propertyInfo.dwFields.HasFlag(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_PROP)); Assert.That(propertyInfo.pProperty, Is.SameAs(decoratedDebugProperty)); }
internal static CodeTypeReference GetParameterTypeReference(CodeTypeDeclaration classDeclaration, IParameter param) { Type underlyingType = GetParameterType(param); CodeTypeReference paramTypeRef = new CodeTypeReference(underlyingType); bool isValueType = underlyingType.IsValueType; // Check if we need to declare a custom type for this parameter. // If the parameter is an enum, try finding the matching enumeration in the current class if (!param.EnumValues.IsNullOrEmpty()) { // Naming scheme: MethodnameParametername CodeTypeReference enumReference = DecoratorUtil.FindFittingEnumeration( classDeclaration, param.EnumValues, param.EnumValueDescriptions); if (enumReference != null) { paramTypeRef = enumReference; isValueType = true; } } // Check if this is an optional value parameter. if (isValueType && !param.IsRequired) { paramTypeRef = new CodeTypeReference(typeof(Nullable <>)) { TypeArguments = { paramTypeRef.BaseType } }; // An optional value parameter has to be nullable. } return(paramTypeRef); }
public void AddMembersToClassTest() { var decl = new CodeTypeDeclaration(); var memberA = new CodeTypeMember() { Name = "MemberA" }; var memberB = new CodeTypeMember() { Name = "MemberB" }; var memberC = new CodeTypeMember() { Name = "MemberA" }; // Test parameter validation Assert.Throws <ArgumentNullException>( () => DecoratorUtil.AddMembersToClass(null, new CodeTypeMemberCollection())); Assert.Throws <ArgumentNullException>(() => DecoratorUtil.AddMembersToClass(decl, null)); // Add a single element. DecoratorUtil.AddMembersToClass(decl, new CodeTypeMemberCollection(new[] { memberA })); Assert.AreEqual(1, decl.Members.Count); // Confirm that this element is skipped when adding it twice. DecoratorUtil.AddMembersToClass(decl, new CodeTypeMemberCollection(new[] { memberA })); Assert.AreEqual(1, decl.Members.Count); // Add the remaining elements DecoratorUtil.AddMembersToClass(decl, new CodeTypeMemberCollection(new[] { memberA, memberB, memberC })); Assert.AreEqual(2, decl.Members.Count); }
public void FindFittingEnumerationTest() { CodeTypeDeclaration decl = new CodeTypeDeclaration(); IEnumerable <string> enumValues = new[] { "foo", "bar", "42" }; IEnumerable <string> enumValues2 = new[] { "foo", "bar", "cake" }; IEnumerable <string> enumValues3 = new[] { "foo", "bar" }; // Test parameter validation. Assert.Throws <ArgumentNullException>(() => DecoratorUtil.FindFittingEnumeration(decl, null, null)); Assert.Throws <ArgumentNullException>(() => DecoratorUtil.FindFittingEnumeration(null, enumValues, null)); // Test with empty class. Assert.IsNull(DecoratorUtil.FindFittingEnumeration(decl, enumValues, null)); // Add an enum, and check whether it can be found. CodeTypeDeclaration testEnum = EnumResourceDecorator.GenerateEnum( decl, "SomeName", "SomeDescription", enumValues, null); decl.Members.Add(testEnum); Assert.AreEqual(testEnum.Name, DecoratorUtil.FindFittingEnumeration(decl, enumValues, null).BaseType); // Confirm that the other values are not found. Assert.IsNull(DecoratorUtil.FindFittingEnumeration(decl, enumValues2, null)); Assert.IsNull(DecoratorUtil.FindFittingEnumeration(decl, enumValues3, null)); // Check that the code also works with two enumerations CodeTypeDeclaration testEnum3 = EnumResourceDecorator.GenerateEnum( decl, "SomeOtherName", "SomeDescription", enumValues3, null); decl.Members.Add(testEnum3); Assert.AreEqual(testEnum.Name, DecoratorUtil.FindFittingEnumeration(decl, enumValues, null).BaseType); Assert.AreEqual(testEnum3.Name, DecoratorUtil.FindFittingEnumeration(decl, enumValues3, null).BaseType); Assert.IsNull(DecoratorUtil.FindFittingEnumeration(decl, enumValues2, null)); }
internal CodeTypeMemberCollection CreateServiceParametersProperty() { var property = DecoratorUtil.CreateAutoProperty( ServiceParametersName, string.Empty, new CodeTypeReference(typeof(IDictionary <string, IParameter>)), Enumerable.Empty <string>(), true, null, MemberAttributes.Override | MemberAttributes.Public); return(property); }
public void CreateSummaryCommentXmlEscapeTest() { string aShortDescription = "A 'Short\" <description> <for/> test & fun"; var result = DecoratorUtil.CreateSummaryComment(aShortDescription); string desiredComment = "<summary>A 'Short" <description> <for/> test & fun</summary>"; Assert.AreEqual(desiredComment, result[0].Comment.Text); }
public void DecorateClass(IService service, CodeTypeDeclaration serviceClass) { CodeTypeMemberCollection col = DecoratorUtil.CreateAutoProperty( PropertyName, "Sets the API-Key (or DeveloperKey) which this service uses for all requests", new CodeTypeReference(typeof(string)), GeneratorUtils.GetUsedWordsFromMembers(serviceClass.Members), false, null); serviceClass.Members.AddRange(col); }
public void CreateInitParameters_NullDictionary() { CodeMemberMethod method = new CodeMemberMethod(); DecoratorUtil.AddInitializeParameters(method, "par", null); Assert.AreEqual(2, method.Statements.Count); // new and assignment Assert.That(method.Statements[0], Is.InstanceOf <CodeVariableDeclarationStatement>()); Assert.That(method.Statements[1], Is.InstanceOf <CodeAssignStatement>()); }
public void CreateSummaryCommentTest() { string aShortDescription = "A Short description for test"; var result = DecoratorUtil.CreateSummaryComment(aShortDescription); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); Assert.IsNotNull(result[0].Comment); Assert.AreEqual(true, result[0].Comment.DocComment); Assert.AreEqual("<summary>" + aShortDescription + "</summary>", result[0].Comment.Text); }
public void CreateBackingFieldEdgeCaseTest() { const string name = "TestProperty"; CodeTypeReference type = new CodeTypeReference(typeof(object)); string[] usedWords = new string[] { }; Assert.Throws <ArgumentNullException>(() => DecoratorUtil.CreateBackingField(null, type, usedWords)); Assert.Throws <ArgumentNullException>(() => DecoratorUtil.CreateBackingField(name, null, usedWords)); Assert.Throws <ArgumentNullException>(() => DecoratorUtil.CreateBackingField(name, type, null)); }
internal static CodeTypeDeclaration GenerateEnum(CodeTypeDeclaration typeDeclaration, string proposedName, string description, IEnumerable <KeyValuePair <string, string> > entries) { typeDeclaration.ThrowIfNull("typeDeclaration"); proposedName.ThrowIfNullOrEmpty("proposedName"); entries.ThrowIfNull("entries"); // Create a safe enum name by avoiding the names of all members which are already in this type. IEnumerable <string> memberNames = from CodeTypeMember m in typeDeclaration.Members select m.Name; string name = GeneratorUtils.GetEnumName(proposedName, memberNames); // Create the enum type. var decl = new CodeTypeDeclaration(name); decl.IsEnum = true; // Get the EnumStringValueTypeConverter type. Type converterType = typeof(EnumStringValueTypeConverter); // [TypeConverter(..)] var typeConvAttribute = new CodeAttributeDeclaration( new CodeTypeReference(typeof(TypeConverterAttribute))); // .. typeof(EnumStringValueTypeConverter) .. typeConvAttribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(converterType))); decl.CustomAttributes.Add(typeConvAttribute); foreach (KeyValuePair <string, string> enumEntry in entries) { // Consider the names of all members in the current type as used words. IEnumerable <string> usedNames = from CodeTypeMember m in decl.Members select m.Name; string safeName = GeneratorUtils.GetEnumValueName(enumEntry.Key, usedNames); var member = new CodeMemberField(typeof(int), safeName); // Attribute: var valueAttribute = new CodeAttributeDeclaration(); valueAttribute.Name = typeof(StringValueAttribute).FullName; valueAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(enumEntry.Key))); member.CustomAttributes.Add(valueAttribute); // Comments: member.Comments.AddRange(DecoratorUtil.CreateSummaryComment(enumEntry.Value)); // Add member to enum. decl.Members.Add(member); } // Class comment: decl.Comments.AddRange(DecoratorUtil.CreateSummaryComment(description)); return(decl); }
/// <summary> /// Gets decorator used for Debug object factories and other factories for types /// that we want to wrap with aspects provided by CreateApiAspects(). /// </summary> public IDecorator GetFactoryDecorator() { if (_factoryDecorator == null) { var decoratorUtil = new DecoratorUtil(new ProxyGenerationOptions(new DebugEngineProxyHook())); _factoryDecorator = decoratorUtil.CreateFactoryDecorator( new ProxyGenerator(), CreateApiAspects().ToArray()); } return(_factoryDecorator); }
/// <summary>Generates an <seealso cref="Google.Apis.Download.IMediaDownloader"/> property.</summary> private static void GenerateMediaDownloaderProperty(CodeTypeDeclaration requestClass) { // Generates: // private IMediaDownloader _mediaDownloader; // public IMediaDownloader MediaDownloader { get { return _mediaDownloader; } } foreach (CodeTypeMember memeber in DecoratorUtil.CreateAutoProperty("mediaDownloader", null, new CodeTypeReference(typeof(IMediaDownloader)), new List <string>(), true)) { requestClass.Members.Add(memeber); } }
internal static CodeTypeDeclaration GenerateEnum(CodeTypeDeclaration typeDeclaration, string proposedName, string description, IEnumerable <string> enumValues, IEnumerable <string> enumDescriptions) { // Add the comments to the values if possible, or create empty ones. IEnumerable <KeyValuePair <string, string> > enumEntries = DecoratorUtil.GetEnumerablePairs( enumValues, enumDescriptions); return(GenerateEnum(typeDeclaration, proposedName, description, enumEntries)); }
public void CreateSummaryCommentEmptyCommentTest() { // Test an empty comment. var result = DecoratorUtil.CreateSummaryComment(""); Assert.IsNotNull(result); Assert.IsEmpty(result); // Test a null comment. result = DecoratorUtil.CreateSummaryComment(null); Assert.IsNotNull(result); Assert.IsEmpty(result); }
public void DecorateClass(IService service, CodeTypeDeclaration serviceClass) { var method = new CodeMemberMethod(); // Generate: private void InitParameters() method.Name = InitParametersName; method.ReturnType = new CodeTypeReference(typeof(void)); method.Attributes = MemberAttributes.Private; // Add request parameters initialization DecoratorUtil.AddInitializeParameters(method, "_serviceParameters", service.Parameters); serviceClass.Members.Add(method); }
public void CreateBackingFieldTest() { const string name = "TestProperty"; CodeTypeReference type = new CodeTypeReference(typeof(bool)); string[] usedWords = new string[] { }; CodeMemberField field = DecoratorUtil.CreateBackingField(name, type, usedWords); Assert.IsNotNull(field); Assert.That(field.Name, Is.EqualTo("_TestProperty")); Assert.That(field.Type.BaseType, Is.EqualTo(typeof(bool).FullName)); Assert.That(field.Attributes, Is.EqualTo(MemberAttributes.Private)); }
public void DecorateClass(IResource resource, IMethod request, CodeTypeDeclaration requestClass, CodeTypeDeclaration resourceClass) { var method = new CodeMemberMethod(); // Generate: private void InitParameters() method.Name = "InitParameters"; method.ReturnType = new CodeTypeReference(typeof(void)); method.Attributes = MemberAttributes.Private; // Add request parameters initialization DecoratorUtil.AddInitializeParameters(method, ParametersName, request.Parameters); requestClass.Members.Add(method); }
public void CreateAutoPropertyEdgeCaseTest() { const string name = "TestProperty"; const string comment = "Comment"; CodeTypeReference type = new CodeTypeReference(typeof(object)); string[] usedWords = new string[] { }; Assert.Throws <ArgumentNullException>( () => DecoratorUtil.CreateAutoProperty(null, comment, type, usedWords, false)); Assert.Throws <ArgumentNullException>( () => DecoratorUtil.CreateAutoProperty(name, comment, null, usedWords, false)); Assert.Throws <ArgumentNullException>( () => DecoratorUtil.CreateAutoProperty(name, comment, type, null, false)); Assert.DoesNotThrow(() => DecoratorUtil.CreateAutoProperty(name, null, type, usedWords, false)); }
internal static CodeTypeMemberCollection CreateETagProperty(CodeTypeDeclaration typeDeclaration) { CodeMemberProperty property = typeDeclaration.Members.FindPropertyByName(ETagPropertyName); if (property != null) { if (property.ImplementationTypes.Count == 0) { property.ImplementationTypes.Add(new CodeTypeReference(typeof(IDirectResponseSchema))); } return(new CodeTypeMemberCollection()); // Don't add a new property; it's already there. } CodeTypeReference type = new CodeTypeReference(typeof(string)); return(DecoratorUtil.CreateAutoProperty(ETagPropertyName, null, type, Enumerable.Empty <string>(), false, typeof(IDirectResponseSchema))); }
public void IsFittingEnumCommectTest() { var decl = new CodeTypeDeclaration(); IEnumerable <string> enumValues = new[] { "foo", "bar", "42" }; IEnumerable <string> enumCommentsA = new[] { "fish", "dolphins", "mice" }; IEnumerable <string> enumCommentsB = new[] { "fishy", "dolphiny", "micy" }; IEnumerable <string> enumCommentsC = null; // Add an enum, and check whether it can be found. CodeTypeDeclaration testEnum = EnumResourceDecorator.GenerateEnum( decl, "SomeName", "SomeDescription", enumValues, enumCommentsA); decl.Members.Add(testEnum); Assert.IsTrue(DecoratorUtil.IsFittingEnum(testEnum, enumValues, enumCommentsA)); Assert.IsFalse(DecoratorUtil.IsFittingEnum(testEnum, enumValues, enumCommentsB)); Assert.IsFalse(DecoratorUtil.IsFittingEnum(testEnum, enumValues, enumCommentsC)); }
public void IsFittingEnumTest() { var decl = new CodeTypeDeclaration(); IEnumerable <string> enumValues = new[] { "foo", "bar", "42" }; IEnumerable <string> enumValues2 = new[] { "foo", "bar", "cake" }; IEnumerable <string> enumValues3 = new[] { "foo", "bar" }; // Add an enum, and check whether it can be found. CodeTypeDeclaration testEnum = EnumResourceDecorator.GenerateEnum( decl, "SomeName", "SomeDescription", enumValues, null); decl.Members.Add(testEnum); Assert.IsTrue(DecoratorUtil.IsFittingEnum(testEnum, enumValues, null)); Assert.IsFalse(DecoratorUtil.IsFittingEnum(testEnum, enumValues2, null)); Assert.IsFalse(DecoratorUtil.IsFittingEnum(testEnum, enumValues3, null)); Assert.IsFalse(DecoratorUtil.IsFittingEnum(testEnum, Enumerable.Empty <string>(), null)); }
internal static CodeTypeMemberCollection CreateErrorProperty(CodeTypeDeclaration typeDeclaration) { CodeTypeReference type = new CodeTypeReference(typeof(RequestError)); CodeTypeMemberCollection col = DecoratorUtil.CreateAutoProperty( ErrorPropertyName, null, type, Enumerable.Empty <string>(), false, typeof(IDirectResponseSchema)); // Find the created property and add the JsonProperty to it. foreach (CodeTypeMember member in col) { if (member is CodeMemberProperty) { member.CustomAttributes.Add(NewtonSoftPropertyAttributeDecorator.CreateAttribute(ErrorJsonName)); break; } } return(col); }
internal CodeTypeMemberCollection GenerateParameterProperty(IDiscoveryParameter parameter, IMethod method, CodeTypeDeclaration resourceClass, IEnumerable <string> usedNames) { // Get the name and return type of this parameter. string name = parameter.Name; CodeTypeReference returnType = ResourceBaseGenerator.GetParameterTypeReference( resourceClass, parameter); // Generate the property and field. CodeTypeMemberCollection newMembers = DecoratorUtil.CreateAutoProperty( name, parameter.Description, returnType, usedNames, parameter.IsRequired, null); // Add the KeyAttribute to the property. foreach (CodeTypeMember member in newMembers) { CodeMemberProperty property = member as CodeMemberProperty; if (property == null) { continue; } RequestParameterType requestParameterType = parameter.ParameterType == PathParameter ? RequestParameterType.Path : RequestParameterType.Query; // Declare the RequestParameter attribute. CodeTypeReference attributeType = new CodeTypeReference(typeof(RequestParameterAttribute)); // Generates something like.. // [Google.Apis.Util.RequestParameterAttribute("prettyPrint", // Google.Apis.Util.RequestParameterType.Query)] CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType); attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(parameter.Name))); attribute.Arguments.Add( new CodeAttributeArgument( new CodeFieldReferenceExpression( new CodeTypeReferenceExpression(typeof(RequestParameterType)), Enum.GetName(typeof(RequestParameterType), requestParameterType)))); property.CustomAttributes.Add(attribute); } return(newMembers); }
public void CompareEqualWithProxy() { var proxyGenerator = new Castle.DynamicProxy.ProxyGenerator(); var decoratorUtil = new DecoratorUtil(); // Create the factory. var factory = new DebugMemoryContext.Factory(); // Decorate the factory with a dummy aspect. var aspect = new YetiCommon.Tests.CastleAspects.TestSupport.CallCountAspect(); var factoryDecorator = decoratorUtil.CreateFactoryDecorator(proxyGenerator, aspect); var factoryWithProxy = factoryDecorator.Decorate(factory); var memoryContextWithProxy = factoryWithProxy.Create(TEST_PC, TEST_NAME); // Check all the combinations of comparing proxied and non-proxied memory context. uint matchIndex; Assert.AreEqual(VSConstants.S_OK, memoryContextWithProxy.Compare( enum_CONTEXT_COMPARE.CONTEXT_EQUAL, new IDebugMemoryContext2[1] { memoryContextWithProxy }, 1, out matchIndex)); Assert.AreEqual(0, matchIndex); Assert.AreEqual(VSConstants.S_OK, memoryContext.Compare( enum_CONTEXT_COMPARE.CONTEXT_EQUAL, new IDebugMemoryContext2[1] { memoryContextWithProxy }, 1, out matchIndex)); Assert.AreEqual(0, matchIndex); Assert.AreEqual(VSConstants.S_OK, memoryContextWithProxy.Compare( enum_CONTEXT_COMPARE.CONTEXT_EQUAL, new IDebugMemoryContext2[1] { memoryContext }, 1, out matchIndex)); Assert.AreEqual(0, matchIndex); }
public void CreateAutoPropertyTest() { const string name = "TestProperty"; const string comment = "Comment"; CodeTypeReference type = new CodeTypeReference(typeof(int)); string[] usedWords = new string[] { }; CodeTypeMemberCollection col = DecoratorUtil.CreateAutoProperty(name, comment, type, usedWords, false); Assert.That(col.Count, Is.EqualTo(2)); Assert.That(col[1], Is.InstanceOf <CodeMemberProperty>()); Assert.That(col[1].Attributes, Is.EqualTo(MemberAttributes.Public)); Assert.That(col[0], Is.InstanceOf <CodeMemberField>()); var property = col[1] as CodeMemberProperty; Assert.IsNotNull(property); Assert.That(property.Name, Is.EqualTo(name)); Assert.That(property.Type.BaseType, Is.EqualTo(typeof(int).FullName)); // Backening field is tested in its own unit case. }
public void GetEnumerablePairsTest() { string[] keys = new[] { "a", "b", "c" }; string[] values = new[] { "1", "2", "3" }; string[] invalidSized = new[] { "1", "2", "3", "x", "y" }; // Test parameter validation. Assert.Throws <ArgumentNullException>( () => DecoratorUtil.GetEnumerablePairs((string[])null, values).First()); Assert.DoesNotThrow(() => DecoratorUtil.GetEnumerablePairs(keys, (string[])null).First()); Assert.Throws <ArgumentException>(() => DecoratorUtil.GetEnumerablePairs(keys, invalidSized).First()); Assert.Throws <ArgumentException>(() => DecoratorUtil.GetEnumerablePairs(invalidSized, values).First()); // Test simple operation. IEnumerable <KeyValuePair <string, string> > joined = DecoratorUtil.GetEnumerablePairs(keys, values); Assert.AreEqual(3, joined.Count()); foreach (KeyValuePair <string, string> pair in joined) { Assert.AreEqual(pair.Key[0] - 'a', pair.Value[0] - '1'); } }
public void CreateInitParameters_WithParameters() { CodeMemberMethod method = new CodeMemberMethod(); var parameters = new Dictionary <string, IDiscoveryParameter>(); parameters["param1"] = new MockParameter { Name = "param1", DefaultValue = "default", IsRequired = true, Pattern = "pattern", ParameterType = "type", EnumValues = new[] { "1", "2" } }; DecoratorUtil.AddInitializeParameters(method, "par", parameters); Assert.AreEqual(3, method.Statements.Count); // new, assignment and add parameter on dictionary methods Assert.That(method.Statements[0], Is.InstanceOf <CodeVariableDeclarationStatement>()); // parameters.Add(param1, ...) Assert.That(method.Statements[1], Is.InstanceOf <CodeExpressionStatement>()); CodeExpressionStatement exp = method.Statements[1] as CodeExpressionStatement; Assert.That(exp.Expression, Is.InstanceOf <CodeMethodInvokeExpression>()); CodeMethodInvokeExpression addMethod = exp.Expression as CodeMethodInvokeExpression; Assert.AreEqual("Add", addMethod.Method.MethodName); Assert.AreEqual(2, addMethod.Parameters.Count); // parameters = param1, CreateRuntimeParameter(...) Assert.That(addMethod.Parameters[0], Is.InstanceOf <CodePrimitiveExpression>()); var nameExp = addMethod.Parameters[0] as CodePrimitiveExpression; Assert.AreEqual("param1", nameExp.Value); Assert.That(addMethod.Parameters[1], Is.InstanceOf <CodeMethodInvokeExpression>()); var createParameterExp = addMethod.Parameters[1] as CodeMethodInvokeExpression; Assert.AreEqual("CreateRuntimeParameter", createParameterExp.Method.MethodName); Assert.AreEqual(6, createParameterExp.Parameters.Count); // name Assert.That(createParameterExp.Parameters[0], Is.InstanceOf <CodePrimitiveExpression>()); Assert.AreEqual("param1", (createParameterExp.Parameters[0] as CodePrimitiveExpression).Value); // is required Assert.That(createParameterExp.Parameters[1], Is.InstanceOf <CodePrimitiveExpression>()); Assert.AreEqual(true, (createParameterExp.Parameters[1] as CodePrimitiveExpression).Value); // parameter type Assert.That(createParameterExp.Parameters[2], Is.InstanceOf <CodePrimitiveExpression>()); Assert.AreEqual("type", (createParameterExp.Parameters[2] as CodePrimitiveExpression).Value); // default value Assert.That(createParameterExp.Parameters[3], Is.InstanceOf <CodePrimitiveExpression>()); Assert.AreEqual("default", (createParameterExp.Parameters[3] as CodePrimitiveExpression).Value); // pattern Assert.That(createParameterExp.Parameters[4], Is.InstanceOf <CodePrimitiveExpression>()); Assert.AreEqual("pattern", (createParameterExp.Parameters[4] as CodePrimitiveExpression).Value); // enum values Assert.That(createParameterExp.Parameters[5], Is.InstanceOf <CodeArrayCreateExpression>()); Assert.AreEqual(2, (createParameterExp.Parameters[5] as CodeArrayCreateExpression).Initializers.Count); Assert.That(method.Statements[2], Is.InstanceOf <CodeAssignStatement>()); }