From bbf856746f61c5ccbdd15898b1e565286e68107c Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Thu, 9 Aug 2012 11:46:24 -0700 Subject: [PATCH] Fixing unit tests --HG-- branch : 1.x --- .../Environment/DefaultOrchardHostTests.cs | 2 ++ .../ShellBuilders/DefaultShellContainerFactoryTests.cs | 4 +++- src/Orchard.Tests/Orchard.Framework.Tests.csproj | 4 ++++ .../Storage/FileSystemStorageProviderTests.cs | 10 +++++++++- src/Orchard/Mvc/Routes/RoutePublisher.cs | 1 - src/Orchard/Mvc/Routes/ShellRoute.cs | 7 ++++++- .../DefaultOrchardWebApiHttpControllerSelector.cs | 4 ++-- 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs b/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs index d54a3fe46..f0d82221e 100644 --- a/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs +++ b/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs @@ -22,6 +22,7 @@ using Orchard.Mvc.Routes; using Orchard.Tests.Environment.TestDependencies; using Orchard.Tests.Stubs; using Orchard.Tests.Utility; +using Orchard.WebApi.Routes; using IModelBinderProvider = Orchard.Mvc.ModelBinders.IModelBinderProvider; namespace Orchard.Tests.Environment { @@ -60,6 +61,7 @@ namespace Orchard.Tests.Environment { builder.RegisterAutoMocking() .Ignore() .Ignore() + .Ignore() .Ignore(); }); _lifetime = _container.BeginLifetimeScope(); diff --git a/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContainerFactoryTests.cs b/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContainerFactoryTests.cs index a3ba85c61..a07abe09c 100644 --- a/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContainerFactoryTests.cs +++ b/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContainerFactoryTests.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Web.Http.Controllers; using System.Web.Mvc; using Autofac; using Autofac.Core; @@ -36,7 +37,8 @@ namespace Orchard.Tests.Environment.ShellBuilders { ShellBlueprint CreateBlueprint(params ShellBlueprintItem[] items) { return new ShellBlueprint { Dependencies = items.OfType(), - Controllers = items.OfType(), + Controllers = items.OfType().Where(bp => typeof(IController).IsAssignableFrom(bp.Type)), + HttpControllers = items.OfType().Where(bp => typeof(IHttpController).IsAssignableFrom(bp.Type)), Records = items.OfType(), }; } diff --git a/src/Orchard.Tests/Orchard.Framework.Tests.csproj b/src/Orchard.Tests/Orchard.Framework.Tests.csproj index 466f7619a..d622771af 100644 --- a/src/Orchard.Tests/Orchard.Framework.Tests.csproj +++ b/src/Orchard.Tests/Orchard.Framework.Tests.csproj @@ -106,6 +106,9 @@ False ..\..\lib\moq\Moq.dll + + ..\..\lib\newtonsoft.json\Newtonsoft.Json.dll + False ..\..\lib\nhibernate\NHibernate.dll @@ -134,6 +137,7 @@ 3.5 + False ..\..\lib\aspnetmvc\System.Web.Mvc.dll diff --git a/src/Orchard.Tests/Storage/FileSystemStorageProviderTests.cs b/src/Orchard.Tests/Storage/FileSystemStorageProviderTests.cs index f153c7909..6a5a46f2b 100644 --- a/src/Orchard.Tests/Storage/FileSystemStorageProviderTests.cs +++ b/src/Orchard.Tests/Storage/FileSystemStorageProviderTests.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; using NUnit.Framework; using System; using Orchard.Environment; @@ -41,7 +42,14 @@ namespace Orchard.Tests.Storage { [TearDown] public void Term() { - Directory.Delete(_folderPath, true); + try { + Directory.Delete(_folderPath, true); + } + catch (IOException) { + // if a system handle is still active give some time to release it + Thread.Sleep(0); + Directory.Delete(_folderPath, true); + } } diff --git a/src/Orchard/Mvc/Routes/RoutePublisher.cs b/src/Orchard/Mvc/Routes/RoutePublisher.cs index 59614b628..11b591787 100644 --- a/src/Orchard/Mvc/Routes/RoutePublisher.cs +++ b/src/Orchard/Mvc/Routes/RoutePublisher.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using System.ServiceModel.Activation; using System.Web.Routing; using Orchard.Environment; using Orchard.Environment.Configuration; diff --git a/src/Orchard/Mvc/Routes/ShellRoute.cs b/src/Orchard/Mvc/Routes/ShellRoute.cs index 347b59924..cae2f49ce 100644 --- a/src/Orchard/Mvc/Routes/ShellRoute.cs +++ b/src/Orchard/Mvc/Routes/ShellRoute.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Web; +using System.Web.Http.WebHost.Routing; using System.Web.Mvc; using System.Web.Routing; using System.Web.SessionState; @@ -49,8 +50,12 @@ namespace Orchard.Mvc.Routes { // otherwise wrap handler and return it routeData.RouteHandler = new RouteHandler(_workContextAccessor, routeData.RouteHandler); - routeData.Values["IWorkContextAccessor"] = _workContextAccessor; // for WebApi routeData.DataTokens["IWorkContextAccessor"] = _workContextAccessor; + + if (_route is HttpWebRoute) { + routeData.Values["IWorkContextAccessor"] = _workContextAccessor; // for WebApi + } + return routeData; } diff --git a/src/Orchard/WebApi/DefaultOrchardWebApiHttpControllerSelector.cs b/src/Orchard/WebApi/DefaultOrchardWebApiHttpControllerSelector.cs index 78a00c28f..2e30e3b1d 100644 --- a/src/Orchard/WebApi/DefaultOrchardWebApiHttpControllerSelector.cs +++ b/src/Orchard/WebApi/DefaultOrchardWebApiHttpControllerSelector.cs @@ -49,8 +49,8 @@ namespace Orchard.WebApi { // Service name pattern matches the identification strategy var serviceKey = (areaName + "/" + controllerName).ToLowerInvariant(); - HttpControllerContext controllerContext = new HttpControllerContext(_configuration, routeData, request); - + var controllerContext = new HttpControllerContext(_configuration, routeData, request); + // Now that the request container is known - try to resolve the controller information Meta> info; var workContext = controllerContext.GetWorkContext();