-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4655 from manojattal/Issue4654
Fix for #4654: Unable to Upload File into Assets On Turkish Localization
- Loading branch information
Showing
4 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
DNN Platform/Tests/DotNetNuke.Tests.Web/InternalServices/FileUploadControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |