예제 #1
0
        public void FormatStringFormaterTest()
        {
            try
            {
                var f = new StringFormater {
                    Format = ""
                };
                f.Formate("");
                throw new Exception("TEST FAILED.");
            }
            catch (SpiderException se)
            {
                Assert.Equal("FormatString should not be null or empty.", se.Message);
            }
            try
            {
                var f = new StringFormater {
                    Format = null
                };
                f.Formate("");
                throw new Exception("TEST FAILED.");
            }
            catch (SpiderException se)
            {
                Assert.Equal("FormatString should not be null or empty.", se.Message);
            }
            try
            {
                var f = new StringFormater {
                    Format = "     "
                };
                f.Formate("");
                throw new Exception("TEST FAILED.");
            }
            catch (SpiderException se)
            {
                Assert.Equal("FormatString should not be null or empty.", se.Message);
            }

            StringFormater formatter1 = new StringFormater {
                Format = "http://{0}"
            };

            Assert.Equal("http://a", formatter1.Formate("a"));

            StringFormater formatter2 = new StringFormater {
                Format = "http://{0}/{1}"
            };

            Assert.Equal("http://a/b", formatter2.Formate(new[] { "a", "b" }));
        }