Esempio n. 1
0
        public static void RefParameter(
            IHaveARefParameter subject,
            string constraintValue,
            string value,
            bool result)
        {
            "Given a fake"
            .x(() => subject = A.Fake <IHaveARefParameter>());

            "And a call to a method with a ref parameter configured on this fake"
            .x(() =>
            {
                constraintValue = "a constraint string";
                A.CallTo(() => subject.CheckYourReferences(ref constraintValue)).Returns(true);
            });

            "When I make a call to the configured method with the constraint string"
            .x(() =>
            {
                value  = constraintValue;
                result = subject.CheckYourReferences(ref value);
            });

            "Then it should return the configured value"
            .x(() => result.Should().BeTrue());

            "And it should assign the constraint value to the ref parameter"
            .x(() => value.Should().Be(constraintValue));
        }
Esempio n. 2
0
        public static void FailingMatchOfRefParameter(
            IHaveARefParameter subject,
            string constraintValue,
            string value,
            bool result)
        {
            "Given a fake"
            .x(() => subject = A.Fake <IHaveARefParameter>());

            "And a call to a method with a ref parameter configured on this fake"
            .x(() =>
            {
                constraintValue = "a constraint string";
                A.CallTo(() => subject.CheckYourReferences(ref constraintValue)).Returns(true);
            });

            "When I make a call to the configured method with a different value"
            .x(() =>
            {
                value  = "a different string";
                result = subject.CheckYourReferences(ref value);
            });

            "Then it should return the default value"
            .x(() => result.Should().BeFalse());

            "And it should leave the ref parameter unchanged"
            .x(() => value.Should().Be("a different string"));
        }
Esempio n. 3
0
        public static void RefParameter(
            IHaveARefParameter subject)
        {
            "establish"
            .x(() => subject = A.Fake <IHaveARefParameter>());

            "when matching a call with a ref parameter"
            .x(() =>
            {
                string refString = "a constraint string";
                A.CallTo(() => subject.CheckYourReferences(ref refString))
                .Returns(true);
            });

            "it should match when ref parameter value matches"
            .x(() =>
            {
                string refString = "a constraint string";

                subject.CheckYourReferences(ref refString)
                .Should().BeTrue();
            });

            "it should not match when ref parameter value does not match"
            .x(() =>
            {
                string refString = "a different string";

                subject.CheckYourReferences(ref refString)
                .Should().BeFalse();
            });

            "it should assign the constraint value to the ref parameter"
            .x(() =>
            {
                string refString = "a constraint string";

                subject.CheckYourReferences(ref refString);

                refString.Should().Be("a constraint string");
            });
        }