コード例 #1
0
            public void InvalidTzName()
            {
                string tzName = "Lunar Standard Time";
                var    html   = CreateHtmlHelper(new ViewDataDictionary());

                SrkHtmlExtensions.SetTimezone(html, tzName);
            }
コード例 #2
0
            public void EmptyTzName()
            {
                string tzName = string.Empty;
                var    html   = CreateHtmlHelper(new ViewDataDictionary());

                SrkHtmlExtensions.SetTimezone(html, tzName);
            }
コード例 #3
0
            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());
            }
コード例 #4
0
            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());
            }
コード例 #5
0
            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());
            }
コード例 #6
0
            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());
            }
コード例 #7
0
            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());
            }
コード例 #8
0
            public void BugWithSingleQuoteAndTwotter()
            {
                var input    = "J'ai ajouté une";
                var expected = "J&#x27;ai ajouté une";
                var result   = SrkHtmlExtensions.DisplayText(null, input, twitterLinks: true, makeParagraphs: false);

                SrkToolkit.Testing.Assert.AreEqual(expected, result.ToString());
            }
コード例 #9
0
            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());
            }
コード例 #10
0
            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"]);
            }
コード例 #11
0
            public void ModelIsPropertyInvalid_ReturnsFalse()
            {
                var model = new TestModel {
                    Name = null,
                };
                var html = GetHtmlHelper(model);

                var result = SrkHtmlExtensions.HasOtherValidationErrors(html);

                Assert.IsFalse(result);
            }
コード例 #12
0
            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);
            }
コード例 #13
0
            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());
            }
コード例 #14
0
            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"]);
            }
コード例 #15
0
            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);
            }
コード例 #16
0
            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);
            }
コード例 #17
0
            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);
            }
コード例 #18
0
            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);
            }
コード例 #19
0
            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());
            }
コード例 #20
0
            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);
            }
コード例 #21
0
            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());
            }
コード例 #22
0
            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");
            }
コード例 #23
0
            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());
            }
コード例 #24
0
            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());
            }
コード例 #25
0
 public void ThrowsWhenArg0IsNull()
 {
     SrkHtmlExtensions.HasOtherValidationErrors(null);
 }