public void DecorateClassTest() { var method = new MockMethod() { Name = "Method", Parameters = new Dictionary <string, IParameter>() }; method.Parameters.Add("Param", new MockParameter() { Name = "Param" }); method.Parameters.Add("Param2", new MockParameter() { Name = "Param2" }); var resource = new MockResource(); resource.Methods.Add("Method", method); var resourceDecl = new CodeTypeDeclaration(); var requestDecl = new CodeTypeDeclaration(); // Confirm that the decorator adds the two parameters as properties with a backing field each. var decorator = new ParameterPropertyDecorator(); decorator.DecorateClass(resource, method, requestDecl, resourceDecl); Assert.AreEqual(4, requestDecl.Members.Count); // 2 properties + 2 field. Assert.AreEqual(0, resourceDecl.Members.Count); }
public void GenerateParameterPropertyTest() { var parameter = new MockParameter() { Name = "Param" }; var method = new MockMethod() { Name = "Method", Parameters = new Dictionary <string, IDiscoveryParameter>() }; method.Parameters.Add("Param", parameter); var resource = new MockResource(); resource.Methods.Add("Method", method); var resourceDecl = new CodeTypeDeclaration(); // Confirm that two properties and two fields are generated. var decorator = new ParameterPropertyDecorator(); CodeTypeMemberCollection newMembers = decorator.GenerateParameterProperty( parameter, method, resourceDecl, Enumerable.Empty <string>()); Assert.AreEqual(2, newMembers.Count); // Property + field. Assert.AreEqual(0, resourceDecl.Members.Count); // Check the generated property. Assert.IsInstanceOf <CodeMemberField>(newMembers[0]); CodeMemberProperty property = (CodeMemberProperty)newMembers[1]; Assert.AreEqual("Param", property.Name); // Check that the property has a Key attribute. Assert.AreEqual(1, property.CustomAttributes.Count); Assert.AreEqual( typeof(RequestParameterAttribute).FullName, property.CustomAttributes[0].AttributeType.BaseType); Assert.AreEqual( "Param", ((CodePrimitiveExpression)property.CustomAttributes[0].Arguments[0].Value).Value); }