Esempio n. 1
0
        public static void ParameterArrays(
            ITypeWithParameterArray fake)
        {
            "Given a fake"
            .x(() => fake = A.Fake <ITypeWithParameterArray>());

            "When a call with a parameter array is made on this fake"
            .x(() => fake.MethodWithParameterArray("foo", "bar", "baz"));

            "Then an assertion with all the same argument values should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo", "bar", "baz")).MustHaveHappened());

            "And an assertion with only one matching params argument value should fail"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo", "bar")).MustNotHaveHappened());

            "And an assertion with one matching and one non-matching params argument value should fail"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo", "qux", "baz")).MustNotHaveHappened());

            "And an assertion with only argument constraints should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray(A <string> ._, A <string> ._, A <string> ._)).MustHaveHappened());

            "And an assertion with mixed argument values and argument constraints should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray(A <string> ._, "bar", A <string> ._)).MustHaveHappened());

            "And an assertion with an array instead of individual arguments should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo", new[] { "bar", "baz" })).MustHaveHappened());

            "And an assertion using IsSameSequenceAs should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo", A <string[]> .That.IsSameSequenceAs(new[] { "bar", "baz" }))).MustHaveHappened());
        }
Esempio n. 2
0
        public static void UnusedParameterArray(
            ITypeWithParameterArray fake)
        {
            "Given a fake"
            .x(() => fake = A.Fake <ITypeWithParameterArray>());

            "When a call with a parameter array is made on this fake but no params are supplied"
            .x(() => fake.MethodWithParameterArray("foo"));

            "Then an assertion with all the same non-params argument values should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo")).MustHaveHappened());

            "And an assertion with an empty array in place of the params arguments should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo", Array.Empty <string>())).MustHaveHappened());
        }
Esempio n. 3
0
        public static void IgnoredArgumentConstraintUsingUnderscoreMatchesAnything(
            string value,
            ITypeWithParameterArray subject,
            bool wasCalled)
        {
            "Given a fake"
            .x(() => subject = A.Fake <ITypeWithParameterArray>());

            "And a call configured to ignore the first argument using the Ignored member"
            .x(() => A.CallTo(() => subject.MethodWithParameterArray(A <string> ._)).Invokes(() => wasCalled = true));

            $"When I make a call to this method with the value '{value}"
            .x(() => subject.MethodWithParameterArray(value));

            "Then the argument is matched"
            .x(() => wasCalled.Should().BeTrue());
        }
Esempio n. 4
0
        public static void ParameterArrays(
            ITypeWithParameterArray fake)
        {
            "Given a fake"
            .x(() => fake = A.Fake <ITypeWithParameterArray>());

            "When a call with a parameter array is made on this fake"
            .x(() => fake.MethodWithParameterArray("foo", "bar", "baz"));

            "Then an assertion with all the same argument values should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo", "bar", "baz")).MustHaveHappened());

            "And an assertion with only argument constraints should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray(A <string> ._, A <string> ._, A <string> ._)).MustHaveHappened());

            "And an assertion with mixed argument values and argument constraints should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray(A <string> ._, "bar", A <string> ._)).MustHaveHappened());

            "And an assertion using the array syntax should succeed"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo", A <string[]> .That.IsSameSequenceAs(new[] { "bar", "baz" }))).MustHaveHappened());
        }
Esempio n. 5
0
        public static void ParameterArrays(
            ITypeWithParameterArray fake)
        {
            "establish"
            .x(() => fake = A.Fake <ITypeWithParameterArray>());

            "when matching calls with parameter arrays"
            .x(() => fake.MethodWithParameterArray("foo", "bar", "baz"));

            "it should be able to match the call"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo", "bar", "baz")).MustHaveHappened());

            "it should be able to match the call with argument constraints"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray(A <string> ._, A <string> ._, A <string> ._)).MustHaveHappened());

            "it should be able to match the call mixing constraints and values"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray(A <string> ._, "bar", A <string> ._)).MustHaveHappened());

            "it should be able to match using array syntax"
            .x(() => A.CallTo(() => fake.MethodWithParameterArray("foo", A <string[]> .That.IsSameSequenceAs(new[] { "bar", "baz" }))).MustHaveHappened());
        }