コード例 #1
0
        public void TestMethodAssertLessThan()
        {
            var myLogger = new Stf.Utilities.StfLogger {
                FileName = @"c:\temp\unittestlogger_TestMethodAssertLessThan.html"
            };
            var myAsserts = new StfAssert(myLogger);
            var obj1      = new DateTime(42);
            var obj2      = new DateTime(4242);

            myAsserts.EnableNegativeTesting = true;

            Assert.IsFalse(myAsserts.AssertLessThan("2 < 1", 2, 1));
            Assert.IsFalse(myAsserts.AssertLessThan("2.0 < 1", 2.0, 1));
            Assert.IsTrue(myAsserts.AssertLessThan("1 < \"2\"", 1, "2"));
            Assert.IsFalse(myAsserts.AssertLessThan("1 < \"1.0\"", 1, "1.0"));

            Assert.IsFalse(myAsserts.AssertLessThan("\"\" < \"\"", string.Empty, string.Empty));
            Assert.IsTrue(myAsserts.AssertLessThan("\"\" < \" \"", string.Empty, " "));
            Assert.IsFalse(myAsserts.AssertLessThan("\" \" < \" \"", " ", string.Empty));
            Assert.IsTrue(myAsserts.AssertLessThan("\"a\" < \"A\"", "a", "A"));
            Assert.IsFalse(myAsserts.AssertLessThan("\"A\" < \"a\"", "A", "a"));
            Assert.IsFalse(myAsserts.AssertLessThan("\"string\" < \"string\"", "string", "string"));

            Assert.IsFalse(myAsserts.AssertLessThan("obj1 < obj1", obj1, obj1));
            Assert.IsTrue(myAsserts.AssertLessThan("obj1 < obj2", obj1, obj2));
            Assert.IsFalse(myAsserts.AssertLessThan("obj2 < obj1", obj2, obj1));

            // fail scenarios
            Assert.IsFalse(myAsserts.AssertLessThan("obj1 = 1", obj1, 1));

            // a bit funky - the object obj1 is converted to string, and then the strings are compared.
            Assert.IsFalse(myAsserts.AssertLessThan("obj1 = \"string\"", obj1, "string"));
        }