示例#1
0
 public void ParseNullableDecimalFromCurrencyString()
 {
     Assert.That(StringFormats.ParseNullableDecimalFromCurrencyString("$100"), Is.EqualTo(100m));
     Assert.That(StringFormats.ParseNullableDecimalFromCurrencyString("$200,000"), Is.EqualTo(200000m));
     Assert.That(StringFormats.ParseNullableDecimalFromCurrencyString("$100.10"), Is.EqualTo(100.10m));
     Assert.That(StringFormats.ParseNullableDecimalFromCurrencyString("-$100.10"), Is.EqualTo(-100.10m));
     Assert.That(StringFormats.ParseNullableDecimalFromCurrencyString("($100.10)"), Is.EqualTo(-100.10m));
 }
示例#2
0
 public void FormatFileSizeHumanReadableTest()
 {
     Assert.That(StringFormats.ToHumanReadableByteSize(0), Is.EqualTo("0 B"));
     Assert.That(StringFormats.ToHumanReadableByteSize(1024), Is.EqualTo("1 KB"));
     Assert.That(StringFormats.ToHumanReadableByteSize(1024 * 1024), Is.EqualTo("1 MB"));
     Assert.That(StringFormats.ToHumanReadableByteSize(1024 * 1024 + 512 * 1024), Is.EqualTo("1.5 MB"));
     Assert.That(StringFormats.ToHumanReadableByteSize(1024 * 1024 + 231 * 1024), Is.EqualTo("1.23 MB"));
     Assert.That(StringFormats.ToHumanReadableByteSize(1024 * 1024 * 1024), Is.EqualTo("1 GB"));
     Assert.That(StringFormats.ToHumanReadableByteSize(1024L * 1024L * 1024L * 1024L), Is.EqualTo("1 TB"));
     Assert.That(StringFormats.ToHumanReadableByteSize(1024L * 1024L * 1024L * 1024L * 1024L), Is.EqualTo("1 PB"));
     Assert.That(StringFormats.ToHumanReadableByteSize(1024L * 1024L * 1024L * 1024L * 1024L * 1024L), Is.EqualTo("1 EB"));
 }
        public void IsRegexToFindAbsoluteUrlsWorking()
        {
            var regExToUse = StringFormats.ConstructContainAbsoluteUrlWithApplicationDomainReferenceRegExForApplicationDomain("someapp.somedomain.org");
            var regEx      = new Regex(regExToUse, RegexOptions.IgnoreCase | RegexOptions.Multiline);

            Trace.WriteLine(string.Format("Non-server root relative Regex string: {0}", regExToUse));
            Assert.That(((string)null).DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.False, "Null string - can't be bad");
            Assert.That("".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.False, "Empty string - can't be bad");
            Assert.That("ABC".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.False, "Simple string - can't be bad");
            Assert.That("\"../../SomeAction".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.False, "not server root relative but we don't care for this case");
            Assert.That("http://qa.someapp.somedomain.org/".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.True, "should be bad - not server root relative");
            Assert.That("http://someapp.somedomain.org/".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.True, "should be bad - not server root relative");
            Assert.That("https://someapp.somedomain.org/".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.True, "should be bad - not server root relative");
            Assert.That("https://qa.someapp.somedomain.org/".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.True, "should be bad - not server root relative");
            Assert.That("http://someapp.somedomain.org/Project/Index".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.True, "should be bad - not server root relative");
            Assert.That("http://qa.someapp.somedomain.org/Project/Index".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.True, "should be bad - not server root relative");
            Assert.That("https://someapp.somedomain.org/Project/Index".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.True, "should be bad - not server root relative");
            Assert.That("https://qa.someapp.somedomain.org/Project/Index".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.True, "should be bad - not server root relative");
            Assert.That("/Project/Index".DoesHtmlStringContainAbsoluteUrlWithApplicationDomainReference(regEx), Is.False, "Should be fine -- is server root relative");
        }
示例#4
0
        public void MakeAbsoluteLinksToApplicationDomainRelativeNullTest()
        {
            var result = StringFormats.MakeAbsoluteLinksToApplicationDomainRelative(null);

            Assert.That(result, Is.Null);
        }