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

Side by Side Diff: Src/GoogleApis.Tools.CodeGen.Tests/Decorator/ResourceDecorator/StandardConstructorResourceDecoratorTest.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, 10 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 2010 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 using System.CodeDom;
18 using Google.Apis.Discovery;
19 using NUnit.Framework;
20 using Google.Apis.Tools.CodeGen.Decorator.ResourceDecorator;
21
22 namespace Google.Apis.Tools.CodeGen.Tests.Decorator.ResourceDecorator
23 {
24 /// <summary>
25 /// Tests the StandardConstructorResourceDecorator
26 /// </summary>
27 [TestFixture]
28 public class StandardConstructorResourceDecoratorTest : BaseResourceDecorato rTest
29 {
30 private IResource CreateEmptyResource()
31 {
32 return CreateResourceDiscoveryV_1_0("MockResource", "{ }");
33 }
34
35 private IResource CreateNonEmptyResource()
36 {
37 var resource = CreateResourceDiscoveryV_1_0("MockResource", "{ }");
38 resource.Resources.Add("Subresource", CreateResourceDiscoveryV_1_0(" Subresource", "{ }"));
39 resource.Resources.Add("AnotherSubresource", CreateResourceDiscovery V_1_0("AnotherSubresource", "{ }"));
40 return resource;
41 }
42
43 /// <summary>
44 /// Tests the constructor
45 /// </summary>
46 [Test]
47 public void TestCreateConstructor()
48 {
49 var decorator = new StandardConstructorResourceDecorator();
50 CodeConstructor constructor = decorator.CreateConstructor(ServiceCla ssName, CreateEmptyResource());
51 Assert.AreEqual(2, constructor.Parameters.Count);
52 var param = constructor.Parameters[0];
53 Assert.AreEqual(ServiceClassName, param.Type.BaseType);
54 Assert.AreEqual(2, constructor.Statements.Count);
55 param = constructor.Parameters[1];
56 Assert.AreEqual(typeof(Google.Apis.Authentication.IAuthenticator).Fu llName, param.Type.BaseType);
57 }
58
59
60 /// <summary>
61 /// Tests the constructor
62 /// </summary>
63 [Test]
64 public void TestCreateConstructorWithSubresources()
65 {
66 var decorator = new StandardConstructorResourceDecorator();
67 CodeConstructor constructor = decorator.CreateConstructor(ServiceCla ssName, CreateNonEmptyResource());
68 Assert.AreEqual(4, constructor.Statements.Count);
69 }
70
71 /// <summary>
72 /// Test the decoration functionallity
73 /// </summary>
74 [Test]
75 public void TestDecorateClass()
76 {
77 var decorator = new StandardConstructorResourceDecorator();
78 var resourceClass = new CodeTypeDeclaration(ResourceClassName);
79 var resource = CreateResourceDiscoveryV_1_0(ResourceName, ResourceAs Json);
80 decorator.DecorateClass(resource, null, resourceClass, null, Service ClassName, null);
81
82 Assert.AreEqual(1, resourceClass.Members.Count);
83 var member = resourceClass.Members[0];
84
85 Assert.IsInstanceOf(typeof(CodeConstructor), member);
86 // Constructor is tested in TestCreateConstructor
87 }
88
89 /// <summary>
90 /// Tests the constructor
91 /// </summary>
92 [Test]
93 public void TestCreateSubresourceStatement()
94 {
95 var decorator = new StandardConstructorResourceDecorator();
96 CodeStatementCollection statements = decorator.CreateSubresourceCrea teStatements(CreateNonEmptyResource());
97 Assert.AreEqual(2, statements.Count);
98
99 Assert.That(statements[0], Is.InstanceOf<CodeAssignStatement>());
100 CodeAssignStatement firstStatement = (CodeAssignStatement) statement s[0];
101
102 // Check the field name
103 Assert.That(firstStatement.Left, Is.InstanceOf<CodeFieldReferenceExp ression>());
104 Assert.That(((CodeFieldReferenceExpression)firstStatement.Left).Fiel dName, Is.EqualTo("_Subresource"));
105
106 // Check the constructor
107 var right = firstStatement.Right as CodeObjectCreateExpression;
108 Assert.IsNotNull(right);
109 Assert.That(right.CreateType.BaseType, Is.EqualTo("SubresourceResour ce"));
110 }
111 }
112 }
OLDNEW

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