Example #1
0
        public void ImmutableClassWithBadCtor()
        {
            var immutableClass = new PropertiesSample.ImmutableClass();

            // Here the implicit NotNull is wrong, but we have the NotNullMemberIsNotInitialized warning at the bad c'tor and
            // the NullGuard check at the property getter.
            Action act = () =>
            {
                var value = immutableClass.Property;
                TestValueAnalysis(value, value == null /*Expect:ConditionIsAlwaysTrueOrFalse[Prps]*/);
            };

            act.ShouldThrow <InvalidOperationException>().WithMessage("[NullGuard] Return value * is null.");
        }
Example #2
0
        public void ImmutableClass()
        {
            var c = new PropertiesSample.ImmutableClass(value: "value");

            TestValueAnalysis(c.Property, c.Property == null /*Expect:ConditionIsAlwaysTrueOrFalse[Prps]*/);
            c.Property.Should().Be("value");

            TestValueAnalysis(c.AutoPropertyWithPrivateSetter, c.AutoPropertyWithPrivateSetter == null
                              /*Expect:ConditionIsAlwaysTrueOrFalse[Prps && !RtGo]*/);
            c.AutoPropertyWithPrivateSetter.Should().Be("value");

            TestValueAnalysis(c.DelegatingProperty, c.DelegatingProperty == null /*Expect:ConditionIsAlwaysTrueOrFalse[Prps]*/);
            c.DelegatingProperty.Should().Be("value");

            TestValueAnalysis(c.NullableProperty /*Expect:AssignNullToNotNullAttribute*/, c.NullableProperty == null);
            c.NullableProperty.Should().BeNull();

            // Here the implicit NotNull is wrong, because "UnknownNullabilityString" returns null:
            c.Invoking(x => TestValueAnalysis(
                           x.PropertyWithUnknownValue, x.PropertyWithUnknownValue == null /*Expect:ConditionIsAlwaysTrueOrFalse[Prps]*/))
            .ShouldThrow <InvalidOperationException>().WithMessage("[NullGuard] Return value * is null.");
        }