1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
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
;
31 public class BatchRegistrationFacilityTestCase
33 private IKernel _kernel
;
38 _kernel
= new DefaultKernel();
48 public void UsingAttributes()
53 " <facility id=\"batchregistration\">" +
54 " <assemblyBatch name=\"Castle.Facilities.BatchRegistration.Tests\" useAttributes=\"true\" />" +
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
) ) );
71 public void UsingAttributesWithExcludes()
76 " <facility id=\"batchregistration\">" +
77 " <assemblyBatch name=\"Castle.Facilities.BatchRegistration.Tests\" useAttributes=\"true\" >" +
78 " <exclude type=\"Castle.Facilities.BatchRegistration.Tests.Components.Component2\" />" +
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
) ) );
96 public void Includes()
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>" +
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
) ) );
121 [ExpectedException( typeof(ConfigurationErrorsException
) )]
122 public void InvalidAssemblyName()
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>" +
135 XmlInterpreter interpreter
= new XmlInterpreter( new StaticContentResource(xml
) );
136 interpreter
.ProcessResource( interpreter
.Source
, _kernel
.ConfigurationStore
);
138 _kernel
.AddFacility( "batchregistration", new BatchRegistrationFacility() );
142 public void AddFacilities()
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\" />" +
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
);