mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#5116: Fixed failing tests.
This commit is contained in:
@@ -273,7 +273,11 @@ namespace Orchard.Tests.Modules.DesignerTools.Services
|
||||
new JProperty("value", "null")),
|
||||
new JObject(
|
||||
new JProperty("name", "TypePartDefinition"),
|
||||
new JProperty("value", "ContentTypePartDefinition")),
|
||||
new JProperty("value", "ContentTypePartDefinition"),
|
||||
new JProperty("children", new JArray(
|
||||
new JObject(
|
||||
new JProperty("name", "ContentTypeDefinition"),
|
||||
new JProperty("value", "null"))))),
|
||||
new JObject(
|
||||
new JProperty("name", "PartDefinition"),
|
||||
new JProperty("value", "ContentPartDefinition"),
|
||||
@@ -349,7 +353,10 @@ namespace Orchard.Tests.Modules.DesignerTools.Services
|
||||
new JProperty("value", "SettingsDictionary"))))),
|
||||
new JObject(
|
||||
new JProperty("name", "Settings"),
|
||||
new JProperty("value", "SettingsDictionary"))))),
|
||||
new JProperty("value", "SettingsDictionary")),
|
||||
new JObject(
|
||||
new JProperty("name", "ContentTypeDefinition"),
|
||||
new JProperty("value", "null"))))),
|
||||
new JObject(
|
||||
new JProperty("name", "PartDefinition"),
|
||||
new JProperty("value", "ContentPartDefinition"),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Autofac;
|
||||
using System;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Mvc;
|
||||
@@ -17,7 +18,7 @@ namespace Orchard.Tests.Modules.Widgets.RuleEngine {
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
_shellSettings = new ShellSettings {RequestUrlPrefix = string.Empty};
|
||||
_shellSettings = new ShellSettings { RequestUrlPrefix = String.Empty };
|
||||
builder.RegisterType<UrlRuleProvider>().As<IRuleProvider>();
|
||||
builder.RegisterInstance(_shellSettings);
|
||||
_stubContextAccessor = new StubHttpContextAccessor();
|
||||
@@ -28,15 +29,15 @@ namespace Orchard.Tests.Modules.Widgets.RuleEngine {
|
||||
|
||||
[Test]
|
||||
public void UrlForHomePageMatchesHomePagePath() {
|
||||
_stubContextAccessor.StubContext = new StubHttpContext("~/");
|
||||
var context = new RuleContext {FunctionName = "url", Arguments = new[] {"~/"}};
|
||||
_stubContextAccessor.Set(new StubHttpContext("~/"));
|
||||
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/" } };
|
||||
_urlRuleProvider.Process(context);
|
||||
Assert.That(context.Result, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UrlForAboutPageMatchesAboutPagePath() {
|
||||
_stubContextAccessor.StubContext = new StubHttpContext("~/about");
|
||||
_stubContextAccessor.Set(new StubHttpContext("~/about"));
|
||||
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/about" } };
|
||||
_urlRuleProvider.Process(context);
|
||||
Assert.That(context.Result, Is.True);
|
||||
@@ -44,7 +45,7 @@ namespace Orchard.Tests.Modules.Widgets.RuleEngine {
|
||||
|
||||
[Test]
|
||||
public void UrlForBlogWithEndingWildcardMatchesBlogPostPageInSaidBlog() {
|
||||
_stubContextAccessor.StubContext = new StubHttpContext("~/my-blog/my-blog-post");
|
||||
_stubContextAccessor.Set(new StubHttpContext("~/my-blog/my-blog-post"));
|
||||
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/my-blog/*" } };
|
||||
_urlRuleProvider.Process(context);
|
||||
Assert.That(context.Result, Is.True);
|
||||
@@ -52,7 +53,7 @@ namespace Orchard.Tests.Modules.Widgets.RuleEngine {
|
||||
|
||||
[Test]
|
||||
public void UrlForHomePageDoesNotMatchAboutPagePath() {
|
||||
_stubContextAccessor.StubContext = new StubHttpContext("~/about");
|
||||
_stubContextAccessor.Set(new StubHttpContext("~/about"));
|
||||
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/" } };
|
||||
_urlRuleProvider.Process(context);
|
||||
Assert.That(context.Result, Is.False);
|
||||
@@ -60,7 +61,7 @@ namespace Orchard.Tests.Modules.Widgets.RuleEngine {
|
||||
|
||||
[Test]
|
||||
public void UrlForAboutPageMatchesDifferentCasedAboutPagePath() {
|
||||
_stubContextAccessor.StubContext = new StubHttpContext("~/About");
|
||||
_stubContextAccessor.Set(new StubHttpContext("~/About"));
|
||||
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/about" } };
|
||||
_urlRuleProvider.Process(context);
|
||||
Assert.That(context.Result, Is.True);
|
||||
@@ -68,7 +69,7 @@ namespace Orchard.Tests.Modules.Widgets.RuleEngine {
|
||||
|
||||
[Test]
|
||||
public void UrlForAboutPageWithEndingSlashMatchesAboutPagePath() {
|
||||
_stubContextAccessor.StubContext = new StubHttpContext("~/About/");
|
||||
_stubContextAccessor.Set(new StubHttpContext("~/About/"));
|
||||
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/about" } };
|
||||
_urlRuleProvider.Process(context);
|
||||
Assert.That(context.Result, Is.True);
|
||||
@@ -76,7 +77,7 @@ namespace Orchard.Tests.Modules.Widgets.RuleEngine {
|
||||
|
||||
[Test]
|
||||
public void UrlForHomePageMatchesHomePagePathWithUrlPrefix() {
|
||||
_stubContextAccessor.StubContext = new StubHttpContext("~/site1");
|
||||
_stubContextAccessor.Set(new StubHttpContext("~/site1"));
|
||||
_shellSettings.RequestUrlPrefix = "site1";
|
||||
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/" } };
|
||||
_urlRuleProvider.Process(context);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using Autofac;
|
||||
using Moq;
|
||||
using NHibernate;
|
||||
@@ -17,7 +16,6 @@ using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Localization.Records;
|
||||
using Orchard.Localization.Services;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Security;
|
||||
using Orchard.Tests.ContentManagement;
|
||||
using Orchard.Tests.Stubs;
|
||||
@@ -31,10 +29,11 @@ namespace Orchard.Tests.Localization {
|
||||
private ISessionFactory _sessionFactory;
|
||||
private ISession _session;
|
||||
private string _databaseFileName;
|
||||
private StubWorkContext _stubWorkContext;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void InitFixture() {
|
||||
_databaseFileName = System.IO.Path.GetTempFileName();
|
||||
_databaseFileName = Path.GetTempFileName();
|
||||
_sessionFactory = DataUtility.CreateSessionFactory(
|
||||
_databaseFileName,
|
||||
typeof(CultureRecord));
|
||||
@@ -43,6 +42,7 @@ namespace Orchard.Tests.Localization {
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
_stubWorkContext = new StubWorkContext();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||
@@ -50,12 +50,11 @@ namespace Orchard.Tests.Localization {
|
||||
builder.RegisterInstance(new Mock<IAuthorizer>().Object);
|
||||
builder.RegisterInstance(new Mock<INotifier>().Object);
|
||||
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
|
||||
builder.RegisterType<StubHttpContextAccessor>().As<IHttpContextAccessor>();
|
||||
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterInstance(_stubWorkContext);
|
||||
builder.RegisterInstance(new StubWorkContextAccessor(_stubWorkContext)).As<IWorkContextAccessor>();
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
builder.RegisterType<TestCultureSelector>().As<ICultureSelector>();
|
||||
builder.RegisterType<DefaultCultureManager>().As<ICultureManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
@@ -106,15 +105,9 @@ namespace Orchard.Tests.Localization {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CultureManagerReturnsCultureFromSelector() {
|
||||
Assert.That(_cultureManager.GetCurrentCulture(null), Is.EqualTo("en-US"));
|
||||
public void CultureManagerReturnsCultureFromWorkContext() {
|
||||
_stubWorkContext.CultureName = "nl-NL";
|
||||
Assert.That(_cultureManager.GetCurrentCulture(null), Is.EqualTo("nl-NL"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TestCultureSelector : ICultureSelector {
|
||||
public CultureSelectorResult GetCulture(HttpContextBase context) {
|
||||
return new CultureSelectorResult { Priority = 1, CultureName = "en-US" };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Localization.Services;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Tests.Stubs;
|
||||
|
||||
namespace Orchard.Tests.Localization {
|
||||
[TestFixture]
|
||||
public class CurrentCultureWorkContextTests {
|
||||
private IContainer _container;
|
||||
private IWorkContextStateProvider _currentCultureStateProvider;
|
||||
private WorkContext _workContext;
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
_workContext = new StubWorkContext();
|
||||
builder.RegisterInstance(new StubCultureSelector("or-CH")).As<ICultureSelector>();
|
||||
builder.RegisterInstance(new StubHttpContext("~/"));
|
||||
builder.RegisterInstance(_workContext);
|
||||
builder.RegisterType<StubHttpContextAccessor>().As<IHttpContextAccessor>();
|
||||
builder.RegisterType<CurrentCultureWorkContext>().As<IWorkContextStateProvider>();
|
||||
_container = builder.Build();
|
||||
_currentCultureStateProvider = _container.Resolve<IWorkContextStateProvider>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CultureManagerReturnsCultureFromSelectors() {
|
||||
var actualCulture = _currentCultureStateProvider.Get<string>("CurrentCulture")(_workContext);
|
||||
var expectedCulture = "or-CH";
|
||||
Assert.That(actualCulture, Is.EqualTo(expectedCulture));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Autofac;
|
||||
using Moq;
|
||||
using Orchard.Localization.Services;
|
||||
@@ -28,16 +25,19 @@ namespace Orchard.Tests.Localization {
|
||||
|
||||
internal class StubWorkContext : WorkContext {
|
||||
|
||||
private string _cultureName;
|
||||
private string _calendarName;
|
||||
private TimeZoneInfo _timeZone;
|
||||
public StubWorkContext() {
|
||||
}
|
||||
|
||||
public StubWorkContext(string cultureName, string calendarName, TimeZoneInfo timeZone) {
|
||||
_cultureName = cultureName;
|
||||
_calendarName = calendarName;
|
||||
_timeZone = timeZone;
|
||||
CultureName = cultureName;
|
||||
CalendarName = calendarName;
|
||||
TimeZone = timeZone;
|
||||
}
|
||||
|
||||
public string CultureName { get; set; }
|
||||
public string CalendarName { get; set; }
|
||||
public TimeZoneInfo TimeZone { get; set; }
|
||||
|
||||
public override T Resolve<T>() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -47,9 +47,9 @@ namespace Orchard.Tests.Localization {
|
||||
}
|
||||
|
||||
public override T GetState<T>(string name) {
|
||||
if (name == "CurrentCulture") return (T)((object)_cultureName);
|
||||
if (name == "CurrentCalendar") return (T)((object)_calendarName);
|
||||
if (name == "CurrentTimeZone") return (T)((object)_timeZone);
|
||||
if (name == "CurrentCulture") return (T)((object)CultureName);
|
||||
if (name == "CurrentCalendar") return (T)((object)CalendarName);
|
||||
if (name == "CurrentTimeZone") return (T)((object)TimeZone);
|
||||
throw new NotImplementedException(String.Format("Property '{0}' is not implemented.", name));
|
||||
}
|
||||
|
||||
@@ -60,17 +60,17 @@ namespace Orchard.Tests.Localization {
|
||||
|
||||
internal class StubWorkContextAccessor : IWorkContextAccessor {
|
||||
|
||||
private WorkContext _workContext;
|
||||
private readonly WorkContext _workContext;
|
||||
|
||||
public StubWorkContextAccessor(WorkContext workContext) {
|
||||
_workContext = workContext;
|
||||
}
|
||||
|
||||
public WorkContext GetContext(System.Web.HttpContextBase httpContext) {
|
||||
public WorkContext GetContext(HttpContextBase httpContext) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IWorkContextScope CreateWorkContextScope(System.Web.HttpContextBase httpContext) {
|
||||
public IWorkContextScope CreateWorkContextScope(HttpContextBase httpContext) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
@@ -259,10 +259,12 @@
|
||||
<Compile Include="FileSystems\Dependencies\AssemblyProbingFolderTests.cs" />
|
||||
<Compile Include="FileSystems\Dependencies\DependenciesFolderTests.cs" />
|
||||
<Compile Include="FileSystems\VirtualPath\DefaultVirtualPathProviderTests.cs" />
|
||||
<Compile Include="Localization\CurrentCultureWorkContextTests.cs" />
|
||||
<Compile Include="Localization\CultureManagerTests.cs" />
|
||||
<Compile Include="Localization\DateTimePartsTests.cs" />
|
||||
<Compile Include="Localization\DefaultDateLocalizationServicesTests.cs" />
|
||||
<Compile Include="Localization\DefaultDateFormatterTests.cs" />
|
||||
<Compile Include="Stubs\StubCultureSelector.cs" />
|
||||
<Compile Include="Localization\TestHelpers.cs" />
|
||||
<Compile Include="Logging\OrchardFileAppenderTests.cs" />
|
||||
<Compile Include="Messaging\MessagingChannelStub.cs" />
|
||||
|
||||
16
src/Orchard.Tests/Stubs/StubCultureSelector.cs
Normal file
16
src/Orchard.Tests/Stubs/StubCultureSelector.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Web;
|
||||
using Orchard.Localization.Services;
|
||||
|
||||
namespace Orchard.Tests.Stubs {
|
||||
public class StubCultureSelector : ICultureSelector {
|
||||
private readonly string _cultureName;
|
||||
|
||||
public StubCultureSelector(string cultureName) {
|
||||
_cultureName = cultureName;
|
||||
}
|
||||
|
||||
public CultureSelectorResult GetCulture(HttpContextBase context) {
|
||||
return new CultureSelectorResult { Priority = 1, CultureName = _cultureName };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,19 @@ namespace Orchard.Tests.Stubs {
|
||||
public class StubHttpContextAccessor : IHttpContextAccessor {
|
||||
private HttpContextBase _httpContext;
|
||||
|
||||
public HttpContextBase StubContext {
|
||||
set { _httpContext = value; }
|
||||
public StubHttpContextAccessor() {
|
||||
}
|
||||
|
||||
public StubHttpContextAccessor(HttpContextBase httpContext) {
|
||||
_httpContext = httpContext;
|
||||
}
|
||||
|
||||
public HttpContextBase Current() {
|
||||
return _httpContext;
|
||||
}
|
||||
|
||||
public void Set(HttpContextBase stub) {
|
||||
_httpContext = stub;
|
||||
public void Set(HttpContextBase httpContext) {
|
||||
_httpContext = httpContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,9 @@ namespace Orchard.Localization.Services {
|
||||
.Select(c => c.GetCulture(httpContext))
|
||||
.Where(c => c != null)
|
||||
.OrderByDescending(c => c.Priority)
|
||||
.FirstOrDefault(c => !string.IsNullOrEmpty(c.CultureName));
|
||||
.FirstOrDefault(c => !String.IsNullOrEmpty(c.CultureName));
|
||||
|
||||
return culture == null ? string.Empty : culture.CultureName;
|
||||
return culture == null ? String.Empty : culture.CultureName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,18 +9,17 @@ using Orchard.Localization.Records;
|
||||
namespace Orchard.Localization.Services {
|
||||
public class DefaultCultureManager : ICultureManager {
|
||||
private readonly IRepository<CultureRecord> _cultureRepository;
|
||||
private readonly IEnumerable<ICultureSelector> _cultureSelectors;
|
||||
private readonly ISignals _signals;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly ICacheManager _cacheManager;
|
||||
|
||||
public DefaultCultureManager(IRepository<CultureRecord> cultureRepository,
|
||||
IEnumerable<ICultureSelector> cultureSelectors,
|
||||
ISignals signals,
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
ICacheManager cacheManager) {
|
||||
public DefaultCultureManager(
|
||||
IRepository<CultureRecord> cultureRepository,
|
||||
ISignals signals,
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
ICacheManager cacheManager) {
|
||||
|
||||
_cultureRepository = cultureRepository;
|
||||
_cultureSelectors = cultureSelectors;
|
||||
_signals = signals;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_cacheManager = cacheManager;
|
||||
@@ -38,12 +37,12 @@ namespace Orchard.Localization.Services {
|
||||
if (!IsValidCulture(cultureName)) {
|
||||
throw new ArgumentException("cultureName");
|
||||
}
|
||||
|
||||
|
||||
if (ListCultures().Any(culture => culture == cultureName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_cultureRepository.Create(new CultureRecord {Culture = cultureName});
|
||||
_cultureRepository.Create(new CultureRecord { Culture = cultureName });
|
||||
_signals.Trigger("culturesChanged");
|
||||
}
|
||||
|
||||
@@ -81,7 +80,7 @@ namespace Orchard.Localization.Services {
|
||||
public bool IsValidCulture(string cultureName) {
|
||||
var segments = cultureName.Split('-');
|
||||
|
||||
if(segments.Length == 0) {
|
||||
if (segments.Length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -92,7 +91,7 @@ namespace Orchard.Localization.Services {
|
||||
if (segments.Any(s => s.Length < 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,19 @@ using System.Web;
|
||||
namespace Orchard.Mvc {
|
||||
public interface IHttpContextAccessor {
|
||||
HttpContextBase Current();
|
||||
void Set(HttpContextBase stub);
|
||||
void Set(HttpContextBase httpContext);
|
||||
}
|
||||
|
||||
public class HttpContextAccessor : IHttpContextAccessor {
|
||||
private HttpContextBase _stub;
|
||||
private HttpContextBase _httpContext;
|
||||
|
||||
public HttpContextBase Current() {
|
||||
var httpContext = GetStaticProperty();
|
||||
return httpContext != null ? new HttpContextWrapper(httpContext) : _stub;
|
||||
return httpContext != null ? new HttpContextWrapper(httpContext) : _httpContext;
|
||||
}
|
||||
|
||||
public void Set(HttpContextBase stub) {
|
||||
_stub = stub;
|
||||
public void Set(HttpContextBase httpContext) {
|
||||
_httpContext = httpContext;
|
||||
}
|
||||
|
||||
private HttpContext GetStaticProperty() {
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Orchard {
|
||||
/// <returns>True if the dependency could be resolved, false otherwise</returns>
|
||||
public abstract bool TryResolve<T>(out T service);
|
||||
|
||||
public abstract T GetState<T>(string name);
|
||||
public abstract T GetState<T>(string name);
|
||||
public abstract void SetState<T>(string name, T value);
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user