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

            myAsserts.EnableNegativeTesting = true;

            Assert.IsTrue(myAsserts.AssertGreaterThan("2 > 1", 2, 1));
            Assert.IsTrue(myAsserts.AssertGreaterThan("2.0 > 1", 2.0, 1));
            Assert.IsFalse(myAsserts.AssertGreaterThan("1 > \"2\"", 1, "2"));
            Assert.IsTrue(myAsserts.AssertGreaterThan("1 > \"1.0\"", 1, "1.0"));

            Assert.IsFalse(myAsserts.AssertGreaterThan("\"\" > \"\"", string.Empty, string.Empty));
            Assert.IsFalse(myAsserts.AssertGreaterThan("\"\" > \" \"", string.Empty, " "));
            Assert.IsTrue(myAsserts.AssertGreaterThan("\" \" > \" \"", " ", string.Empty));
            Assert.IsFalse(myAsserts.AssertGreaterThan("\"a\" > \"A\"", "a", "A"));
            Assert.IsTrue(myAsserts.AssertGreaterThan("\"A\" > \"a\"", "A", "a"));
            Assert.IsFalse(myAsserts.AssertGreaterThan("\"string\" > \"string\"", "string", "string"));

            Assert.IsFalse(myAsserts.AssertGreaterThan("obj1 = obj1", obj1, obj1));
            Assert.IsFalse(myAsserts.AssertGreaterThan("obj1 = obj2", obj1, obj2));
            Assert.IsTrue(myAsserts.AssertGreaterThan("obj2 = obj1", obj2, obj1));

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

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