Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1214)

Side by Side Diff: GoogleApis.Tools.CodeGen.IntegrationTests/CodegenTest.cs

Issue 12020043: Issue 325 - Remove discovery and codegen (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: Sir miceli comment Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 Copyright 2011 Google Inc
3
4 Licensed under the Apache License, Version 2.0 (the ""License"");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an ""AS IS"" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18 using System;
19 using System.CodeDom;
20 using System.Reflection;
21 using Google.Apis.Discovery;
22 using NUnit.Framework;
23
24 namespace Google.Apis.Tools.CodeGen.IntegrationTests
25 {
26 /// <summary>
27 /// Integration test for the CodeGenerator.
28 /// Tests whether certain services can be generated. Tests special use-cases .
29 ///·
30 /// Tests:
31 /// - The CodeGenerator project.
32 /// - The Integration of the CodeGenerator with the CoreLibrary.
33 /// </summary>
34 [TestFixture]
35 public class CodegenTest : BaseIntegrationTest
36 {
37 /// <summary>
38 /// Generates and compiles a service from its json discovery document.
39 /// </summary>
40 /// <param name="discoveryJson">The discovery document of this service.< /param>
41 /// <returns>Compiled codegen service.</returns>
42 private static Assembly GenerateService(string discoveryJson)
43 {
44 IService service = GetService(discoveryJson);
45 CodeCompileUnit code = CodegenService(service);
46 return CompileCodeUnit(CSharp, code);
47 }
48
49 /// <summary>
50 /// Tests the CodeGenerator with a service which has no schemas declared .
51 /// </summary>
52 [Test]
53 public void NoSchemaServiceTest()
54 {
55 const string JSON =
56 @"{
57 ""kind"": ""discovery#restDescription"",
58 ""id"": ""testService:v1"",
59 ""name"": ""testService"",
60 ""version"": ""v1"",
61 ""description"": ""A test service"",
62 ""protocol"": ""rest"",
63 ""rootUrl"": ""https://example.com/"",
64 ""basePath"": ""/basePath/"",
65 ""resources"": {
66 ""myclass"": {
67 ""methods"": {
68 ""get"": {
69 ""id"": ""myclass.get"",
70 ""path"": ""get/{id}"",
71 ""httpMethod"": ""GET"",
72 ""parameters"": {
73 ""id"": {
74 ""type"": ""string"",
75 ""required"": true,
76 ""location"": ""path""
77 }
78 }
79 }
80 }
81 }
82 }
83 }";
84
85 // Generate this service.
86 Assembly generatedAssembly = GenerateService(JSON);
87 Assert.IsNotNull(generatedAssembly);
88 }
89
90 /// <summary>
91 /// Tests the CodeGenerator with a service providing a simple schema.
92 /// </summary>
93 [Test]
94 public void SimpleSchemaServiceTest()
95 {
96 const string JSON =
97 @"{
98 ""kind"": ""discovery#restDescription"",
99 ""id"": ""testService:v1"",
100 ""name"": ""testService"",
101 ""version"": ""v1"",
102 ""description"": ""A test service"",
103 ""protocol"": ""rest"",
104 ""rootUrl"": ""https://example.com/"",
105 ""basePath"": ""/basePath/"",
106 ""schemas"": {
107 ""TestSchema"": {
108 ""id"": ""TestSchema"",
109 ""type"": ""object"",
110 ""properties"": {
111 ""id"": {
112 ""type"": ""string"",
113 ""description"": ""The ID of this test.""
114 }
115 }
116 }
117 },
118 ""resources"": {
119 ""myclass"": {
120 ""methods"": {
121 ""get"": {
122 ""id"": ""myclass.get"",
123 ""path"": ""get/{id}"",
124 ""httpMethod"": ""GET"",
125 ""parameters"": {
126 ""id"": {
127 ""type"": ""string"",
128 ""required"": true,
129 ""location"": ""path""
130 }
131 }
132 }
133 }
134 }
135 }
136 }";
137
138 // Generate this service.
139 Assembly generatedAssembly = GenerateService(JSON);
140 Assert.IsNotNull(generatedAssembly);
141 }
142
143 /// <summary>
144 /// Tests the CodeGenerator with a service which has methods declared on the service itsef.
145 /// </summary>
146 [Test]
147 public void MethodOnServiceTest()
148 {
149 const string JSON =
150 @"{
151 ""kind"": ""discovery#restDescription"",
152 ""id"": ""test:v1"",
153 ""name"": ""test"",
154 ""version"": ""v1"",
155 ""description"": ""A test service"",
156 ""protocol"": ""rest"",
157 ""rootUrl"": ""https://example.com"",
158 ""basePath"": ""/basePath/"",
159 ""schemas"": { },
160 ""methods"": {
161 ""doTest"": {
162 ""id"": ""doTest"",
163 ""path"": ""get/{id}"",
164 ""httpMethod"": ""GET"",
165 ""parameters"": {
166 ""id"": {
167 ""type"": ""string"",
168 ""required"": true,
169 ""location"": ""path""
170 }
171 }
172 }
173 },
174 ""resources"": {
175 ""myclass"": {
176 ""methods"": {
177 ""get"": {
178 ""id"": ""myclass.get"",
179 ""path"": ""get/{id}"",
180 ""httpMethod"": ""GET"",
181 ""parameters"": {
182 ""id"": {
183 ""type"": ""string"",
184 ""required"": true,
185 ""location"": ""path""
186 }
187 }
188 }
189 }
190 }
191 }
192 }";
193
194 // Generate this service.
195 Assembly result = GenerateService(JSON);
196 Type serviceClass = result.GetType("Generated.TestService");
197 Assert.IsNotNull(serviceClass, "TestService class not found.");
198 Assert.IsNotNull(serviceClass.GetMethod("DoTest"), "DoTest(..) metho d not found on service.");
199 Assert.IsNotNull(serviceClass.GetMember("DoTestRequest"), "DoTestReq uest class not found on service.");
200 }
201 }
202 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b