Skip to content

Commit

Permalink
Merge pull request #4655 from manojattal/Issue4654
Browse files Browse the repository at this point in the history
Fix for #4654: Unable to Upload File into Assets On Turkish Localization
  • Loading branch information
mitchelsellers authored Jun 8, 2021
2 parents 91d3ead + 77e634d commit da4d732
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public Task<HttpResponseMessage> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public static Mock<RoleProvider> CreateRoleProvider()
{
return CreateNew<RoleProvider>();
}

public static Mock<IPortalController> CreatePortalController()
{
return CreateNew<IPortalController>();
}

public static void ResetContainer()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="DependencyInjection\BuildUpExtensionsTests.cs" />
<Compile Include="DependencyInjection\BuildUpExtensions_SampleFilters.cs" />
<Compile Include="InternalServices\FakeModuleCrawlerController.cs" />
<Compile Include="InternalServices\FileUploadControllerTests.cs" />
<Compile Include="InternalServices\SearchServiceControllerTests.cs">
<SubType>Code</SubType>
</Compile>
Expand Down Expand Up @@ -139,6 +140,10 @@
<Project>{0FCA217A-5F9A-4F5B-A31B-86D64AE65198}</Project>
<Name>DotNetNuke.DependencyInjection</Name>
</ProjectReference>
<ProjectReference Include="..\..\DotNetNuke.Instrumentation\DotNetNuke.Instrumentation.csproj">
<Project>{3cd5f6b8-8360-4862-80b6-f402892db7dd}</Project>
<Name>DotNetNuke.Instrumentation</Name>
</ProjectReference>
<ProjectReference Include="..\..\DotNetNuke.Log4net\DotNetNuke.Log4Net.csproj">
<Project>{04f77171-0634-46e0-a95e-d7477c88712e}</Project>
<Name>DotNetNuke.Log4Net</Name>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
/// <summary>
/// Tests FileUploadController methods
/// </summary>
[TestFixture]
public class FileUploadControllerTests
{
private Mock<DataProvider> _mockDataProvider;
private FileUploadController _testInstance;
private Mock<CachingProvider> _mockCachingProvider;
private Mock<IPortalController> _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<int>()))
.Returns(Mock.Of<IDataReader>());
}

private void SetupCachingProvider()
{
this._mockCachingProvider = MockComponentProvider.CreateDataCacheProvider();
this._mockCachingProvider.Setup(x => x.GetItem(It.IsAny<string>()))
.Returns(Enumerable.Empty<ListEntryInfo>());
}

private void SetupServiceProvider()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddTransient<IApplicationStatusInfo>(
container => new Application.ApplicationStatusInfo(Mock.Of<IApplicationInfo>()));
serviceCollection.AddTransient(container => Mock.Of<INavigationManager>());
serviceCollection.AddTransient(container => Mock.Of<IEventLogger>());
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;
}
}
}
}

0 comments on commit da4d732

Please # to comment.