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

Side by Side Diff: Src/GoogleApis.Tools.CodeGen.Tests/Decorator/ServiceDecorator/StandardConstructServiceDecoratorTest.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 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
19 using NUnit.Framework;
20
21 using Google.Apis.Discovery;
22 using Google.Apis.Authentication;
23 using Google.Apis.Tools.CodeGen.Decorator.ServiceDecorator;
24 using Google.Apis.Tools.CodeGen.Generator;
25 using Google.Apis.Services;
26
27 namespace Google.Apis.Tools.CodeGen.Tests.Decorator.ServiceDecorator
28 {
29 /// <summary> Tests for the StandardConstructServiceDecorator class. </summa ry>
30 [TestFixture]
31 public class StandardConstructServiceDecoratorTest : BaseServiceDecoratorTes t
32 {
33 /// <summary>
34 /// Tests if resource assignments can be added
35 /// </summary>
36 [Test]
37 public void TestAddResourceAssignments()
38 {
39 CodeMemberMethod method = new CodeMemberMethod();
40 method.Name = "TestMethod";
41 var decorator = new StandardConstructServiceDecorator();
42
43 var service = CreateBuzzService();
44 decorator.AddResourceAssignments(service, method);
45
46 Assert.AreEqual(7, method.Statements.Count);
47 foreach (var statment in method.Statements)
48 {
49 Assert.IsInstanceOf(typeof(CodeAssignStatement), statment);
50 var assign = (CodeAssignStatement)statment;
51 Assert.IsNotNull(assign.Left);
52 Assert.IsNotNull(assign.Right);
53 Assert.IsInstanceOf(typeof(CodeFieldReferenceExpression), assign .Left);
54 Assert.IsInstanceOf(typeof(CodeObjectCreateExpression), assign.R ight);
55 }
56 }
57
58 /// <summary>
59 /// Tests if the CreateConstructorWithArgs methods returns the correct r esult
60 /// </summary>
61 [Test]
62 public void TestCreateConstructorWithArgs()
63 {
64 var decorator = new StandardConstructServiceDecorator();
65 IService service = CreateBuzzService();
66 CodeConstructor constructor = decorator.CreateConstructorWithArgs();
67
68 Assert.AreEqual(1, constructor.Parameters.Count);
69 Assert.AreEqual(typeof(BaseClientService.Initializer).FullName, cons tructor.Parameters[0].Type.BaseType);
70 Assert.AreEqual("initializer", constructor.Parameters[0].Name);
71
72 Assert.AreEqual(0, constructor.Statements.Count);
73 }
74
75 /// <summary>
76 /// Tests the class decorator
77 /// </summary>
78 [Test]
79 public void TestDecorateClass()
80 {
81 var codeType = new CodeTypeDeclaration("TestClass");
82 var decorator = new StandardConstructServiceDecorator();
83 var service = CreateBuzzService();
84
85 Assert.AreEqual(0, codeType.Members.Count);
86 decorator.DecorateClass(service, codeType);
87
88 Assert.AreEqual(1, codeType.Members.Count); // We expect one member to be added
89 Assert.IsInstanceOf(typeof(CodeConstructor), codeType.Members[0]);
90 var constructor = (CodeConstructor)codeType.Members[0];
91
92 // Assinging service.Resource.Count statemenets + initParameters()
93 Assert.AreEqual(constructor.Statements.Count, service.Resources.Coun t + 1);
94
95 //We have already tested the statment formation in the other tests.
96 }
97 }
98 }
OLDNEW

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