Clover.NET coverage report - Coverage for s2container.net

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

File Stats: LOC: 255   Methods: 23
NCLOC: 206 Classes: 8
 
Source File Conditionals Statements Methods TOTAL
Seasar.Tests.Framework.Container\Impl\ComponentDefImplTest.cs - 100.0% 100.0% 100.0%
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.IO;
21   using System.Collections;
22   using System.Reflection;
23   using NUnit.Framework;
24   using Seasar.Framework.Aop.Interceptors;
25   using Seasar.Framework.Container;
26   using Seasar.Framework.Container.Impl;
27   using log4net;
28   using log4net.Config;
29   using log4net.Util;
30  
31   namespace Seasar.Tests.Framework.Container.Impl
32   {
33   /// <summary>
34   /// ComponentDefImplTest の概要の説明です。
35   /// </summary>
36   [TestFixture]
37   public class ComponentDefImplTest
38   {
39 10 [SetUp]
40   public void SetUp()
41   {
42 10 FileInfo info = new FileInfo(SystemInfo.AssemblyFileName(
43   Assembly.GetExecutingAssembly()) + ".config");
44 10 XmlConfigurator.Configure(LogManager.GetRepository(), info);
45   }
46  
47 1 [Test]
48   public void TestGetComponentForType3()
49   {
50 1 IS2Container container = new S2ContainerImpl();
51 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
52 1 container.Register(cd);
53 1 container.Register(typeof(B));
54 1 A a = (A) container.GetComponent(typeof(A));
55 1 Assert.AreEqual("B", a.HogeName);
56 1 Assert.AreSame(a, container.GetComponent(typeof(A)));
57   }
58  
59 1 [Test]
60   public void TestGetComponentForType2()
61   {
62 1 IS2Container container = new S2ContainerImpl();
63 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(A2));
64 1 container.Register(cd);
65 1 container.Register(typeof(B));
66 1 A2 a2 = (A2) container.GetComponent(typeof(A2));
67 1 Assert.AreEqual("B", a2.HogeName);
68   }
69  
70 1 [Test]
71   public void TestGetComponentForArgDef()
72   {
73 1 IS2Container container = new S2ContainerImpl();
74 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(Decimal), "num");
75 1 cd.AddArgDef(new ArgDefImpl(123));
76 1 container.Register(cd);
77 1 Assert.AreEqual(new Decimal(123), container.GetComponent("num"));
78   }
79  
80 1 [Test]
81   public void TestGetComponentForPropertyDef()
82   {
83 1 IS2Container container = new S2ContainerImpl();
84 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(A2));
85 1 cd.AddPropertyDef(new PropertyDefImpl("hoge", new B()));
86 1 container.Register(cd);
87 1 A2 a2 = (A2) container.GetComponent(typeof(A2));
88 1 Assert.AreEqual("B", a2.HogeName);
89   }
90  
91 1 [Test]
92   public void TestGetComponentForMethodDef()
93   {
94 1 IS2Container container = new S2ContainerImpl();
95 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(Hashtable), "myTable");
96 1 IInitMethodDef md = new InitMethodDefImpl("Add");
97 1 md.AddArgDef(new ArgDefImpl("aaa"));
98 1 md.AddArgDef(new ArgDefImpl("hoge"));
99 1 cd.AddInitMethodDef(md);
100 1 container.Register(cd);
101 1 Hashtable table = (Hashtable) container.GetComponent("myTable");
102 1 Assert.AreEqual("hoge", table["aaa"]);
103   }
104  
105 1 [Test]
106   public void TestGetComponentForAspectDef()
107   {
108 1 IS2Container container = new S2ContainerImpl();
109 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
110 1 cd.AddAspeceDef(new AspectDefImpl(new TraceInterceptor()));
111 1 container.Register(cd);
112 1 container.Register(typeof(B));
113 1 A a = (A) container.GetComponent(typeof(A));
114 1 Assert.AreEqual("B", a.HogeName);
115   }
116  
117 1 [Test]
118   public void TestGetComponentForExpression()
119   {
120 1 IS2Container container = new S2ContainerImpl();
121 1 container.Register(typeof(Object), "obj");
122 1 ComponentDefImpl cd = new ComponentDefImpl(null, "hash");
123 1 cd.Expression = "container.GetComponent('obj').GetHashCode()";
124 1 container.Register(cd);
125 1 Assert.IsNotNull(container.GetComponent("hash"));
126   }
127  
128 1 [Test]
129   public void TestCyclicReference()
130   {
131 1 IS2Container container = new S2ContainerImpl();
132 1 container.Register(typeof(A2));
133 1 container.Register(typeof(C));
134 1 A2 a2 = (A2) container.GetComponent(typeof(A2));
135 1 C c = (C) container.GetComponent(typeof(C));
136 1 Assert.AreEqual("C", a2.HogeName);
137 1 Assert.AreEqual("C", c.HogeName);
138   }
139  
140 1 [Test]
141   public void TestInit()
142   {
143 1 IComponentDef cd = new ComponentDefImpl(typeof(D));
144 1 cd.AddInitMethodDef(new InitMethodDefImpl("Init"));
145 1 cd.Init();
146 1 D d = (D) cd.GetComponent();
147 1 Assert.AreEqual(true, d.IsInited);
148   }
149  
150 1 [Test]
151   public void TestDestroy()
152   {
153 1 IComponentDef cd = new ComponentDefImpl(typeof(D));
154 1 cd.AddDestroyMethodDef(new DestroyMethodDefImpl("Destroy"));
155 1 D d = (D) cd.GetComponent();
156 1 cd.Destroy();
157 1 Assert.AreEqual(true, d.IsDestroyed);
158   }
159  
160   public interface IFoo
161   {
162   string HogeName { get; }
163   }
164  
165   public class A : MarshalByRefObject
166   {
167   private IHoge hoge_;
168  
169 2 public A(IHoge hoge)
170   {
171 2 hoge_ = hoge;
172   }
173  
174   public string HogeName
175   {
176 2 get { return hoge_.Name; }
177   }
178   }
179  
180   public class A2 : IFoo
181   {
182   private IHoge hoge_;
183  
184   public IHoge Hoge
185   {
186 3 set { hoge_ = value; }
187   }
188  
189   public string HogeName
190   {
191 4 get { return hoge_.Name; }
192   }
193   }
194  
195   public interface IHoge
196   {
197   string Name { get; }
198   }
199  
200   public class B : IHoge
201   {
202   public string Name
203   {
204 4 get { return "B"; }
205   }
206   }
207  
208   public class C : IHoge
209   {
210   private IFoo foo_;
211  
212   public IFoo Foo
213   {
214 1 set { foo_ = value; }
215   }
216  
217   public string Name
218   {
219 2 get { return "C"; }
220   }
221  
222   public string HogeName
223   {
224 1 get { return foo_.HogeName; }
225   }
226   }
227  
228   public class D
229   {
230   private bool inited_ = false;
231   private bool destroyed_ = false;
232  
233   public bool IsInited
234   {
235 1 get { return inited_; }
236   }
237  
238   public bool IsDestroyed
239   {
240 1 get { return destroyed_; }
241   }
242  
243 1 public void Init()
244   {
245 1 inited_ = true;
246   }
247  
248 1 public void Destroy()
249   {
250 1 destroyed_ = true;
251   }
252   }
253   }
254   }
255