/
anton.bessolitsyn
/
easyapiTests
Обзор
Документация
Войти
/
anton.bessolitsyn
/
easyapiTests
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Utilities/StyleOptionHelperTests.cs
137 строк
5 KB
Anton Bessolitsyn
Работа над кодом (читаемость именование переменных)
07 мар 2025, 18:09
07 мар 2025, 18:09
c3294b1
Код
Авторство
О чём код?
using Microsoft.VisualStudio.TestTools.UnitTesting; using easyapi.Utilities; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace easyapi.Utilities.Tests { [TestClass()] public class StyleOptionHelperTests { [TestMethod()] [DataRow("normal text bold", "normal text <b>bold</b>")] [DataRow("normal text bold normal text", "normal text <b>bold</b> normal text")] [DataRow("normal text bold normal text italic text not bold", "normal text <b>bold</b> normal text <i>italic</i> text not bold")] public void FormatToHtmlTest1(string text, string formatedText) { Dictionary<string, string>[] sample = [ new Dictionary<string, string>() { { "type", "Unknown"}, { "offset", "12" }, { "length", "4" }, { "url", "" } }, new Dictionary<string, string>() { { "type", "Bold"}, { "offset", "12" }, { "length", "4" }, { "url", "" } }, new Dictionary<string, string>() { { "type", "Italic"}, { "offset", "29" }, { "length", "6" }, { "url", "" } }, new Dictionary<string, string>() { { "type", "Bold"}, { "offset", "1000" }, { "length", "4" }, { "url", "" } } ]; var result = StyleOptionHelper.ApplyStyleOptionsToTextAsHtml(text, sample); Assert.IsTrue(string.Equals(result, formatedText)); } [TestMethod()] [DataRow("text bolditalicbold", "text <b>bold<i>italic</i>bold</b>")] public void FormatToHtmlTest3(string text, string formatedText) { Dictionary<string, string>[] sample = [ new Dictionary<string, string>() { { "type", "Bold"}, { "offset", "5" }, { "length", "14" }, { "url", "" } }, new Dictionary<string, string>() { { "type", "Italic"}, { "offset", "9" }, { "length", "6" }, { "url", "" } }, ]; var result = StyleOptionHelper.ApplyStyleOptionsToTextAsHtml(text, sample); Assert.IsTrue(String.Equals(result, formatedText)); } [TestMethod()] [DataRow("0123456789abcdef", "01<i>23<b>45</b>67<b>89</b>ab</i>cdef")] public void FormatToHtmlTest4(string text, string formatedText) { Dictionary<string, string>[] sample = [ new Dictionary<string, string>() { { "type", "Bold"}, { "offset", "4" }, { "length", "2" }, { "url", "" } }, new Dictionary<string, string>() { { "type", "Bold"}, { "offset", "8" }, { "length", "2" }, { "url", "" } }, new Dictionary<string, string>() { { "type", "Italic"}, { "offset", "2" }, { "length", "10" }, { "url", "" } } ]; var result = StyleOptionHelper.ApplyStyleOptionsToTextAsHtml(text, sample); Assert.IsTrue(String.Equals(result, formatedText)); } [TestMethod()] [DataRow("0123456789abcdef", "0123456789a<a href=\"https://disk.yandex.ru/\"><b><i>bc</i></b></a>def")] public void FormatToHtmlTest5(string text, string formatedText) { Dictionary<string, string>[] sample = [ new Dictionary<string, string>() { { "type", "TextLink"}, { "offset", "11" }, { "length", "2" }, { "url", "https://disk.yandex.ru/" } }, new Dictionary<string, string>() { { "type", "Bold"}, { "offset", "11" }, { "length", "2" }, { "url", "" } }, new Dictionary<string, string>() { { "type", "Italic"}, { "offset", "11" }, { "length", "2" }, { "url", "" } } ]; var result = StyleOptionHelper.ApplyStyleOptionsToTextAsHtml(text, sample); Assert.IsTrue(String.Equals(result, formatedText)); } } }