コード例 #1
0
        public void Visit_CompareSameMethodsOnSameObject_ThrowsWarning()
        {
            var account = new Account();
            var inspector = new InspectExpressionVisitor();
            Expression<Func<bool>> expression = () => account.GetName() == account.GetName();

            TestDelegate action = () => inspector.Visit(expression);

            Assert.That(action, Throws.TypeOf<InspectionWarning>());
        }
コード例 #2
0
        public void Visit_ComparisonOfDefaultValueForReferenceType_Warns()
        {
            Account account = null;
            Account otherAccount = null;
            var inspector = new InspectExpressionVisitor();
            Expression<Func<bool>> expression = () => account == otherAccount;

            TestDelegate action = () => inspector.Visit(expression);

            Assert.That(action, Throws.TypeOf<DefaultValueWarning>().With.Message.EqualTo("Comparison where both values are null."));
        }
コード例 #3
0
        public void Visit_CompareSameMethodsOnDifferntObjects_ThrowsWarning()
        {
            var account = new Account();
            account.SetName("A");
            var otherAccount = new Account();
            account.SetName("B");
            var inspector = new InspectExpressionVisitor();
            Expression<Func<bool>> expression = () => account.GetMe().GetName() == otherAccount.GetMe().GetName();

            TestDelegate action = () => inspector.Visit(expression);

            Assert.That(action, Throws.Nothing);
        }
コード例 #4
0
        public void Visit_ComparisonOfNotDefaultValueForValueType_DoesNotWarn()
        {
            int a = 1;
            int b = default(int);
            var inspector = new InspectExpressionVisitor();
            Expression<Func<bool>> expression = () => a == b;

            TestDelegate action = () => inspector.Visit(expression);

            Assert.That(action, Throws.Nothing);
        }
コード例 #5
0
        public void Visit_ComparisonOfDefaultValueForValueType_Warns()
        {
            int a = default(int);
            int b = default(int);
            var inspector = new InspectExpressionVisitor();
            Expression<Func<bool>> expression = () => a == b;

            TestDelegate action = () => inspector.Visit(expression);

            Assert.That(action, Throws.TypeOf<DefaultValueWarning>().With.Message.EqualTo("Comparison of value types where both are the default value."));
        }
コード例 #6
0
        public void Visit_DifferentMembers_DoesNotThrowWarning()
        {
            var account = new Account();
            var otherAccount = new Account();
            var inspector = new InspectExpressionVisitor();
            Expression<Func<bool>> expression = () => account == otherAccount;

            TestDelegate action = () => inspector.Visit(expression);

            Assert.That(action, Throws.Nothing);
        }