diff --git a/DNN Platform/DotNetNuke.Web/InternalServices/FileUploadController.cs b/DNN Platform/DotNetNuke.Web/InternalServices/FileUploadController.cs index 0b412dddeb7..991441a9660 100644 --- a/DNN Platform/DotNetNuke.Web/InternalServices/FileUploadController.cs +++ b/DNN Platform/DotNetNuke.Web/InternalServices/FileUploadController.cs @@ -343,7 +343,7 @@ public Task UploadFromLocal(int portalId) foreach (var item in provider.Contents) { var name = item.Headers.ContentDisposition.Name; - switch (name.ToUpper()) + switch (name.ToUpperInvariant()) { case "\"FOLDER\"": folder = item.ReadAsStringAsync().Result ?? string.Empty; diff --git a/DNN Platform/Tests/DotNetNuke.Tests.Utilities/Mocks/MockComponentProvider.cs b/DNN Platform/Tests/DotNetNuke.Tests.Utilities/Mocks/MockComponentProvider.cs index 90372fc9d79..5e126821a42 100644 --- a/DNN Platform/Tests/DotNetNuke.Tests.Utilities/Mocks/MockComponentProvider.cs +++ b/DNN Platform/Tests/DotNetNuke.Tests.Utilities/Mocks/MockComponentProvider.cs @@ -102,6 +102,11 @@ public static Mock CreateRoleProvider() { return CreateNew(); } + + public static Mock CreatePortalController() + { + return CreateNew(); + } public static void ResetContainer() { diff --git a/DNN Platform/Tests/DotNetNuke.Tests.Web/DotNetNuke.Tests.Web.csproj b/DNN Platform/Tests/DotNetNuke.Tests.Web/DotNetNuke.Tests.Web.csproj index d0ff99bcb02..6216eb99b9d 100644 --- a/DNN Platform/Tests/DotNetNuke.Tests.Web/DotNetNuke.Tests.Web.csproj +++ b/DNN Platform/Tests/DotNetNuke.Tests.Web/DotNetNuke.Tests.Web.csproj @@ -108,6 +108,7 @@ + Code @@ -139,6 +140,10 @@ {0FCA217A-5F9A-4F5B-A31B-86D64AE65198} DotNetNuke.DependencyInjection + + {3cd5f6b8-8360-4862-80b6-f402892db7dd} + DotNetNuke.Instrumentation + {04f77171-0634-46e0-a95e-d7477c88712e} DotNetNuke.Log4Net diff --git a/DNN Platform/Tests/DotNetNuke.Tests.Web/InternalServices/FileUploadControllerTests.cs b/DNN Platform/Tests/DotNetNuke.Tests.Web/InternalServices/FileUploadControllerTests.cs new file mode 100644 index 00000000000..e3f5d8251ab --- /dev/null +++ b/DNN Platform/Tests/DotNetNuke.Tests.Web/InternalServices/FileUploadControllerTests.cs @@ -0,0 +1,125 @@ +namespace DotNetNuke.Tests.Web.InternalServices +{ + using System.Data; + using System.Linq; + using System.Net.Http; + using System.Threading; + using System.Threading.Tasks; + using Abstractions; + using Abstractions.Application; + using Abstractions.Logging; + + using Common; + using Common.Lists; + + using Data; + using DotNetNuke.Entities.Portals; + using DotNetNuke.Web.InternalServices; + + using Microsoft.Extensions.DependencyInjection; + + using Moq; + + using NUnit.Framework; + + using Services.Cache; + + using Utilities.Mocks; + /// + /// Tests FileUploadController methods + /// + [TestFixture] + public class FileUploadControllerTests + { + private Mock _mockDataProvider; + private FileUploadController _testInstance; + private Mock _mockCachingProvider; + private Mock _mockPortalController; + private TestSynchronizationContext _synchronizationContext = new TestSynchronizationContext(); + + [SetUp] + public void SetUp() + { + + this.SetupDataProvider(); + + this.SetupCachingProvider(); + + this.SetupPortalSettings(); + this.SetupServiceProvider(); + this.SetupSynchronizationContext(); + } + + [Test] + [SetCulture("tr-TR")] + public async Task UploadFromLocal_ShouldUploadFile_WithTrCultureAsync() + { + var formDataContent = new MultipartFormDataContent(); + formDataContent.Add(new StringContent("Hello World!"), "\"postfile\"", "\"testing\""); + + var request = new HttpRequestMessage(); + request.Content = formDataContent; + this._testInstance.Request = request; + await this._testInstance.UploadFromLocal(-1); + + Assert.IsTrue(_synchronizationContext.IsUploadFileCalled()); + } + + private void SetupPortalSettings() + { + _mockPortalController = MockComponentProvider.CreatePortalController(); + _mockPortalController.Setup(x => x.GetCurrentPortalSettings()).Returns(new PortalSettings() { PortalId = 0 }); + PortalController.SetTestableInstance(_mockPortalController.Object); + } + + private void SetupDataProvider() + { + this._mockDataProvider = MockComponentProvider.CreateDataProvider(); + this._mockDataProvider.Setup(x => x.GetListEntriesByListName("ImageTypes", string.Empty, It.IsAny())) + .Returns(Mock.Of()); + } + + private void SetupCachingProvider() + { + this._mockCachingProvider = MockComponentProvider.CreateDataCacheProvider(); + this._mockCachingProvider.Setup(x => x.GetItem(It.IsAny())) + .Returns(Enumerable.Empty()); + } + + private void SetupServiceProvider() + { + var serviceCollection = new ServiceCollection(); + serviceCollection.AddTransient( + container => new Application.ApplicationStatusInfo(Mock.Of())); + serviceCollection.AddTransient(container => Mock.Of()); + serviceCollection.AddTransient(container => Mock.Of()); + Globals.DependencyProvider = serviceCollection.BuildServiceProvider(); + } + + private void SetupSynchronizationContext() + { + _synchronizationContext = new TestSynchronizationContext(); + SynchronizationContext.SetSynchronizationContext(_synchronizationContext); + this._testInstance = new FileUploadController(); + } + + private class TestSynchronizationContext : SynchronizationContext + { + private bool isUploadFileCalled; + public override void Post(SendOrPostCallback d, object state) + { + d(state); + } + + public override void Send(SendOrPostCallback d, object state) + { + isUploadFileCalled = true; + } + + public bool IsUploadFileCalled() + { + return isUploadFileCalled; + } + } + } +}