示例#1
0
        public void NoConstraintGenericWithStringType_AndMethodWithNullArgument()
        {
            var instance = new GenericsSample.NoConstraint <string>();

            Action act = () => instance.Method(null /*Expect:AssignNullToNotNullAttribute[MIn]*/);

            act.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("a");
        }
示例#2
0
        public void NoConstraintGenericWithDateTimeType_AndFunctionWithDefaultOfTReturnValue()
        {
            var instance = new GenericsSample.NoConstraint <DateTime>();

            Action act = () => instance.Function(returnValue: default(DateTime));

            act.ShouldNotThrow("the return value check should not perform a 'param == default(T)' comparison");
        }
示例#3
0
        public void NoConstraintGenericWithDateTimeType_AndMethodWithDefaultOfTArgument()
        {
            var instance = new GenericsSample.NoConstraint <DateTime>();

            Action act = () => instance.Method(default(DateTime));

            act.ShouldNotThrow("the argument check should not perform a 'param == default(T)' comparison");
        }
示例#4
0
        public void NoConstraintGenericWithNullableIntType_AndFunctionWithNullReturnValue()
        {
            var instance = new GenericsSample.NoConstraint <int?>();

            Action act = () => instance.Function(returnValue: null);

            act.ShouldThrow <InvalidOperationException>().WithMessage(
                "[NullGuard] Return value * is null.",
                "known issue for generics without constraint (it's a trade-off between this false positive and a false-negative if T is a reference type");
        }
示例#5
0
        public void NoConstraintGenericWithNullableIntType_AndMethodWithNullArgument()
        {
            var instance = new GenericsSample.NoConstraint <int?>();

            Action act = () => instance.Method(null /*Expect:AssignNullToNotNullAttribute[MIn]*/);

            act.ShouldThrow <ArgumentNullException>(
                "known issue for generics without constraint (it's a trade-off between this false positive and a false-negative if T is a reference type")
            .And.ParamName.Should().Be("a");
        }
示例#6
0
        public void NoConstraintGenericWithStringType_AndFunctionWithNullReturnValue()
        {
            var instance = new GenericsSample.NoConstraint <string>();

            Action act = () =>
            {
                var result = instance.Function(returnValue: null);
                ReSharper.TestValueAnalysis(result, result == null /*Expect:ConditionIsAlwaysTrueOrFalse[MOut]*/);
            };

            act.ShouldThrow <InvalidOperationException>().WithMessage("[NullGuard] Return value * is null.");
        }