Clover.NET coverage report - Coverage for s2container.net

Coverage timestamp: 2006年5月30日 11:21:29

File Stats: LOC: 202   Methods: 14
NCLOC: 161 Classes: 5
 
Source File Conditionals Statements Methods TOTAL
Seasar.Tests.Framework.Container\Assembler\DefaultInitMethodAssemblerTest.cs - 91.4% 57.1% 85.7%
coverage coverage
1   #region Copyright
2   /*
3   * Copyright 2005 the Seasar Foundation and the Others.
4   *
5   * Licensed under the Apache License, Version 2.0 (the "License");
6   * you may not use this file except in compliance with the License.
7   * You may obtain a copy of the License at
8   *
9   * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14   * either express or implied. See the License for the specific language
15   * governing permissions and limitations under the License.
16   */
17   #endregion
18  
19   using System;
20   using System.Collections;
21   using NUnit.Framework;
22   using Seasar.Framework.Beans;
23   using Seasar.Framework.Container;
24   using Seasar.Framework.Container.Assembler;
25   using Seasar.Framework.Container.Impl;
26  
27   namespace Seasar.Tests.Framework.Container.Assembler
28   {
29   /// <summary>
30   /// DefaultInitMethodAssemblerTest の概要の説明です。
31   /// </summary>
32   [TestFixture]
33   public class DefaultInitMethodAssemblerTest
34   {
35 1 [Test]
36   public void TestAssemble()
37   {
38 1 IS2Container container = new S2ContainerImpl();
39 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(Hashtable));
40 1 IInitMethodDef md = new InitMethodDefImpl("Add");
41 1 IArgDef argDef = new ArgDefImpl("aaa");
42 1 md.AddArgDef(argDef);
43 1 IArgDef argDef2 = new ArgDefImpl("111");
44 1 md.AddArgDef(argDef2);
45 1 cd.AddInitMethodDef(md);
46 1 container.Register(cd);
47 1 IMethodAssembler assembler = new DefaultInitMethodAssembler(cd);
48 1 Hashtable table = new Hashtable();
49 1 assembler.Assemble(table);
50 1 Assert.AreEqual("111",table["aaa"]);
51   }
52  
53 1 [Test]
54   public void TestAssembleForExpression()
55   {
56 1 IS2Container container = new S2ContainerImpl();
57 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(Hashtable));
58 1 IInitMethodDef md = new InitMethodDefImpl();
59 1 md.Expression = "self.Add('aaa','111')";
60 1 cd.AddInitMethodDef(md);
61 1 container.Register(cd);
62 1 IMethodAssembler assembler = new DefaultInitMethodAssembler(cd);
63 1 Hashtable table = new Hashtable();
64 1 assembler.Assemble(table);
65 1 Assert.AreEqual("111",table["aaa"]);
66   }
67  
68 1 [Test]
69   public void TestAssembleForAuto()
70   {
71 1 IS2Container container = new S2ContainerImpl();
72 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(B));
73 1 IInitMethodDef md = new InitMethodDefImpl("Bbb");
74 1 cd.AddInitMethodDef(md);
75 1 container.Register(cd);
76 1 container.Register(typeof(ArrayList));
77 1 IMethodAssembler assembler = new DefaultInitMethodAssembler(cd);
78 1 B b = new B();
79 1 assembler.Assemble(b);
80 1 Assert.AreEqual(0,b.ValueSize);
81   }
82  
83 1 [Test]
84   public void TestAssembleIllegalArgument()
85   {
86 1 IS2Container container = new S2ContainerImpl();
87 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(Hashtable));
88 1 IInitMethodDef md = new InitMethodDefImpl("Add");
89 1 cd.AddInitMethodDef(md);
90 1 container.Register(cd);
91 1 IMethodAssembler assembler = new DefaultInitMethodAssembler(cd);
92 1 Hashtable table = new Hashtable();
93 1 try
94   {
95 1 assembler.Assemble(table);
96 0 Assert.Fail();
97   }
98   catch(MethodNotFoundRuntimeException ex)
99   {
100 1 Console.WriteLine(ex);
101   }
102   }
103  
104 1 [Test]
105   public void TestAssembleIllegalArgument2()
106   {
107 1 IS2Container container = new S2ContainerImpl();
108 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(B));
109 1 IInitMethodDef md = new InitMethodDefImpl("SetAAA");
110 1 IArgDef argDef = new ArgDefImpl("aaa");
111 1 md.AddArgDef(argDef);
112 1 cd.AddInitMethodDef(md);
113 1 container.Register(cd);
114 1 IMethodAssembler assembler = new DefaultInitMethodAssembler(cd);
115 1 try
116   {
117 1 assembler.Assemble(new B());
118 0 Assert.Fail();
119   }
120   catch(MethodNotFoundRuntimeException ex)
121   {
122 1 Console.WriteLine(ex);
123   }
124   }
125  
126 1 [Test]
127   public void TestAssembleField()
128   {
129 1 IS2Container container = new S2ContainerImpl();
130 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(Int32));
131 1 IInitMethodDef md = new InitMethodDefImpl();
132 1 md.Expression = "out.WriteLine(Int32.MinValue)";
133 1 cd.AddInitMethodDef(md);
134 1 container.Register(cd);
135 1 IMethodAssembler assembler = new DefaultInitMethodAssembler(cd);
136 1 assembler.Assemble(1);
137   }
138  
139   public interface IFoo
140   {
141   string HogeName{ get; }
142   }
143  
144   public class A : IFoo
145   {
146   private IHoge hoge_;
147  
148 0 public A()
149   {
150   }
151  
152 0 public IHoge Hoge
153   {
154   get { return hoge_; }
155   set { hoge_ = value; }
156   }
157  
158 0 public string HogeName
159   {
160   get
161   {
162   return hoge_.Name;
163   }
164   }
165   }
166  
167   public interface IHoge
168   {
169   string Name { get; }
170   }
171  
172   public class B : IHoge
173   {
174   private IList values_;
175  
176 0 public string Name
177   {
178   get
179   {
180   return "B";
181   }
182   }
183  
184 0 public void SetAaa(int aaa)
185   {
186   }
187  
188 1 public void Bbb(IList values)
189   {
190 1 values_ = values;
191   }
192  
193   public int ValueSize
194   {
195 1 get { return values_.Count; }
196   }
197   }
198  
199  
200   }
201   }
202