public void InvalidTzName() { string tzName = "Lunar Standard Time"; var html = CreateHtmlHelper(new ViewDataDictionary()); SrkHtmlExtensions.SetTimezone(html, tzName); }
public void EmptyTzName() { string tzName = string.Empty; var html = CreateHtmlHelper(new ViewDataDictionary()); SrkHtmlExtensions.SetTimezone(html, tzName); }
public void NationalUsaStandardFormat() { string phone = "123-456-7890"; string expected = @"<a class=""tel"" href=""tel:" + phone + @""">" + phone + "</a>"; var result = SrkHtmlExtensions.CallLink(null, phone); Assert.AreEqual(expected, result.ToString()); }
public void EmptyDescriptionReturnsEmptyString() { var model = new TestModel(); var html = this.GetHtmlHeper <TestModel>(model); var result = SrkHtmlExtensions.DescriptionFor(html, m => m.Description); Assert.IsNull(result.ToString().NullIfEmpty()); }
public void ForIsValidAtLevel1() { var model = new TestModel(); var html = this.GetHtmlHeper <TestModel>(model); var result = SrkHtmlExtensions.DescriptionFor(html, m => m.Description2); Assert.AreEqual("<span data-for=\"Description2\">Desc a2a</span>", result.ToString().NullIfEmpty()); }
public void AcceptsHtmlAttributes() { var model = new TestModel(); var html = this.GetHtmlHeper <TestModel>(model); var result = SrkHtmlExtensions.DescriptionFor(html, m => m.Description2, new { attr1 = "value", }); Assert.AreEqual("<span attr1=\"value\" data-for=\"Description2\">Desc a2a</span>", result.ToString().NullIfEmpty()); }
public void InternationalFrenchStandardFormat() { string phone = "+33 123456789"; string expected = @"<a class=""tel"" href=""tel:" + phone + @""">" + phone + "</a>"; var result = SrkHtmlExtensions.CallLink(null, phone); Assert.AreEqual(expected, result.ToString()); }
public void BugWithSingleQuoteAndTwotter() { var input = "J'ai ajouté une"; var expected = "J'ai ajouté une"; var result = SrkHtmlExtensions.DisplayText(null, input, twitterLinks: true, makeParagraphs: false); SrkToolkit.Testing.Assert.AreEqual(expected, result.ToString()); }
public void BackAndForth_UtcIn() { long epoch = 13912786171000L; // GMT: Sat, 01 Feb 2014 18:16:57 GMT DateTime utc = UnixEpoch.AddMilliseconds(epoch); var result = SrkHtmlExtensions.JsDate(null, utc); var expected = "new Date(13912786171000)"; Assert.AreEqual(expected, result.ToString()); }
public void WorksWithTzObject2() { var data = new ViewDataDictionary(); var tz = TimeZoneInfo.FindSystemTimeZoneById("Russia Time Zone 3"); var html = CreateHtmlHelper(data); SrkHtmlExtensions.SetTimezone(html, tz); Assert.IsNotNull(data["Timezone"]); Assert.AreEqual(tz, data["Timezone"]); }
public void ModelIsPropertyInvalid_ReturnsFalse() { var model = new TestModel { Name = null, }; var html = GetHtmlHelper(model); var result = SrkHtmlExtensions.HasOtherValidationErrors(html); Assert.IsFalse(result); }
public void ModelIsValid_Hides() { var model = new TestModel { Name = "hello", }; var html = GetHtmlHelper(model); var response = SrkHtmlExtensions.ValidationSummaryEx(html); var isDisplayed = response != null && response.ToString().Length > 0; Assert.IsFalse(isDisplayed); }
public void BackAndForth_LocalTzIn() { long epoch = 13912786171000L; // GMT: Sat, 01 Feb 2014 18:16:57 GMT DateTime utc = UnixEpoch.AddMilliseconds(epoch); DateTime local = utc.ToLocalTime(); var html = CreateHtmlHelper(new ViewDataDictionary()); var result = SrkHtmlExtensions.JsDate(html, local); var expected = "new Date(13912786171000)"; Assert.AreEqual(expected, result.ToString()); }
public void WorksWithTzName1() { var data = new ViewDataDictionary(); var tzName = "Romance Standard Time"; var tz = TimeZoneInfo.FindSystemTimeZoneById(tzName); var html = CreateHtmlHelper(data); SrkHtmlExtensions.SetTimezone(html, tzName); Assert.IsNotNull(data["Timezone"]); Assert.AreEqual(tz, data["Timezone"]); }
public void WorksWhenSetInHttpContext2() { var data = new ViewDataDictionary(); var tzName = "Russia Time Zone 3"; var tz = TimeZoneInfo.FindSystemTimeZoneById(tzName); var html = CreateHtmlHelper(data); html.ViewContext.HttpContext.SetTimezone(tz); var result = SrkHtmlExtensions.GetTimezone(html); Assert.IsNotNull(result); Assert.AreEqual(tz, result); }
public void ModelIsOtherInvalid_Shows() { var model = new TestModel { Name = "hello", }; var html = GetHtmlHelper(model); html.ViewData.ModelState.AddModelError(string.Empty, "Other error"); var response = SrkHtmlExtensions.ValidationSummaryEx(html); var isDisplayed = response != null && response.ToString().Length > 0; Assert.IsTrue(isDisplayed); }
public void ModelIsOtherInvalid_ReturnsFalse() { var model = new TestModel { Name = "hello", }; var html = GetHtmlHelper(model); html.ViewData.ModelState.AddModelError(string.Empty, "Other error"); var result = SrkHtmlExtensions.HasOtherValidationErrors(html); Assert.IsTrue(result); }
public void GetterWorks2() { var data = new ViewDataDictionary(); var tzName = "Russia Time Zone 3"; var tz = TimeZoneInfo.FindSystemTimeZoneById(tzName); var html = CreateHtmlHelper(data); SrkHtmlExtensions.SetTimezone(html, tzName); var result = SrkHtmlExtensions.GetTimezone(html); Assert.IsNotNull(result); Assert.AreEqual(tz, result); }
public void UserIsUtc_ArgIsUtc_ResultIsUtc() { Thread.CurrentThread.CurrentCulture = TestCulture1; DateTime source = new DateTime(2013, 1, 29, 13, 28, 21, 1, DateTimeKind.Utc); TimeZoneInfo tz = null; string expected = "<time datetime=\"2013-01-29T13:28:21.0010000Z\" title=\"29/01/2013 13:28:21\" class=\"past not-today display-time\">13:28:21</time>"; var html = CreateHtmlHelper(new ViewDataDictionary()); html.SetTimezone(tz); var result = SrkHtmlExtensions.DisplayTime(html, source); Assert.AreEqual(expected, result.ToString()); }
public void UndefinedTzIsUtc_ArgIsUtc_ResultIsUtc() { DateTime source = new DateTime(2013, 1, 29, 13, 28, 21, 1, DateTimeKind.Utc); TimeZoneInfo tz = null; var html = CreateHtmlHelper(new ViewDataDictionary()); html.SetTimezone(tz); DateTime utcResult; var result = SrkHtmlExtensions.GetUserDate(html, source, out utcResult); Assert.AreEqual(source, result); Assert.AreEqual(source, utcResult); }
public void BackAndForth_UserTzIn() { long epoch = 13912786171000L; // GMT: Sat, 01 Feb 2014 18:16:57 GMT DateTime utc = UnixEpoch.AddMilliseconds(epoch); TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time"); DateTime user = tz.ConvertFromUtc(utc); var html = CreateHtmlHelper(new ViewDataDictionary()); html.SetTimezone(tz); var result = SrkHtmlExtensions.JsDate(html, user); var expected = "new Date(13912786171000)"; Assert.AreEqual(expected, result.ToString()); }
public void RomanceTz_ArgIsUtc_ResultIsRomance() { TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time"); DateTime orig = new DateTime(2013, 1, 29, 13, 28, 21, 1, DateTimeKind.Utc); DateTime source = tz.ConvertFromUtc(orig); var html = CreateHtmlHelper(new ViewDataDictionary()); html.SetTimezone(tz); DateTime utcResult; var result = SrkHtmlExtensions.GetUserDate(html, source, out utcResult); Assert.AreEqual(source, result, "wrong user result"); Assert.AreEqual(orig, utcResult, "wrong UTC result"); }
public void UserIsRomance_ArgIsUtc_ResultIsRomance() { Thread.CurrentThread.CurrentCulture = TestCulture1; TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time"); DateTime source = new DateTime(2013, 1, 29, 13, 28, 21, 1, DateTimeKind.Utc); DateTime romance = tz.ConvertFromUtc(source); string expected = "<time datetime=\"2013-01-29T13:28:21.0010000Z\" title=\"29/01/2013 14:28:21\" class=\"past not-today display-datetime\">29 January 2013 14:28:21</time>"; var html = CreateHtmlHelper(new ViewDataDictionary()); html.SetTimezone(tz); var result = SrkHtmlExtensions.DisplayDateTime(html, source); Assert.AreEqual(expected, result.ToString()); }
public void UserIsUtc_ArgIsLocal_ResultIsUtc() { Thread.CurrentThread.CurrentCulture = TestCulture1; var localTz = TimeZoneInfo.Local; DateTime orig = new DateTime(2013, 1, 29, 13, 28, 21, 1, DateTimeKind.Utc); DateTime source = orig.ToLocalTime(); Debug.Assert(source.Kind == DateTimeKind.Local); TimeZoneInfo tz = null; string expected = "<time datetime=\"2013-01-29T" + orig.Hour + ":28:21.0010000Z\" title=\"29/01/2013 13:28:21\" class=\"past not-today display-datetime\">29 January 2013 13:28:21</time>"; var html = CreateHtmlHelper(new ViewDataDictionary()); html.SetTimezone(tz); var result = SrkHtmlExtensions.DisplayDateTime(html, source); Assert.AreEqual(expected, result.ToString()); }
public void ThrowsWhenArg0IsNull() { SrkHtmlExtensions.HasOtherValidationErrors(null); }