Skip to content

Commit

Permalink
Merge pull request #15 from shosca/master
Browse files Browse the repository at this point in the history
Test for WindsorServiceProvider and fix it.
  • Loading branch information
kkozmic committed Oct 19, 2011
2 parents a6bf0e6 + 3afc34f commit 8e2b032
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Castle.Windsor.Tests/Castle.Windsor.Tests.csproj
Expand Up @@ -1096,6 +1096,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Windsor.Tests\XmlConfigStructureTestCase.cs" />
<Compile Include="WindsorServiceProviderTestCase.cs" />
<Compile Include="XmlFiles\Xml.cs" />
<EmbeddedResource Include="XmlFiles\Channel1.xml" />
<EmbeddedResource Include="Config\OneComponentInTwoPieces.xml">
Expand Down
45 changes: 45 additions & 0 deletions src/Castle.Windsor.Tests/WindsorServiceProviderTestCase.cs
@@ -0,0 +1,45 @@
// Copyright 2004-2011 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace CastleTests
{
using Castle.MicroKernel.Handlers;
using Castle.MicroKernel.Registration;
using Castle.Windsor;

using CastleTests.Components;

using NUnit.Framework;

[TestFixture]
public class WindsorServiceProviderTextCase : AbstractContainerTestCase
{
[Test]
public void Can_windsor_service_provider_resolve_services()
{
Container.Register(Component.For<IEmptyService>().ImplementedBy<EmptyServiceA>());
WindsorServiceProvider provider = new WindsorServiceProvider(Container);
IEmptyService service = provider.GetService<IEmptyService>();
Assert.IsNotNull(service);
}

[Test]
public void Can_windsor_service_provider_return_null_when_service_not_found()
{
WindsorServiceProvider provider = new WindsorServiceProvider(Container);
IEmptyService service = provider.GetService<IEmptyService>();
Assert.IsNull(service);
}
}
}
2 changes: 1 addition & 1 deletion src/Castle.Windsor/Windsor/WindsorServiceProvider.cs
Expand Up @@ -43,7 +43,7 @@ public IKernel Kernel

public object GetService(Type serviceType)
{
if (kernel.LoadHandlerByType(null, serviceType, null) == null)
if (kernel.LoadHandlerByType(null, serviceType, null) != null)
{
return kernel.Resolve(serviceType);
}
Expand Down

0 comments on commit 8e2b032

Please sign in to comment.