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); }
/// <summary> /// Generates the CodeCompileUnit for the specified service by using the CodeGenerator. /// </summary> protected static CodeCompileUnit CodegenService(IService service) { // Generate the service. var generator = new GoogleServiceGenerator(service, "Generated"); return(generator.GenerateCode()); }
/// <summary> /// Generates a service from the specified discovery uri. /// </summary> /// <param name="url">The URL or file where the discovery document can be found.</param> public void GenerateService(Uri url) { Console.WriteLine(" Generating: " + url); // Create the output directory if it does not exist yet. if (!Directory.Exists(OutputDir)) { Directory.CreateDirectory(OutputDir); } // Discover the service. Console.WriteLine(" Fetching " + url); IDiscoveryDevice src = url.IsFile ? (IDiscoveryDevice) new StreamDiscoveryDevice { DiscoveryStream = File.Open(url.LocalPath, FileMode.Open, FileAccess.Read) } : new StringDiscoveryDevice { Document = Utils.FetchDocument(url) }; var discovery = new DiscoveryService(src); IService service = discovery.GetService(DiscoveryVersion.Version_1_0); // Generate the formal names based upon the discovery data. string name = service.Name; string version = service.Version; string formalServiceName = GeneratorUtils.UpperFirstLetter(name); string serviceNamespace = GeneratorUtils.GetNamespaceName(formalServiceName); if ((Flags & GeneratorFlags.GoogleService) > 0) // If this is a google service, add the google prefix. { formalServiceName = GooglePrefix + formalServiceName; serviceNamespace = GooglePrefix + serviceNamespace; } string baseFileName = Path.Combine(OutputDir, formalServiceName + "." + version); string fileName = baseFileName + CodeFileExtension; string libfileName = baseFileName + LibraryExtension; serviceNamespace = String.Format("{0}.{1}", serviceNamespace, GeneratorUtils.GetNamespaceName(version)); // Produce the code. var generator = new GoogleServiceGenerator(service, serviceNamespace); CodeCompileUnit generatedCode = generator.GenerateCode(); WriteCodeToFile(generatedCode, fileName); if ((Flags & GeneratorFlags.CompileLibrary) > 0) { CompileIntoLibrary(service, generatedCode, libfileName); } }
private static RequestClassGenerator ConstructRequestGenerator() { var mockService = new Mock <IService>(); mockService .Setup(m => m.Parameters) .Returns(() => null); return(new RequestClassGenerator( GoogleServiceGenerator.GetSchemaAwareRequestDecorators("Generated", mockService.Object))); }
public void TestCompilationWithDefaultDecorators_Buzz() { var clientNamespace = "Google.Apis.Samples.CommandLineGeneratedService.Buzz"; var service = CreateBuzzService(); var generator = new GoogleServiceGenerator(service, clientNamespace); var codeCompileUnit = generator.GenerateCode(); // Full Compile we should not have any warnings. CheckCompile(codeCompileUnit, true, "Failed To compile resultant code with default decorators."); }
public void SystemTestCompilationWithDefaultDecorators_Discovery() { const string serviceName = "discovery"; const string serviceVersion = "v1"; var clientNamespace = "Google.Apis.Samples.CommandLineGeneratedService.Discovery"; // Generate the discovery URL for that service string url = string.Format(GoogleServiceGenerator.GoogleDiscoveryURL, serviceName, serviceVersion); var discovery = new DiscoveryService(new WebDiscoveryDevice(new Uri(url))); // Build the service based on discovery information. var service = discovery.GetService(DiscoveryVersion.Version_1_0); Assert.AreEqual(serviceName, service.Name); Assert.AreEqual(serviceVersion, service.Version); // Generate code var generator = new GoogleServiceGenerator(service, clientNamespace); var codeCompileUnit = generator.GenerateCode(); // Full Compile we should not have any warnings. CheckCompile(codeCompileUnit, true, "Failed To compile resultant code with default decorators."); }