Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Add tests

support2bd854f3e536
diff --git a/src/Core/Grand.SharedKernel/Extensions/FormatText.cs b/src/Core/Grand.SharedKernel/Extensions/FormatText.cs
index 28e36b350..48fb93d32 100644
--- a/src/Core/Grand.SharedKernel/Extensions/FormatText.cs
+++ b/src/Core/Grand.SharedKernel/Extensions/FormatText.cs
@@ -12,10 +12,7 @@ namespace Grand.SharedKernel.Extensions
text = WebUtility.HtmlEncode(text);
text = text.Replace("\r\n", "<br />");
- text = text.Replace("\r", "<br />");
- text = text.Replace("\n", "<br />");
text = text.Replace("\t", "&nbsp;&nbsp;");
- text = text.Replace(" ", "&nbsp;&nbsp;");
return text;
}
diff --git a/src/Tests/Grand.SharedKernel.Tests/Extensions/ExtendedLinqTests.cs b/src/Tests/Grand.SharedKernel.Tests/Extensions/ExtendedLinqTests.cs
new file mode 100644
index 000000000..34f7fd661
--- /dev/null
+++ b/src/Tests/Grand.SharedKernel.Tests/Extensions/ExtendedLinqTests.cs
@@ -0,0 +1,28 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Grand.SharedKernel.Extensions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Grand.SharedKernel.Tests;
+
+namespace Grand.SharedKernel.Extensions.Tests
+{
+ [TestClass()]
+ public class ExtendedLinqTests
+ {
+ [TestMethod()]
+ public void CartesianProductTest()
+ {
+ var sampleList = new List<SampleObject>() {
+ new SampleObject() { Id = "1", Name = "name1" },
+ new SampleObject() { Id = "1", Name = "name2" },
+ new SampleObject() { Id = "3", Name = "name3" }
+ };
+
+ var cartesianProduct = sampleList.GroupBy(x=>x.Id).CartesianProduct().ToList();
+ Assert.AreEqual(2, cartesianProduct.Count);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.SharedKernel.Tests/Extensions/FormatTextTests.cs b/src/Tests/Grand.SharedKernel.Tests/Extensions/FormatTextTests.cs
new file mode 100644
index 000000000..2387545ba
--- /dev/null
+++ b/src/Tests/Grand.SharedKernel.Tests/Extensions/FormatTextTests.cs
@@ -0,0 +1,25 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Grand.SharedKernel.Extensions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Grand.SharedKernel.Extensions.Tests
+{
+ [TestClass()]
+ public class FormatTextTests
+ {
+
+ [TestMethod()]
+ [DataRow("sample <br /> sample ")]
+ [DataRow("&nbsp;&nbsp; sample <br /> sample &nbsp;&nbsp;")]
+ public void ConvertTextTest(string text)
+ {
+ Assert.IsFalse(FormatText.ConvertText(text).Contains("<br"));
+ Assert.IsFalse(FormatText.ConvertText(text).Contains("&nbsp;&nbsp;"));
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.SharedKernel.Tests/SampleObject.cs b/src/Tests/Grand.SharedKernel.Tests/SampleObject.cs
new file mode 100644
index 000000000..a323abe3e
--- /dev/null
+++ b/src/Tests/Grand.SharedKernel.Tests/SampleObject.cs
@@ -0,0 +1,8 @@
+namespace Grand.SharedKernel.Tests;
+
+public class SampleObject
+{
+ public string Id { get; set; }
+ public string Name { get; set; }
+
+}