Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Mvc/HtmlStringUtilitiesTests.cs

51 lines
1.5 KiB
C#
Raw Normal View History

// Copyright (c) Umbraco.
// See LICENSE for more details.
using NUnit.Framework;
using Umbraco.Cms.Web.Common.Mvc;
2017-09-19 15:51:47 +02:00
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Mvc
2017-09-19 15:51:47 +02:00
{
[TestFixture]
public class HtmlStringUtilitiesTests
{
private HtmlStringUtilities _htmlStringUtilities;
[SetUp]
public virtual void Initialize() => _htmlStringUtilities = new HtmlStringUtilities();
2017-09-19 15:51:47 +02:00
2018-03-27 17:59:53 +02:00
[Test]
public void TruncateWithElipsis()
{
string output = _htmlStringUtilities.Truncate("hello world", 5, true, false).ToString();
2018-03-27 17:59:53 +02:00
var expected = "hello…";
Assert.AreEqual(expected, output);
}
[Test]
public void TruncateWithoutElipsis()
{
string output = _htmlStringUtilities.Truncate("hello world", 5, false, false).ToString();
2018-03-27 17:59:53 +02:00
var expected = "hello";
Assert.AreEqual(expected, output);
}
[Test]
public void TruncateShorterWordThanHellip()
{
// http://issues.umbraco.org/issue/U4-10478
2018-03-27 17:59:53 +02:00
var output = _htmlStringUtilities.Truncate("hi", 5, true, false).ToString();
var expected = "hi";
Assert.AreEqual(expected, output);
}
[Test]
public void TruncateAndRemoveSpaceBetweenHellipAndWord()
{
var output = _htmlStringUtilities.Truncate("hello world", 6 /* hello plus space */, true, false).ToString();
var expected = "hello…";
Assert.AreEqual(expected, output);
}
2017-09-19 15:51:47 +02:00
}
2018-09-06 14:10:10 +02:00
}