mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 21:13:35 +08:00
- Making some adjustments to the previous contributions.
- Unit tests for StringExtensions belongs to the Utility\ folder. - Unit tests files are named after classes. - Use localizedstrings via the T localizer injected as a controller property instead of plain strings.
This commit is contained in:
@@ -148,7 +148,6 @@
|
|||||||
<Compile Include="EventsTests.cs" />
|
<Compile Include="EventsTests.cs" />
|
||||||
<Compile Include="Extensions\ExtensionFoldersTests.cs" />
|
<Compile Include="Extensions\ExtensionFoldersTests.cs" />
|
||||||
<Compile Include="Extensions\ExtensionManagerTests.cs" />
|
<Compile Include="Extensions\ExtensionManagerTests.cs" />
|
||||||
<Compile Include="Extensions\NullOrEmptyTrimmedStringExtensionsTests.cs" />
|
|
||||||
<Compile Include="Localization\NullLocalizerTests.cs" />
|
<Compile Include="Localization\NullLocalizerTests.cs" />
|
||||||
<Compile Include="Logging\LoggingModuleTests.cs" />
|
<Compile Include="Logging\LoggingModuleTests.cs" />
|
||||||
<Compile Include="Mvc\ModelBinders\KeyedListModelBinderTests.cs" />
|
<Compile Include="Mvc\ModelBinders\KeyedListModelBinderTests.cs" />
|
||||||
@@ -176,6 +175,7 @@
|
|||||||
<Compile Include="UI\Navigation\MenuItemComparerTests.cs" />
|
<Compile Include="UI\Navigation\MenuItemComparerTests.cs" />
|
||||||
<Compile Include="UI\Navigation\NavigationManagerTests.cs" />
|
<Compile Include="UI\Navigation\NavigationManagerTests.cs" />
|
||||||
<Compile Include="UI\Navigation\PositionComparerTests.cs" />
|
<Compile Include="UI\Navigation\PositionComparerTests.cs" />
|
||||||
|
<Compile Include="Utility\Extensions\StringExtensionsTests.cs" />
|
||||||
<Compile Include="Utility\ReflectOnTests.cs" />
|
<Compile Include="Utility\ReflectOnTests.cs" />
|
||||||
<Compile Include="Utility\ReflectTests.cs" />
|
<Compile Include="Utility\ReflectTests.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@@ -1,31 +1,29 @@
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.Extensions;
|
using Orchard.Extensions;
|
||||||
|
|
||||||
namespace Orchard.Tests.Extensions
|
namespace Orchard.Tests.Utility.Extensions {
|
||||||
{
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class NullOrEmptyTrimmedStringExtensionsTests
|
public class StringExtensionsTests {
|
||||||
{
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Trimmed_EmptyStringReturnsTrue() {
|
public void IsNullOrEmptyTrimmed_EmptyStringReturnsTrue() {
|
||||||
const string testString = "";
|
const string testString = "";
|
||||||
Assert.AreEqual(true, testString.IsNullOrEmptyTrimmed());
|
Assert.AreEqual(true, testString.IsNullOrEmptyTrimmed());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void NullStringReturnsTrue() {
|
public void IsNullOrEmptyTrimmed_NullStringReturnsTrue() {
|
||||||
const string testString = null;
|
const string testString = null;
|
||||||
Assert.AreEqual(true, testString.IsNullOrEmptyTrimmed());
|
Assert.AreEqual(true, testString.IsNullOrEmptyTrimmed());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SpacedStringReturnsTrue() {
|
public void IsNullOrEmptyTrimmed_SpacedStringReturnsTrue() {
|
||||||
const string testString = " ";
|
const string testString = " ";
|
||||||
Assert.AreEqual(true, testString.IsNullOrEmptyTrimmed());
|
Assert.AreEqual(true, testString.IsNullOrEmptyTrimmed());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ActualStringReturnsFalse() {
|
public void IsNullOrEmptyTrimmed_ActualStringReturnsFalse() {
|
||||||
const string testString = "testString";
|
const string testString = "testString";
|
||||||
Assert.AreEqual(false, testString.IsNullOrEmptyTrimmed());
|
Assert.AreEqual(false, testString.IsNullOrEmptyTrimmed());
|
||||||
}
|
}
|
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Extensions;
|
using Orchard.Extensions;
|
||||||
@@ -140,32 +139,28 @@ namespace Orchard.Media.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Add()
|
public ActionResult Add() {
|
||||||
{
|
|
||||||
var viewModel = new MediaItemAddViewModel();
|
var viewModel = new MediaItemAddViewModel();
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
UpdateModel(viewModel);
|
UpdateModel(viewModel);
|
||||||
if (!Services.Authorizer.Authorize(Permissions.UploadMediaFiles, T("Couldn't upload media file")))
|
if (!Services.Authorizer.Authorize(Permissions.UploadMediaFiles, T("Couldn't upload media file")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
if(Request.Files[0].FileName.IsNullOrEmptyTrimmed()) {
|
if(Request.Files[0].FileName.IsNullOrEmptyTrimmed()) {
|
||||||
ModelState.AddModelError("File", "Select a file to upload");
|
ModelState.AddModelError("File", T("Select a file to upload").ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
|
|
||||||
foreach (string fileName in Request.Files)
|
foreach (string fileName in Request.Files) {
|
||||||
{
|
|
||||||
HttpPostedFileBase file = Request.Files[fileName];
|
HttpPostedFileBase file = Request.Files[fileName];
|
||||||
_mediaService.UploadMediaFile(viewModel.MediaPath, file);
|
_mediaService.UploadMediaFile(viewModel.MediaPath, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectToAction("Edit", new { name = viewModel.FolderName, mediaPath = viewModel.MediaPath });
|
return RedirectToAction("Edit", new { name = viewModel.FolderName, mediaPath = viewModel.MediaPath });
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception) {
|
||||||
{
|
|
||||||
Services.Notifier.Error("Uploading media file failed: " + exception.Message);
|
Services.Notifier.Error("Uploading media file failed: " + exception.Message);
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Text.RegularExpressions;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace Orchard.Extensions {
|
namespace Orchard.Extensions {
|
||||||
public static class StringExtensions {
|
public static class StringExtensions {
|
||||||
@@ -16,8 +15,7 @@ namespace Orchard.Extensions {
|
|||||||
return cleanTailRegex.Replace(text.Substring(0, characterCount + 1), "") + ellipsis;
|
return cleanTailRegex.Replace(text.Substring(0, characterCount + 1), "") + ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsNullOrEmptyTrimmed(this string text)
|
public static bool IsNullOrEmptyTrimmed(this string text) {
|
||||||
{
|
|
||||||
if(text == null) return true;
|
if(text == null) return true;
|
||||||
return string.IsNullOrEmpty(text.Trim());
|
return string.IsNullOrEmpty(text.Trim());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user