Applied patch from Jan Limpens 'ReflectionBasedDictionaryAdapter needs to check if...
[castle.git] / Facilities / BatchRegistration / Castle.Facilities.BatchRegistration.Tests / BatchRegistrationFacilityTestCase.cs
blob46858f5b3010505a1dbdd8837db51d2ee895e53d
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Facilities.BatchRegistration.Tests
17 using System;
18 using System.Configuration;
20 using Castle.Core.Resource;
22 using Castle.MicroKernel;
24 using Castle.Windsor.Configuration.Interpreters;
26 using Castle.Facilities.BatchRegistration.Tests.Components;
28 using NUnit.Framework;
30 [TestFixture]
31 public class BatchRegistrationFacilityTestCase
33 private IKernel _kernel;
35 [SetUp]
36 public void Init()
38 _kernel = new DefaultKernel();
41 [TearDown]
42 public void Finish()
44 _kernel.Dispose();
47 [Test]
48 public void UsingAttributes()
50 String xml =
51 "<configuration>" +
52 " <facilities>" +
53 " <facility id=\"batchregistration\">" +
54 " <assemblyBatch name=\"Castle.Facilities.BatchRegistration.Tests\" useAttributes=\"true\" />" +
55 " </facility>" +
56 " </facilities>" +
57 "</configuration>";
59 XmlInterpreter interpreter = new XmlInterpreter( new StaticContentResource(xml) );
60 interpreter.ProcessResource( interpreter.Source, _kernel.ConfigurationStore);
62 _kernel.AddFacility( "batchregistration", new BatchRegistrationFacility() );
64 Assert.IsTrue( _kernel.HasComponent("comp1") );
65 Assert.IsTrue( _kernel.HasComponent("comp2") );
66 Assert.IsTrue( _kernel.HasComponent( typeof(Component1) ) );
67 Assert.IsTrue( _kernel.HasComponent( typeof(Component2) ) );
70 [Test]
71 public void UsingAttributesWithExcludes()
73 String xml =
74 "<configuration>" +
75 " <facilities>" +
76 " <facility id=\"batchregistration\">" +
77 " <assemblyBatch name=\"Castle.Facilities.BatchRegistration.Tests\" useAttributes=\"true\" >" +
78 " <exclude type=\"Castle.Facilities.BatchRegistration.Tests.Components.Component2\" />" +
79 " </assemblyBatch>" +
80 " </facility>" +
81 " </facilities>" +
82 "</configuration>";
84 XmlInterpreter interpreter = new XmlInterpreter( new StaticContentResource(xml) );
85 interpreter.ProcessResource( interpreter.Source, _kernel.ConfigurationStore);
87 _kernel.AddFacility( "batchregistration", new BatchRegistrationFacility() );
89 Assert.IsTrue( _kernel.HasComponent("comp1") );
90 Assert.IsFalse( _kernel.HasComponent("comp2") );
91 Assert.IsTrue( _kernel.HasComponent( typeof(Component1) ) );
92 Assert.IsFalse( _kernel.HasComponent( typeof(Component2) ) );
95 [Test]
96 public void Includes()
98 String xml =
99 "<configuration>" +
100 " <facilities>" +
101 " <facility id=\"batchregistration\">" +
102 " <assemblyBatch name=\"Castle.Facilities.BatchRegistration.Tests\" useAttributes=\"false\" >" +
103 " <include key=\"other\" component=\"Castle.Facilities.BatchRegistration.Tests.Components.OtherComponent\" />" +
104 " </assemblyBatch>" +
105 " </facility>" +
106 " </facilities>" +
107 "</configuration>";
109 XmlInterpreter interpreter = new XmlInterpreter( new StaticContentResource(xml) );
110 interpreter.ProcessResource( interpreter.Source, _kernel.ConfigurationStore);
112 _kernel.AddFacility( "batchregistration", new BatchRegistrationFacility() );
114 Assert.IsTrue( _kernel.HasComponent("other") );
115 Assert.IsFalse( _kernel.HasComponent("comp2") );
116 Assert.IsTrue( _kernel.HasComponent( typeof(OtherComponent) ) );
117 Assert.IsFalse( _kernel.HasComponent( typeof(Component2) ) );
120 [Test]
121 [ExpectedException( typeof(ConfigurationErrorsException) )]
122 public void InvalidAssemblyName()
124 String xml =
125 "<configuration>" +
126 " <facilities>" +
127 " <facility id=\"batchregistration\">" +
128 " <assemblyBatch name=\"MyCastle.Facilities.BatchRegistration.Tests\" useAttributes=\"false\" >" +
129 " <include key=\"other\" component=\"Castle.Facilities.BatchRegistration.Tests.Components.OtherComponent\" />" +
130 " </assemblyBatch>" +
131 " </facility>" +
132 " </facilities>" +
133 "</configuration>";
135 XmlInterpreter interpreter = new XmlInterpreter( new StaticContentResource(xml) );
136 interpreter.ProcessResource( interpreter.Source, _kernel.ConfigurationStore);
138 _kernel.AddFacility( "batchregistration", new BatchRegistrationFacility() );
141 [Test]
142 public void AddFacilities()
144 String xml =
145 "<configuration>" +
146 " <facilities>" +
147 " <facility id=\"batchregistration\">" +
148 " <addFacility id=\"facility1\" type=\"Castle.Facilities.BatchRegistration.Tests.Facilities.Facility1, Castle.Facilities.BatchRegistration.Tests\" />" +
149 " <addFacility id=\"facility2\" type=\"Castle.Facilities.BatchRegistration.Tests.Facilities.Facility2, Castle.Facilities.BatchRegistration.Tests\" />" +
150 " </facility>" +
151 " </facilities>" +
152 "</configuration>";
154 XmlInterpreter interpreter = new XmlInterpreter( new StaticContentResource(xml) );
155 interpreter.ProcessResource( interpreter.Source, _kernel.ConfigurationStore);
157 _kernel.AddFacility( "batchregistration", new BatchRegistrationFacility() );
159 IFacility[] facilities = _kernel.GetFacilities();
160 Assert.AreEqual( 3, facilities.Length );