Clover.NET coverage report - Coverage for s2container.net

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

File Stats: LOC: 221   Methods: 18
NCLOC: 177 Classes: 9
 
Source File Conditionals Statements Methods TOTAL
Seasar.Tests.Framework.Container\Assembler\AutoConstructorAssemblerTest.cs - 95.3% 88.9% 93.9%
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 NUnit.Framework;
21   using Seasar.Framework.Aop;
22   using Seasar.Framework.Aop.Interceptors;
23   using Seasar.Framework.Container;
24   using Seasar.Framework.Container.Assembler;
25   using Seasar.Framework.Container.Impl;
26   using Seasar.Framework.Exceptions;
27  
28   namespace Seasar.Tests.Framework.Container.Assembler
29   {
30   /// <summary>
31   /// AutoConstructorAssemblerTest の概要の説明です。
32   /// </summary>
33   [TestFixture]
34   public class AutoConstructorAssemblerTest
35   {
36 1 [Test]
37   public void TestAssemble()
38   {
39 1 IS2Container container = new S2ContainerImpl();
40 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
41 1 container.Register(cd);
42 1 container.Register(typeof(B));
43 1 IConstructorAssembler assembler = new AutoConstructorAssembler(cd);
44 1 A a = (A) assembler.Assemble();
45 1 Assert.AreEqual("B", a.HogeName);
46   }
47  
48 1 [Test]
49   public void TestAssembleAspect()
50   {
51 1 IS2Container container = new S2ContainerImpl();
52 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
53 1 cd.AddAspeceDef(new AspectDefImpl(new TraceInterceptor()));
54 1 container.Register(cd);
55 1 container.Register(typeof(B));
56 1 IConstructorAssembler assembler = new AutoConstructorAssembler(cd);
57 1 A a = (A) assembler.Assemble();
58 1 Assert.AreEqual("B", a.HogeName);
59   }
60  
61 1 [Test]
62   public void TestAssembleArgNotFound()
63   {
64 1 IS2Container container = new S2ContainerImpl();
65 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
66 1 container.Register(cd);
67 1 IConstructorAssembler assembler = new AutoConstructorAssembler(cd);
68 1 A a = (A) assembler.Assemble();
69 1 Assert.AreEqual(null,a.Hoge);
70   }
71  
72 1 [Test]
73   public void TestAssembleDefaultConstructor()
74   {
75 1 IS2Container container = new S2ContainerImpl();
76 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(D));
77 1 container.Register(cd);
78 1 IConstructorAssembler assembler = new AutoConstructorAssembler(cd);
79 1 D d = (D) assembler.Assemble();
80 1 Assert.AreEqual("", d.Name);
81   }
82  
83 1 [Test]
84   public void TestAssembleDefaultConstructor2()
85   {
86 1 IS2Container container = new S2ContainerImpl();
87 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(Hoge));
88 1 cd.AddAspeceDef(new AspectDefImpl(new HogeInterceptor()));
89 1 container.Register(cd);
90 1 IConstructorAssembler assembler = new AutoConstructorAssembler(cd);
91 1 Hoge hoge = (Hoge) assembler.Assemble();
92 1 Assert.AreEqual("hoge",hoge.Name);
93   }
94  
95 1 [Test]
96   public void TestAssembleAutoNotInterfaceConstructor()
97   {
98 1 IS2Container container = new S2ContainerImpl();
99 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(C));
100 1 container.Register(cd);
101 1 IConstructorAssembler assembler = new AutoConstructorAssembler(cd);
102 1 try
103   {
104 1 assembler.Assemble();
105 0 Assert.Fail();
106   }
107   catch(NoSuchConstructorRuntimeException ex)
108   {
109 1 Console.Error.WriteLine(ex);
110   }
111   }
112  
113 1 [Test]
114   public void TestAccessComponentDef()
115   {
116 1 IS2Container container = new S2ContainerImpl();
117 1 ComponentDefImpl cd = new ComponentDefImpl(typeof(Hoge));
118 1 ComponentDefInterceptor interceptor = new ComponentDefInterceptor();
119 1 cd.AddAspeceDef(new AspectDefImpl(interceptor));
120 1 container.Register(cd);
121 1 IConstructorAssembler assembler = new AutoConstructorAssembler(cd);
122 1 Hoge hoge = (Hoge) assembler.Assemble();
123 1 Assert.AreEqual("hoge",hoge.Name);
124 1 Assert.AreSame(cd,interceptor.ComponentDef);
125   }
126  
127   public interface Foo
128   {
129   String HogeName { get; }
130   }
131  
132   public class A :MarshalByRefObject, Foo
133   {
134   private Hoge hoge_;
135 3 public A(Hoge hoge)
136   {
137 3 hoge_ = hoge;
138   }
139  
140   public Hoge Hoge
141   {
142 1 get { return hoge_; }
143   }
144  
145   public string HogeName
146   {
147 2 get { return hoge_.Name; }
148   }
149   }
150  
151   public interface Hoge
152   {
153  
154   string Name { get; }
155   }
156  
157   public class B : Hoge
158   {
159   public string Name
160   {
161 2 get { return "B"; }
162   }
163   }
164  
165   public class C
166   {
167  
168   private string name_;
169  
170 0 public C(string name)
171   {
172   name_ = name;
173   }
174  
175 0 public String Name
176   {
177   get { return name_; }
178   }
179   }
180  
181   public class D : MarshalByRefObject
182   {
183   private string name_;
184 1 public D()
185   {
186 1 name_ = "";
187   }
188  
189   public string Name
190   {
191 1 get { return name_; }
192   }
193   }
194  
195   public class HogeInterceptor : IMethodInterceptor
196   {
197 1 public object Invoke(IMethodInvocation invocation)
198   {
199 1 return "hoge";
200   }
201   }
202  
203   public class ComponentDefInterceptor : IMethodInterceptor
204   {
205   private IComponentDef componentDef_;
206  
207   public IComponentDef ComponentDef
208   {
209 1 get { return componentDef_; }
210   }
211  
212 1 public Object Invoke(IMethodInvocation invocation)
213   {
214 1 IS2MethodInvocation impl = (IS2MethodInvocation) invocation;
215 1 componentDef_ = (IComponentDef) impl.GetParameter(ContainerConstants.COMPONENT_DEF_NAME);
216 1 return "hoge";
217   }
218   }
219   }
220   }
221