Пример #1
0
        public static void ConfiguringNonConfigurableSetter(
            ClassWithInterestingProperties subject,
            Exception exception)
        {
            "Given a Fake with a property that can't be configured"
            .x(() => subject = A.Fake <ClassWithInterestingProperties>());

            "When assignment of the property is configured"
            .x(() => exception = Record.Exception(() => A.CallToSet(() => subject.NonConfigurableProperty).DoesNothing()));

            "Then a fake configuration exception is thrown"
            .x(() => exception.Should().BeAnExceptionOfType <FakeConfigurationException>());
        }
        public static void ConfiguringNonConfigurableSetter(
            ClassWithInterestingProperties subject,
            Exception exception)
        {
            "Given a Fake with a property that can't be configured"
                .x(() => subject = A.Fake<ClassWithInterestingProperties>());

            "When assignment of the property is configured"
                .x(() => exception = Record.Exception(() => A.CallToSet(() => subject.NonConfigurableProperty).DoesNothing()));

            "Then a fake configuration exception is thrown"
                .x(() => exception.Should().BeAnExceptionOfType<FakeConfigurationException>());
        }
Пример #3
0
        public static void ConfiguringSetterViaField(
            ClassWithInterestingProperties subject,
            Exception exception)
        {
            "Given a Fake with a property"
            .x(() => subject = A.Fake <ClassWithInterestingProperties>());

            "When assignment of the property is configured using a field access expression"
            .x(() => exception = Record.Exception(() => A.CallToSet(() => subject.Field).DoesNothing()));

            "Then an argument exception is thrown"
            .x(() => exception.Should().BeAnExceptionOfType <ArgumentException>());

            "And the exception message indicates that the expression refers to an incorrect member type"
            .x(() => exception.Message.Should().Be("The specified expression is not a method call or property getter."));
        }
        public static void ConfiguringSetterToCallBaseMethodForAnyValue(
            int value,
            ClassWithInterestingProperties subject)
        {
            "Given a Fake with a property"
            .x(() => subject = A.Fake <ClassWithInterestingProperties>());

            "And assignment of the property is configured to call the base implementation for any value"
            .x(() => A.CallToSet(() => subject.ConfigurableProperty).CallsBaseMethod());

            $"When I assign the property to {value}"
            .x(() => subject.ConfigurableProperty = value);

            "Then the base implementation is called"
            .x(() => subject.WasBaseSetterCalled.Should().BeTrue());
        }
        public static void ConfiguringSetterViaField(
            ClassWithInterestingProperties subject,
            Exception exception)
        {
            "Given a Fake with a property"
                .x(() => subject = A.Fake<ClassWithInterestingProperties>());

            "When assignment of the property is configured using a field access expression"
                .x(() => exception = Record.Exception(() => A.CallToSet(() => subject.Field).DoesNothing()));

            "Then an argument exception is thrown"
                .x(() => exception.Should().BeAnExceptionOfType<ArgumentException>());

            "And the exception message indicates that the expression refers to an incorrect member type"
                .x(() => exception.Message.Should().Be("The specified expression is not a method call or property getter."));
        }