public void DecorateClassRenamingTest() { var dec = new SubresourceClassDecorator(); var resource = new MockResource(); const string className = "TestClass"; var decl = new CodeTypeDeclaration(); const string serviceName = "TestService"; var decorators = new IResourceDecorator[0]; // Create generators. var resourceGen = new ResourceContainerGenerator(new IResourceContainerDecorator[0]); var requestGen = new RequestClassGenerator(new IRequestDecorator[0]); var gen = new ResourceClassGenerator( resource, serviceName, decorators, requestGen, resourceGen, new string[0]); // Add subresources. resource.Resources.Add("Sub1", new MockResource { Name = "Sub1" }); resource.Resources.Add("Sub2", new MockResource { Name = "Sub2" }); // Add existing members decl.Members.Add(new CodeMemberField { Name = "Sub1Resource" }); // Test decoration. dec.DecorateClass(resource, className, decl, gen, serviceName, decorators); Assert.AreEqual(3, decl.Members.Count); Assert.AreEqual("Sub1Resource", decl.Members[0].Name); Assert.AreEqual("Sub1Res", decl.Members[1].Name); Assert.AreEqual("Sub2Resource", decl.Members[2].Name); }
public void DecorateClassTest() { var dec = new SubresourceClassDecorator(); var resource = new MockResource(); const string className = "TestClass"; var decl = new CodeTypeDeclaration(); const string serviceName = "TestService"; var decorators = new IResourceDecorator[0]; // Create generators. var resourceGen = new ResourceContainerGenerator(new IResourceContainerDecorator[0]); var requestGen = new RequestClassGenerator(new IRequestDecorator[0]); var gen = new ResourceClassGenerator( resource, serviceName, decorators, requestGen, resourceGen, new string[0]); // Add subresources. resource.Resources.Add("Sub1", new MockResource { Name = "Sub1" }); resource.Resources.Add("Sub2", new MockResource { Name = "Sub2" }); // Test decoration. dec.DecorateClass(resource, className, decl, gen, serviceName, decorators); Assert.AreEqual(2, decl.Members.Count); Assert.IsInstanceOf<CodeTypeDeclaration>(decl.Members[0]); Assert.IsInstanceOf<CodeTypeDeclaration>(decl.Members[1]); }
public void DecorateClassValidationTest() { var dec = new SubresourceClassDecorator(); var resource = new MockResource(); const string className = "TestClass"; var decl = new CodeTypeDeclaration(); const string serviceName = "TestService"; IEnumerable<IResourceDecorator> decorators = GoogleServiceGenerator.GetSchemaAwareResourceDecorators("Generated.Data."); // Create generators. var resourceGen = new ResourceContainerGenerator( GoogleServiceGenerator.StandardResourceContainerDecorator); var requestGen = new RequestClassGenerator(new IRequestDecorator[0]); var gen = new ResourceClassGenerator( resource, serviceName, decorators, requestGen, resourceGen, new string[0]); // Validate method: Assert.Throws<ArgumentNullException>( () => dec.DecorateClass(null, className, decl, gen, serviceName, decorators)); Assert.Throws<ArgumentNullException>( () => dec.DecorateClass(resource, null, decl, gen, serviceName, decorators)); Assert.Throws<ArgumentNullException>( () => dec.DecorateClass(resource, className, null, gen, serviceName, decorators)); Assert.Throws<ArgumentNullException>( () => dec.DecorateClass(resource, className, decl, null, serviceName, decorators)); Assert.Throws<ArgumentNullException>( () => dec.DecorateClass(resource, className, decl, gen, null, decorators)); Assert.Throws<ArgumentNullException>( () => dec.DecorateClass(resource, className, decl, gen, serviceName, null)); // Test normal use case. dec.DecorateClass(resource, className, decl, gen, serviceName, decorators); }