Clover.NET coverage report - Coverage for s2container.net

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

File Stats: LOC: 249   Methods: 17
NCLOC: 198 Classes: 11
 
Source File Conditionals Statements Methods TOTAL
Seasar.Tests.Framework.Container\Deployer\PrototypeComponentDeployerTest.cs - 98.8% 100.0% 99.0%
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.Aop;
23   using Seasar.Framework.Container;
24   using Seasar.Framework.Container.Deployer;
25   using Seasar.Framework.Container.Impl;
26  
27   namespace Seasar.Tests.Framework.Container.Deployer
28   {
29   /// <summary>
30   /// PrototypeComponentDeployerTest の概要の説明です。
31   /// </summary>
32   [TestFixture]
33   public class PrototypeComponentDeployerTest
34   {
35 1 [Test]
36   public void TestDeployAutoAutoConstructor()
37   {
38 1 IS2Container container = new S2ContainerImpl();
39 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
40 1 container.Register(cd);
41 1 container.Register(typeof(B));
42 1 IComponentDeployer deployer = new PrototypeComponentDeployer(cd);
43 1 A a = (A) deployer.Deploy(typeof(A));
44 1 Assert.AreEqual("B", a.HogeName);
45 1 Assert.AreEqual(false, a == deployer.Deploy(typeof(A)));
46   }
47  
48 1 [Test]
49   public void TestCyclicReference()
50   {
51 1 IS2Container container = new S2ContainerImpl();
52 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(A2));
53 1 ComponentDefImpl cd2 = new ComponentDefImpl(typeof(C));
54 1 container.Register(cd);
55 1 container.Register(cd2);
56 1 IComponentDeployer deployer = new PrototypeComponentDeployer(cd);
57 1 IComponentDeployer deployer2 = new PrototypeComponentDeployer(cd2);
58 1 A2 a2 = (A2) deployer.Deploy(typeof(A2));
59 1 C c = (C) deployer2.Deploy(typeof(C));
60 1 Assert.AreEqual("C", a2.HogeName);
61 1 Assert.AreEqual("C", c.HogeName);
62   }
63  
64 1 [Test]
65   public void TestInjectDependency()
66   {
67 1 IS2Container container = new S2ContainerImpl();
68 1 ComponentDefImpl cd = new ComponentDefImpl();
69 1 container.Register(cd);
70 1 IComponentDeployer deployer = new PrototypeComponentDeployer(cd);
71 1 try
72   {
73 1 deployer.InjectDependency(new Hashtable());
74 0 Assert.Fail();
75   }
76   catch(NotSupportedException ex)
77   {
78 1 Console.WriteLine(ex);
79   }
80   }
81  
82 1 [Test]
83   public void TestDeployAspect1()
84   {
85 1 IS2Container container = new S2ContainerImpl();
86 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(CulcImpl1));
87  
88 1 IAspectDef ad = new AspectDefImpl();
89 1 ad.Expression = "plusOne";
90 1 ad.Container = container;
91 1 cd.AddAspeceDef(ad);
92 1 ComponentDefImpl plusOneCd = new ComponentDefImpl(typeof(PlusOneInterceptor), "plusOne");
93 1 container.Register(plusOneCd);
94 1 container.Register(cd);
95  
96 1 IComponentDeployer deployer = new PrototypeComponentDeployer(cd);
97 1 ICulc culc = (ICulc) deployer.Deploy(typeof(ICulc));
98 1 PlusOneInterceptor.Count = 0;
99 1 Assert.AreEqual(1, culc.Count());
100   }
101  
102 1 [Test]
103   public void TestDeployAspect2()
104   {
105 1 IS2Container container = new S2ContainerImpl();
106 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(CulcImpl2));
107  
108 1 IAspectDef ad = new AspectDefImpl();
109 1 ad.Expression = "plusOne";
110 1 ad.Container = container;
111 1 cd.AddAspeceDef(ad);
112 1 ComponentDefImpl plusOneCd = new ComponentDefImpl(typeof(PlusOneInterceptor), "plusOne");
113 1 container.Register(plusOneCd);
114 1 container.Register(cd);
115  
116 1 IComponentDeployer deployer = new PrototypeComponentDeployer(cd);
117 1 CulcImpl2 culc = (CulcImpl2) deployer.Deploy(typeof(CulcImpl2));
118 1 PlusOneInterceptor.Count = 0;
119 1 Assert.AreEqual(1, culc.Count());
120   }
121  
122 1 [Test]
123   public void TestDeployAspect3()
124   {
125 1 IS2Container container = new S2ContainerImpl();
126 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(CulcImpl2));
127  
128 1 IAspectDef ad = new AspectDefImpl();
129 1 ad.Expression = "plusOne";
130 1 ad.Container = container;
131  
132 1 IAspectDef ad2 = new AspectDefImpl();
133 1 ad2.Expression = "plusOne";
134 1 ad2.Container = container;
135  
136 1 cd.AddAspeceDef(ad);
137 1 cd.AddAspeceDef(ad2);
138 1 ComponentDefImpl plusOneCd = new ComponentDefImpl(typeof(PlusOneInterceptor), "plusOne");
139 1 container.Register(plusOneCd);
140 1 container.Register(cd);
141  
142 1 IComponentDeployer deployer = new PrototypeComponentDeployer(cd);
143 1 CulcImpl2 culc = (CulcImpl2) deployer.Deploy(typeof(CulcImpl2));
144 1 PlusOneInterceptor.Count = 0;
145 1 Assert.AreEqual(2, culc.Count());
146   }
147  
148   public class PlusOneInterceptor : IMethodInterceptor
149   {
150   public static int Count = 0;
151 4 public object Invoke(IMethodInvocation invocation)
152   {
153 4 ++Count;
154 4 invocation.Proceed();
155 4 return Count;
156   }
157   }
158  
159   public interface ICulc
160   {
161   int Count();
162   }
163  
164   public class CulcImpl1 : ICulc
165   {
166 1 public int Count()
167   {
168 1 return 0;
169   }
170   }
171  
172   public class CulcImpl2 : MarshalByRefObject, ICulc
173   {
174 2 public int Count()
175   {
176 2 return 0;
177   }
178   }
179  
180   public interface IFoo
181   {
182   string HogeName { get; }
183   }
184  
185   public class A
186   {
187   private IHoge hoge_;
188  
189 2 public A(IHoge hoge)
190   {
191 2 hoge_ = hoge;
192   }
193  
194   public string HogeName
195   {
196 1 get { return hoge_.Name; }
197   }
198   }
199  
200   public class A2 : IFoo
201   {
202   private IHoge hoge_;
203  
204   public IHoge Hoge
205   {
206 2 set { hoge_ = value; }
207   }
208  
209   public string HogeName
210   {
211 2 get { return hoge_.Name; }
212   }
213   }
214  
215   public interface IHoge
216   {
217   string Name { get; }
218   }
219  
220   public class B : IHoge
221   {
222   public string Name
223   {
224 1 get { return "B"; }
225   }
226   }
227  
228   public class C : IHoge
229   {
230   private IFoo foo_;
231  
232   public IFoo Foo
233   {
234 2 set { foo_ = value; }
235   }
236  
237   public string Name
238   {
239 2 get { return "C"; }
240   }
241  
242   public string HogeName
243   {
244 1 get { return foo_.HogeName; }
245   }
246   }
247   }
248   }
249