Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET MVC: Finding the controller should be made in a case insensitive way #480

Merged
merged 3 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Castle Windsor Changelog

## Unreleased

Bugfixes:
- Finding the controller should be made in a case insensitive way for Castle.Facilities.AspNet.Mvc facility (@yitzchok, #480)

## 5.0.0 (2019-02-12)

Bugfixes:
Expand Down
68 changes: 68 additions & 0 deletions src/Castle.Facilities.AspNet.Mvc.Tests/ControllerFinderTestCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2004-2017 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 Castle.Facilities.AspNet.Mvc.Tests
{
using System.Web.Mvc;
using System.Web.Routing;

using Castle.Facilities.AspNet.Mvc;
using Castle.MicroKernel.Lifestyle;
using Castle.MicroKernel.Registration;
using Castle.Windsor;

using NUnit.Framework;

[TestFixture]
public class ControllerFinderTestCase
{
private AspNetMvcFacility facility = null;
private WindsorContainer container;

[SetUp]
public void SetUp()
{
container = new WindsorContainer();

container.AddFacility<AspNetMvcFacility>(x =>
{
facility = x;
x.AddControllerAssembly<MvcTestController>();
});
}

[TestCase("MvcTest")]
[TestCase("mvctest")]
[TestCase("Mvctest")]
[TestCase("MVCtest")]
public void Should_find_controller_by_name_ignoring_case(string controllerName)
{
container.Register(Component.For<MvcTestController>().LifestyleScoped());

var result = ResolveController(controllerName);

Assert.That(typeof(MvcTestController), Is.EqualTo(result.GetType()));
}

private IController ResolveController(string controllerName)
{
using (container.BeginScope())
return facility.ControllerFactory.CreateController(new RequestContext(), controllerName);
}

public class MvcTestController : Controller
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public class AspNetMvcControllerFactory : IControllerFactory
private readonly IKernel kernel;
private bool autoCreateLifestyleScopes;
private SessionStateBehavior sessionStateBehaviour;
private IEnumerable<Type> controllerCandidateTypes;
private IEnumerable<Type> controllerCandidateTypes;

public event Action<IKernel, Type> BeforeControllerResolved;
public event Action<IKernel, Type> BeforeControllerResolved;
public event Action<IKernel, object> AfterControllerReleased;

public AspNetMvcControllerFactory(IKernel kernel, bool autoCreateLifestyleScopes, SessionStateBehavior sessionStateBehaviour, List<Assembly> controllerAssemblies)
Expand Down Expand Up @@ -100,7 +100,7 @@ private Type FindControllerType(string controllerName)
{
foreach (var type in this.controllerCandidateTypes)
{
if (type.Name == controllerName)
if (type.Name.Equals(controllerName, StringComparison.OrdinalIgnoreCase))
{
return type;
}
Expand All @@ -125,7 +125,5 @@ private void DisposeScopedLifestyleIfRequired()
HttpContext.Current.Items.Remove(ContextScopeKey);
}
}


}
}