From 54ab14b35687591cbe6fb8ec7e2c895dc774d8d7 Mon Sep 17 00:00:00 2001 From: Benedek Farkas Date: Fri, 8 Mar 2024 10:56:06 +0000 Subject: [PATCH] 8686: Fixing build and tests on dev (#8695) * Fixing that RecipeManagerTests failed due to HttpContext not being available * Fixing OwnerEditor tests in CommonPartProviderTests as the owner editor now checks for a different permission since 5b0c82d1ad39526253eb2a5caf74dbcb8615860a * Fixing typo in CommonPartProviderTests.UpdateModelStub class name * Fixing that test cases for invalid path in FileSystemStorageProviderTests broke in a3e9bef3ca084aedc0dbdcc6e82d31f4497b2007 (issue #6802, PR #6919) I should review PRs more carefully! * Fixing CurrentCultureWorkContextTests * Fixing indentation in DefaultDateFormatterTests * Updating Orchard.Azure.Web's required version of System.Web.Mvc to match the rest of the solution * Orchard.Specs: Fixing assembly loading errors when starting up the web host by adding binding redirects * Adding empty compile workflow from dev * Adding the compile workflow's actual contents * Changing default shell to pwsh (msbuild was not found in cmd?) * Adding msbuild to PATH * Removing unused references to System.Net.Http * Replacing System.Net.Http references with its NuGet package to pin the correct version number (experimental) * Upgrading Microsoft.CodeDom.Providers.DotNetCompilerPlatform to 4.1.0 (latest) to get rid of old System.Http.Net dependency * Orchard.proj: Spec target actually depends on only the Compile target, not Package-Stage (experimental) * Compile workflow: Testing the Test and Spec targets * Fixing Test step * Fixing compile workflow to also mark Razor compilation warnings as errors * Restoring Orchard.Specs/Hosting/Orchard.Web/Web.config to match Orchard.Web's web.config closer so that it loads assemblies from the Dependencies folder. This fixes the error with Autofac not being able to resolve dependencies for DefaultOrchardShell * Orchard.Specs/Hosting/Orchard.Web/Global.asax.cs: Workaround for AntiForgeryToken bug in ASP.NET MVC since version 5.2.4 https://github.com/aspnet/AspNetWebStack/issues/162 * Revert "Replacing System.Net.Http references with its NuGet package to pin the correct version number (experimental)" This reverts commit 087f2849b116fd1e1d890a8e5ea867a644f05426. * Revert "Upgrading Microsoft.CodeDom.Providers.DotNetCompilerPlatform to 4.1.0 (latest) to get rid of old System.Http.Net dependency" This reverts commit be2ba866e34b9140e92365ede4876c375a0053f2. * Reverting the addition of assembly binding redirects to Orchard.Specs/Hosting/Simple.Web/Web.config since it doesn't need them like Orchard.Specs/Hosting/Orchard.Web/Web.config does * Disabling Test and Spec execution for now * Orchard.Framework: Making the System.Net.Http not-private to prevent an outdated version sticking around * Orchard.Workflows: Adding assembly binding redirect for System.Net.Http to avoid Razor compilation warning * Moving the System.Net.Http assembly redirect to Orchard.Web * Specs: Fixing "I can create browse blog posts on several pages" Blog test's usage of "I should not see" and correcting the parameters too because unlike "I should see", this is not a regex match, just contains * Specs: Fixing "I can create browse blog posts on several pages" Blog test's flakyness due to timing because the blog posts are created quickly after one another and the lack of millisecond-precision can cause the blog posts to appear out of order of creation * Specs: Media test simplified since the Orchard.Media feature is deprecated * Adding step to the Compile workflow to upload the MSBuild binlog results * Pinning the referenced version of System.Net.Http to 4.2.0.0 to prevent Razor compilation warning System.Net.Http is known to have such problems across different framework versions ways of referencing it The original warning is: ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Orchard.Workflows, Version=1.10.3.0, Culture=neutral, PublicKeyToken=null. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [D:\a\Orchard\Orchard\src\Orchard.Web\Modules\Orchard.Workflows\Orchard.Workflows.csproj * Re-enabling the Test step * Re-enabling the Specs step * Marking System.Net.Http references as private (copy local) to make sure that it's always available, because it requires a specific version * Revert "Marking System.Net.Http references as private (copy local) to make sure that it's always available, because it requires a specific version" This reverts commit e4f563223689b5cf88a143634a75e8b999a55a76. * Orchard.Specs: Adding Settings feature * Orchard.Specs: Updating DateTime.CreatingAndUsingDateTimeFieldsInAnotherCulture structure without functional change * Orchard.Specs: Updating Settings.AddingANewSiteCultureAndSelectingItAsTheDefaultWorks to correctly detect that a culture that wasn't added before can be set as default * Fixing outdated assembly binding redirects * Fixing Newtonsoft.Json references * Updating Newtonsoft.Json reference in Orchard.Messaging.Tests.csproj * Disabling the Test step for now * Adding System.Net.Http 4.2.0.0 reference to Orchard.Email's web.config to fix Razor compilation warning * Re-enabling the Test step * Fixing HqlExpressionTests.AllDataTypesCanBeQueried * Fixing initialization error error in StylesheetBindingStrategyTests * Fixing initialization errors in FeatureManagerTests * Fixing Orchard.Tests.Localization.TextTests * Code styling and fixing warning in Orchard.Tests/UI/Resources/ResourceManagerTests.cs * Updating Orchard.Tests/UI/Resources/ResourceManagerTests.cs according to ResourceManager API change in ac11024be40ed340345e73e13e0824d5911bb9cb and removing obsolete tests * Orchard.Tests.Modules: Adding missing reference to Iesi.Collections (that doesn't cause a build error, just when running tests) * Fixing initialization errors in ModuleStepTest and ThemeStepTest * Fixing initialization errors in ShellDescriptorManagerTests * Fixing initialization errors in AccountControllerTests * Fixing that MembershipServiceTests should use IPasswordService, also making SaltAndPasswordShouldBeDifferentEvenWithSameSourcePassword test parameters more readable * Specs: Updating the Newtonsoft.Json binding redirect in the spec app's web.config * Re-enabling the Spec step * Upgrading actions to latest versions These actions generated the Node.js 16 deprecation warning * Removing SpecFlow test execution from the compile workflow * Testing the branch strategy matrix concept to be used for the nightly build * Revert "Testing the branch strategy matrix concept to be used for the nightly build" This reverts commit 1354e367b78402c01cd291f7292556b5b59da5e9. * Adding workflow to run specflow tests as a nightly build * Updating Orchard.Tests.ContentManagement.HqlExpressionTests.ShouldSortRandomly to decrease failure chance due to randomness --- .github/workflows/compile.yml | 8 +- .github/workflows/specflow.yml | 39 ++++++++ .../Hosting/Orchard.Web/Web.config | 2 +- src/Orchard.Specs/Orchard.Specs.csproj | 9 ++ src/Orchard.Specs/Settings.feature | 14 +++ src/Orchard.Specs/Settings.feature.cs | 93 +++++++++++++++++++ .../Orchard.Tests.Modules.csproj | 3 + .../Recipes/RecipeHandlers/ModuleStepTest.cs | 3 + .../Recipes/RecipeHandlers/ThemeStepTest.cs | 3 + .../Blueprint/ShellDescriptorManagerTests.cs | 3 + .../Controllers/AccountControllerTests.cs | 2 + .../Users/Services/MembershipServiceTests.cs | 11 ++- .../ContentManagement/HqlExpressionTests.cs | 39 ++++---- .../StylesheetBindingStrategyTests.cs | 5 + .../Features/FeatureManagerTests.cs | 11 ++- src/Orchard.Tests/Localization/TextTests.cs | 12 +-- .../UI/Resources/ResourceManagerTests.cs | 70 +++++--------- .../Modules/Orchard.Email/Web.config | 1 + .../Modules/Orchard.Glimpse/Web.config | 2 +- .../Tests/Orchard.Messaging.Tests.csproj | 4 +- .../Modules/Orchard.Resources/Web.config | 2 +- 21 files changed, 246 insertions(+), 90 deletions(-) create mode 100644 .github/workflows/specflow.yml create mode 100644 src/Orchard.Specs/Settings.feature create mode 100644 src/Orchard.Specs/Settings.feature.cs diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 9ca714922b7..ce5f1a9591b 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -1,4 +1,5 @@ name: Compile +# Compiles the solution and runs unit tests. on: workflow_dispatch: @@ -18,13 +19,16 @@ jobs: steps: - name: Clone repository - uses: actions/checkout@v3.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Restore NuGet packages run: nuget restore src/Orchard.sln - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.3.1 + uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2.0.0 - name: Compile run: msbuild Orchard.proj /m /t:Compile /p:MvcBuildViews=true /p:TreatWarningsAsErrors=true -WarnAsError + + - name: Test + run: msbuild Orchard.proj /m /t:Test diff --git a/.github/workflows/specflow.yml b/.github/workflows/specflow.yml new file mode 100644 index 00000000000..8e058809ebe --- /dev/null +++ b/.github/workflows/specflow.yml @@ -0,0 +1,39 @@ +name: SpecFlow tests +# Compiles the solution and runs unit tests, as well the SpecFlow tests on the main development branches. + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * *' # Every day at midnight. + +jobs: + compile: + name: SpecFlow tests + defaults: + run: + shell: pwsh + runs-on: windows-latest + strategy: + matrix: + branch: [dev, 1.10.x] + + steps: + - name: Clone repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + ref: ${{ matrix.branch }} + + - name: Restore NuGet packages + run: nuget restore src/Orchard.sln + + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2.0.0 + + - name: Compile + run: msbuild Orchard.proj /m /t:Compile /p:MvcBuildViews=true /p:TreatWarningsAsErrors=true -WarnAsError + + - name: Test + run: msbuild Orchard.proj /m /t:Test + + - name: Spec + run: msbuild Orchard.proj /m /t:Spec diff --git a/src/Orchard.Specs/Hosting/Orchard.Web/Web.config b/src/Orchard.Specs/Hosting/Orchard.Web/Web.config index 79431085e04..f1ddceef2cd 100644 --- a/src/Orchard.Specs/Hosting/Orchard.Web/Web.config +++ b/src/Orchard.Specs/Hosting/Orchard.Web/Web.config @@ -164,7 +164,7 @@ - + diff --git a/src/Orchard.Specs/Orchard.Specs.csproj b/src/Orchard.Specs/Orchard.Specs.csproj index 5031ed85fb9..87c775a47a9 100644 --- a/src/Orchard.Specs/Orchard.Specs.csproj +++ b/src/Orchard.Specs/Orchard.Specs.csproj @@ -200,6 +200,11 @@ True True + + True + True + Settings.feature + Text.feature True @@ -372,6 +377,10 @@ HostComponents.config + + SpecFlowSingleFileGenerator + Settings.feature.cs + SpecFlowSingleFileGenerator Text.feature.cs diff --git a/src/Orchard.Specs/Settings.feature b/src/Orchard.Specs/Settings.feature new file mode 100644 index 00000000000..d4567363911 --- /dev/null +++ b/src/Orchard.Specs/Settings.feature @@ -0,0 +1,14 @@ +Feature: Settings + +In order to manage my site +As a privileged user +I want to be able to see and change site settings + +Scenario: Adding a new site culture and selecting it as the default works + + Given I have installed Orchard + When I go to "Admin/Settings/Index" + Then I should not see "hu-HU" + When I have "hu-HU" as the default culture + And I go to "Admin/Settings/Index" + Then I should see "" diff --git a/src/Orchard.Specs/Settings.feature.cs b/src/Orchard.Specs/Settings.feature.cs new file mode 100644 index 00000000000..83e95acf94b --- /dev/null +++ b/src/Orchard.Specs/Settings.feature.cs @@ -0,0 +1,93 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (http://www.specflow.org/). +// SpecFlow Version:1.9.0.77 +// SpecFlow Generator Version:1.9.0.0 +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +#region Designer generated code +#pragma warning disable +namespace Orchard.Specs +{ + using TechTalk.SpecFlow; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.9.0.77")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [NUnit.Framework.TestFixtureAttribute()] + [NUnit.Framework.DescriptionAttribute("Settings")] + public partial class SettingsFeature + { + + private static TechTalk.SpecFlow.ITestRunner testRunner; + +#line 1 "Settings.feature" +#line hidden + + [NUnit.Framework.TestFixtureSetUpAttribute()] + public virtual void FeatureSetup() + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Settings", "\r\nIn order to manage my site\r\nAs a privileged user\r\nI want to be able to see and " + + "change site settings", ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [NUnit.Framework.TestFixtureTearDownAttribute()] + public virtual void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [NUnit.Framework.SetUpAttribute()] + public virtual void TestInitialize() + { + } + + [NUnit.Framework.TearDownAttribute()] + public virtual void ScenarioTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioStart(scenarioInfo); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Adding a new site culture and selecting it as the default works")] + public virtual void AddingANewSiteCultureAndSelectingItAsTheDefaultWorks() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Adding a new site culture and selecting it as the default works", ((string[])(null))); +#line 7 +this.ScenarioSetup(scenarioInfo); +#line 9 + testRunner.Given("I have installed Orchard", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 10 + testRunner.When("I go to \"Admin/Settings/Index\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 11 + testRunner.Then("I should not see \"hu-HU\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line 12 + testRunner.When("I have \"hu-HU\" as the default culture", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 13 + testRunner.And("I go to \"Admin/Settings/Index\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 14 + testRunner.Then("I should see \"\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/src/Orchard.Tests.Modules/Orchard.Tests.Modules.csproj b/src/Orchard.Tests.Modules/Orchard.Tests.Modules.csproj index dad7f771fd0..5d8e4dea542 100644 --- a/src/Orchard.Tests.Modules/Orchard.Tests.Modules.csproj +++ b/src/Orchard.Tests.Modules/Orchard.Tests.Modules.csproj @@ -80,6 +80,9 @@ ..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll + + ..\packages\Iesi.Collections.4.0.4\lib\net461\Iesi.Collections.dll + ..\packages\IronRuby.1.1.3\lib\IronRuby.dll diff --git a/src/Orchard.Tests.Modules/Recipes/RecipeHandlers/ModuleStepTest.cs b/src/Orchard.Tests.Modules/Recipes/RecipeHandlers/ModuleStepTest.cs index ed850d4c73b..8bd77d1e35b 100644 --- a/src/Orchard.Tests.Modules/Recipes/RecipeHandlers/ModuleStepTest.cs +++ b/src/Orchard.Tests.Modules/Recipes/RecipeHandlers/ModuleStepTest.cs @@ -19,6 +19,7 @@ using Orchard.Environment.Features; using Orchard.Environment.State; using Orchard.Events; +using Orchard.Locking; using Orchard.Packaging.GalleryServer; using Orchard.Packaging.Models; using Orchard.Packaging.Services; @@ -57,6 +58,7 @@ public override void Register(ContainerBuilder builder) { builder.RegisterType().AsSelf(); builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); @@ -65,6 +67,7 @@ public override void Register(ContainerBuilder builder) { builder.RegisterInstance(_packagesInRepository).As(); builder.RegisterInstance(_packageManager).As(); builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType(); builder.RegisterSource(new EventsRegistrationSource()); diff --git a/src/Orchard.Tests.Modules/Recipes/RecipeHandlers/ThemeStepTest.cs b/src/Orchard.Tests.Modules/Recipes/RecipeHandlers/ThemeStepTest.cs index 07eda2e9dc4..934744a7d1f 100644 --- a/src/Orchard.Tests.Modules/Recipes/RecipeHandlers/ThemeStepTest.cs +++ b/src/Orchard.Tests.Modules/Recipes/RecipeHandlers/ThemeStepTest.cs @@ -19,6 +19,7 @@ using Orchard.Environment.State; using Orchard.Events; using Orchard.FileSystems.VirtualPath; +using Orchard.Locking; using Orchard.Packaging.GalleryServer; using Orchard.Packaging.Services; using Orchard.Recipes.Models; @@ -60,6 +61,7 @@ public override void Register(ContainerBuilder builder) { builder.RegisterType().AsSelf(); builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); @@ -71,6 +73,7 @@ public override void Register(ContainerBuilder builder) { builder.RegisterInstance(testVirtualPathProvider).As(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As(); + builder.RegisterType().As().SingleInstance(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType(); diff --git a/src/Orchard.Tests.Modules/Settings/Blueprint/ShellDescriptorManagerTests.cs b/src/Orchard.Tests.Modules/Settings/Blueprint/ShellDescriptorManagerTests.cs index 3b38d6a4dea..87e94a01ad6 100644 --- a/src/Orchard.Tests.Modules/Settings/Blueprint/ShellDescriptorManagerTests.cs +++ b/src/Orchard.Tests.Modules/Settings/Blueprint/ShellDescriptorManagerTests.cs @@ -14,6 +14,7 @@ using Orchard.Events; using Orchard.Caching; using Orchard.Core.Settings.State.Records; +using Orchard.Locking; namespace Orchard.Tests.Modules.Settings.Blueprint { [TestFixture] @@ -24,6 +25,8 @@ public override void Register(ContainerBuilder builder) { builder.RegisterType().As(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As(); + builder.RegisterType().As(); + builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); diff --git a/src/Orchard.Tests.Modules/Users/Controllers/AccountControllerTests.cs b/src/Orchard.Tests.Modules/Users/Controllers/AccountControllerTests.cs index eed55f7ec1e..94cf64b5b52 100644 --- a/src/Orchard.Tests.Modules/Users/Controllers/AccountControllerTests.cs +++ b/src/Orchard.Tests.Modules/Users/Controllers/AccountControllerTests.cs @@ -71,6 +71,8 @@ public override void Register(ContainerBuilder builder) { builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterInstance(new Work>(resolve => _container.Resolve>())).AsSelf(); builder.RegisterType().As(); diff --git a/src/Orchard.Tests.Modules/Users/Services/MembershipServiceTests.cs b/src/Orchard.Tests.Modules/Users/Services/MembershipServiceTests.cs index 0138ddb2427..4d4d2ef2ba6 100644 --- a/src/Orchard.Tests.Modules/Users/Services/MembershipServiceTests.cs +++ b/src/Orchard.Tests.Modules/Users/Services/MembershipServiceTests.cs @@ -68,6 +68,7 @@ public void Init() { //builder.RegisterModule(new ImplicitCollectionSupportModule()); builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); @@ -77,7 +78,6 @@ public void Init() { builder.RegisterType().As(); builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataProvider = "SqlCe" }); builder.RegisterType().As(); - //builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterAutoMocking(MockBehavior.Loose); builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)); @@ -135,11 +135,12 @@ public void DefaultPasswordFormatShouldBeHashedAndHaveSalt() { [Test] public void SaltAndPasswordShouldBeDifferentEvenWithSameSourcePassword() { - var user1 = _membershipService.CreateUser(new CreateUserParams("a", "b", "c", null, null, true, false)); + var password = "Password1!"; + var user1 = _membershipService.CreateUser(new CreateUserParams("user1", password, "user1@email.com", null, null, true, false)); _session.Flush(); _session.Clear(); - var user2 = _membershipService.CreateUser(new CreateUserParams("d", "b", "e", null, null, true, false)); + var user2 = _membershipService.CreateUser(new CreateUserParams("user2", password, "user2@email.com", null, null, true, false)); _session.Flush(); _session.Clear(); @@ -150,8 +151,8 @@ public void SaltAndPasswordShouldBeDifferentEvenWithSameSourcePassword() { Assert.That(user1Record.Password, Is.Not.EqualTo(user2Record.Password)); List validationErrors; - Assert.That(_membershipService.ValidateUser("a", "b", out validationErrors), Is.Not.Null); - Assert.That(_membershipService.ValidateUser("d", "b", out validationErrors), Is.Not.Null); + Assert.That(_membershipService.ValidateUser("user1", password, out validationErrors), Is.Not.Null); + Assert.That(_membershipService.ValidateUser("user2", password, out validationErrors), Is.Not.Null); } [Test] diff --git a/src/Orchard.Tests/ContentManagement/HqlExpressionTests.cs b/src/Orchard.Tests/ContentManagement/HqlExpressionTests.cs index f73c0f080e3..05cdcb0e3f6 100644 --- a/src/Orchard.Tests/ContentManagement/HqlExpressionTests.cs +++ b/src/Orchard.Tests/ContentManagement/HqlExpressionTests.cs @@ -106,7 +106,10 @@ public void Cleanup() { [Test] public void AllDataTypesCanBeQueried() { - var dt = DateTime.Now; + var now = DateTime.Now; + // NHibernate stores DateTime values with seconds-precision, so everything below that needs to be truncated + // so that the query works correctly. Thanks to https://stackoverflow.com/a/1005222 for elegant solution. + now = now.AddTicks(-(now.Ticks % TimeSpan.TicksPerSecond)); _manager.Create("lambda", init => { init.Record.BooleanStuff = true; @@ -116,7 +119,7 @@ public void AllDataTypesCanBeQueried() { init.Record.IntegerStuff = 0; init.Record.LongStuff = 0; init.Record.StringStuff = "0"; - init.Record.DateTimeStuff = dt; + init.Record.DateTimeStuff = now; }); _session.Flush(); @@ -144,7 +147,7 @@ public void AllDataTypesCanBeQueried() { lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord(), x => x.Eq("StringStuff", "0")).List(); Assert.That(lambda.Count(), Is.EqualTo(1)); - lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord(), x => x.Eq("DateTimeStuff", dt)).List(); + lambda = _manager.HqlQuery().Where(alias => alias.ContentPartRecord(), x => x.Eq("DateTimeStuff", now)).List(); Assert.That(lambda.Count(), Is.EqualTo(1)); } @@ -940,31 +943,29 @@ public void ShouldQueryUsingOperatorLtProperty() { } [Test] + // This is a potentially flaky test, but failure due to randomness is extremely unlikely. public void ShouldSortRandomly() { - _manager.Create("lambda", init => { - init.Record.IntegerStuff = 1; - }); - - _manager.Create("lambda", init => { - init.Record.IntegerStuff = 2; - }); + var itemCount = 10; + for (int i = 0; i < itemCount; i++) { + _manager.Create("lambda", init => { + init.Record.IntegerStuff = i; + }); + } - _manager.Create("lambda", init => { - init.Record.IntegerStuff = 3; - }); _session.Flush(); - var result = _manager.HqlQuery().ForType("lambda").List(); - Assert.That(result.Count(), Is.EqualTo(3)); + var items = _manager.HqlQuery().ForType("lambda").List(); + Assert.That(items.Count(), Is.EqualTo(itemCount)); - var firstResults = new List(); + var results = new List(); for (int i = 0; i < 10; i++) { - result = _manager.HqlQuery().Join(alias => alias.ContentPartRecord()).OrderBy(x => x.Named("civ"), order => order.Random()).List(); - firstResults.Add(result.First().As().Record.IntegerStuff); + items = _manager.HqlQuery().Join(alias => + alias.ContentPartRecord()).OrderBy(x => x.Named("civ"), order => order.Random()).List(); + results.Add(string.Join("", items.Select(item => item.As().Record.IntegerStuff))); } - Assert.That(firstResults.Distinct().Count(), Is.GreaterThan(1)); + Assert.That(results.Distinct().Count(), Is.GreaterThan(1)); } [Test] diff --git a/src/Orchard.Tests/DisplayManagement/Descriptors/StylesheetBindingStrategyTests.cs b/src/Orchard.Tests/DisplayManagement/Descriptors/StylesheetBindingStrategyTests.cs index 2ff3a87a9a8..0c25bf4cb97 100644 --- a/src/Orchard.Tests/DisplayManagement/Descriptors/StylesheetBindingStrategyTests.cs +++ b/src/Orchard.Tests/DisplayManagement/Descriptors/StylesheetBindingStrategyTests.cs @@ -8,10 +8,13 @@ using Orchard.DisplayManagement.Descriptors; using Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy; using Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy; +using Orchard.Environment; using Orchard.Environment.Descriptor.Models; using Orchard.Environment.Extensions; using Orchard.Environment.Extensions.Models; using Orchard.FileSystems.VirtualPath; +using Orchard.Tests.Localization; +using Orchard.UI.Resources; namespace Orchard.Tests.DisplayManagement.Descriptors { [TestFixture] @@ -29,8 +32,10 @@ protected override void Register(Autofac.ContainerBuilder builder) { builder.Register(ctx => _descriptor); builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterInstance(_testViewEngine).As(); builder.RegisterInstance(_testVirtualPathProvider).As(); + builder.RegisterInstance(new Work(resolve => new StubWorkContext())).AsSelf(); var extensionManager = new Mock(); builder.Register(ctx => extensionManager); diff --git a/src/Orchard.Tests/Environment/Features/FeatureManagerTests.cs b/src/Orchard.Tests/Environment/Features/FeatureManagerTests.cs index fa988a1654f..6bae88a3b96 100644 --- a/src/Orchard.Tests/Environment/Features/FeatureManagerTests.cs +++ b/src/Orchard.Tests/Environment/Features/FeatureManagerTests.cs @@ -16,6 +16,7 @@ using Orchard.Environment.Features; using Orchard.Environment.State; using Orchard.Events; +using Orchard.Locking; using Orchard.Tests.Environment.Extensions; using Orchard.Tests.Stubs; @@ -27,10 +28,10 @@ public class FeatureManagerTests : DatabaseEnabledTestsBase { protected override IEnumerable DatabaseTypes { get { return new[] { - typeof (ShellDescriptorRecord), - typeof (ShellFeatureRecord), - typeof (ShellParameterRecord), - }; + typeof (ShellDescriptorRecord), + typeof (ShellFeatureRecord), + typeof (ShellParameterRecord), + }; } } @@ -39,11 +40,13 @@ public override void Register(ContainerBuilder builder) { builder.RegisterInstance(_folders).As(); builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterSource(new EventsRegistrationSource()); diff --git a/src/Orchard.Tests/Localization/TextTests.cs b/src/Orchard.Tests/Localization/TextTests.cs index 628adc580dc..c5c69d84e3a 100644 --- a/src/Orchard.Tests/Localization/TextTests.cs +++ b/src/Orchard.Tests/Localization/TextTests.cs @@ -1,12 +1,11 @@ -using Autofac; +using System.Collections.Generic; +using System.Web; +using Autofac; using Moq; using NUnit.Framework; using Orchard.Localization; using Orchard.Localization.Services; -using Orchard.Mvc; using Orchard.Tests.Stubs; -using System.Collections.Generic; -using System.Web; namespace Orchard.Tests.Localization { [TestFixture] @@ -18,7 +17,7 @@ public class TextTests { public void Init() { var mockLocalizedManager = new Mock(); mockLocalizedManager - .Setup(x => x.GetLocalizedString(new List { It.IsAny() }, It.IsAny(), It.IsAny())) + .Setup(x => x.GetLocalizedString(It.IsAny>(), It.IsAny(), It.IsAny())) .Returns(new FormatForScope("foo {0}", null)); var builder = new ContainerBuilder(); @@ -38,8 +37,7 @@ public void TextHtmlEncodeAllArguments() { } [Test] - public void TextDoesEncodeHtmlEncodedArguments() - { + public void TextDoesEncodeHtmlEncodedArguments() { Assert.That(_text.Get("foo {0}", new HtmlString("bar")).Text, Is.EqualTo("foo bar")); Assert.That(_text.Get("foo {0}", new HtmlString("")).Text, Is.EqualTo("foo ")); } diff --git a/src/Orchard.Tests/UI/Resources/ResourceManagerTests.cs b/src/Orchard.Tests/UI/Resources/ResourceManagerTests.cs index 1b3c0fdd9b6..2ab6dc85a61 100644 --- a/src/Orchard.Tests/UI/Resources/ResourceManagerTests.cs +++ b/src/Orchard.Tests/UI/Resources/ResourceManagerTests.cs @@ -13,7 +13,7 @@ public class ResourceManagerTests { private IResourceManager _resourceManager; private IResourceFileHashProvider _resourceFileHashProvider; private TestManifestProvider _testManifest; - private string _appPath = "/AppPath/"; + private readonly string _appPath = "/AppPath/"; private class TestManifestProvider : IResourceManifestProvider { public Action DefineManifest { get; set; } @@ -30,10 +30,6 @@ public void BuildManifests(ResourceManifestBuilder builder) { } private void VerifyPaths(string resourceType, RequireSettings defaultSettings, string expectedPaths) { - VerifyPaths(resourceType, defaultSettings, expectedPaths, false); - } - - private void VerifyPaths(string resourceType, RequireSettings defaultSettings, string expectedPaths, bool ssl) { defaultSettings = defaultSettings ?? new RequireSettings(); var requiredResources = _resourceManager.BuildRequiredResources(resourceType); var renderedResources = string.Join(",", requiredResources.Select(context => context @@ -57,90 +53,68 @@ public void Init() { [Test] public void ReleasePathIsTheDefaultPath() { - _testManifest.DefineManifest = m => { - m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js"); - }; + _testManifest.DefineManifest = m => m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js"); _resourceManager.Require("script", "Script1"); VerifyPaths("script", null, "script1.min.js"); } [Test] public void DebugPathIsUsedWithDebugMode() { - _testManifest.DefineManifest = m => { - m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js"); - }; + _testManifest.DefineManifest = m => m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js"); _resourceManager.Require("script", "Script1"); VerifyPaths("script", new RequireSettings { DebugMode = true }, "script1.js"); } [Test] public void ReleasePathIsUsedWhenNoDebugPath() { - _testManifest.DefineManifest = m => { - m.DefineResource("script", "Script1").SetUrl("script1.min.js"); - }; + _testManifest.DefineManifest = m => m.DefineResource("script", "Script1").SetUrl("script1.min.js"); _resourceManager.Require("script", "Script1"); VerifyPaths("script", new RequireSettings { DebugMode = true }, "script1.min.js"); } [Test] public void DefaultSettingsAreOverriddenByUseDebugMode() { - _testManifest.DefineManifest = m => { - m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js"); - }; + _testManifest.DefineManifest = m => m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js"); _resourceManager.Require("script", "Script1").UseDebugMode(); VerifyPaths("script", new RequireSettings { DebugMode = false }, "script1.js"); } [Test] public void CdnPathIsUsedInCdnMode() { - _testManifest.DefineManifest = m => { - m.DefineResource("script", "Script1").SetUrl("script1.js").SetCdn("http://cdn/script1.min.js"); - }; + _testManifest.DefineManifest = m => m + .DefineResource("script", "Script1") + .SetUrl("script1.js") + .SetCdn("http://cdn/script1.min.js"); _resourceManager.Require("script", "Script1"); VerifyPaths("script", new RequireSettings { CdnMode = true }, "http://cdn/script1.min.js"); } [Test] public void CdnSslPathIsUsedInCdnMode() { - _testManifest.DefineManifest = m => { - m.DefineResource("script", "Script1").SetUrl("script1.js").SetCdn("https://cdn/script1.min.js"); - }; + _testManifest.DefineManifest = m => m + .DefineResource("script", "Script1") + .SetUrl("script1.js") + .SetCdn("https://cdn/script1.min.js"); _resourceManager.Require("script", "Script1"); - VerifyPaths("script", new RequireSettings { CdnMode = true }, "https://cdn/script1.min.js", true); - } - - [Test] - public void LocalPathIsUsedInCdnModeNotSupportsSsl() { - _testManifest.DefineManifest = m => { - m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js").SetCdn("http://cdn/script1.min.js", "http://cdn/script1.js"); - }; - _resourceManager.Require("script", "Script1"); - VerifyPaths("script", new RequireSettings { CdnMode = true }, "script1.min.js", true); - } - - [Test] - public void LocalDebugPathIsUsedInCdnModeNotSupportsSslAndDebug() { - _testManifest.DefineManifest = m => { - m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js").SetCdn("http://cdn/script1.min.js", "http://cdn/script1.js"); - }; - _resourceManager.Require("script", "Script1"); - VerifyPaths("script", new RequireSettings { CdnMode = true, DebugMode = true }, "script1.js", true); + VerifyPaths("script", new RequireSettings { CdnMode = true }, "https://cdn/script1.min.js"); } [Test] public void CdnDebugPathIsUsedInCdnModeAndDebugMode() { - _testManifest.DefineManifest = m => { - m.DefineResource("script", "Script1").SetUrl("script1.js").SetCdn("http://cdn/script1.min.js", "http://cdn/script1.js"); - }; + _testManifest.DefineManifest = m => m + .DefineResource("script", "Script1") + .SetUrl("script1.js") + .SetCdn("http://cdn/script1.min.js", "http://cdn/script1.js"); _resourceManager.Require("script", "Script1"); VerifyPaths("script", new RequireSettings { CdnMode = true, DebugMode = true }, "http://cdn/script1.js"); } [Test] public void DebugPathIsUsedInCdnModeAndDebugModeAndThereIsNoCdnDebugPath() { - _testManifest.DefineManifest = m => { - m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js").SetCdn("http://cdn/script1.min.js"); - }; + _testManifest.DefineManifest = m => m + .DefineResource("script", "Script1") + .SetUrl("script1.min.js", "script1.js") + .SetCdn("http://cdn/script1.min.js"); _resourceManager.Require("script", "Script1"); VerifyPaths("script", new RequireSettings { CdnMode = true, DebugMode = true }, "script1.js"); } diff --git a/src/Orchard.Web/Modules/Orchard.Email/Web.config b/src/Orchard.Web/Modules/Orchard.Email/Web.config index 933fe9ba185..0df49e40c1c 100644 --- a/src/Orchard.Web/Modules/Orchard.Email/Web.config +++ b/src/Orchard.Web/Modules/Orchard.Email/Web.config @@ -29,6 +29,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Glimpse/Web.config b/src/Orchard.Web/Modules/Orchard.Glimpse/Web.config index d39700e0c23..9fcbe1d7673 100644 --- a/src/Orchard.Web/Modules/Orchard.Glimpse/Web.config +++ b/src/Orchard.Web/Modules/Orchard.Glimpse/Web.config @@ -56,7 +56,7 @@ - + diff --git a/src/Orchard.Web/Modules/Orchard.JobsQueue/Tests/Orchard.Messaging.Tests.csproj b/src/Orchard.Web/Modules/Orchard.JobsQueue/Tests/Orchard.Messaging.Tests.csproj index 6ea952ce296..3b731591222 100644 --- a/src/Orchard.Web/Modules/Orchard.JobsQueue/Tests/Orchard.Messaging.Tests.csproj +++ b/src/Orchard.Web/Modules/Orchard.JobsQueue/Tests/Orchard.Messaging.Tests.csproj @@ -44,8 +44,8 @@ False ..\..\..\..\..\lib\moq\Moq.dll - - ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dllHintPath> ..\..\..\..\..\lib\nunit\nunit.framework.dll diff --git a/src/Orchard.Web/Modules/Orchard.Resources/Web.config b/src/Orchard.Web/Modules/Orchard.Resources/Web.config index 0a4b7f43f38..68c59f718e3 100644 --- a/src/Orchard.Web/Modules/Orchard.Resources/Web.config +++ b/src/Orchard.Web/Modules/Orchard.Resources/Web.config @@ -60,7 +60,7 @@ - +