Exemple #1
0
        public static void FailingMatchOfCollectionParameter(
            IIHaveACollectionParameter fake,
            Exception exception)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IIHaveACollectionParameter>());

            "And a call with argument [1, \"hello\", NULL, NULL, \"foo\", \"bar\"] made on this fake"
            .x(() => fake.Bar(new object[] { 1, "hello", null, null, "foo", "bar" }));

            "And a call with argument [null, 42] made on this fake"
            .x(() => fake.Bar(new object[] { null, 42 }));

            "When I assert that a call with an argument that is the same sequence as [null, 42, \"hello\"] has happened on this fake"
            .x(() => exception = Record.Exception(
                   () => A.CallTo(
                       () => fake.Bar(A <object[]> .That.IsSameSequenceAs(new object[] { null, 42, "hello" })))
                   .MustHaveHappened()));

            "Then the assertion should fail"
            .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>());

            "And the exception message should tell us that the call was not matched, and include the values of the actual collection elements"
            .x(() => exception.Message.Should().Be(@"

  Assertion failed for the following call:
    FakeItEasy.Specs.CallMatchingSpecs+IIHaveACollectionParameter.Bar(args: <NULL, 42, ""hello"">)
  Expected to find it at least once but found it #0 times among the calls:
    1: FakeItEasy.Specs.CallMatchingSpecs+IIHaveACollectionParameter.Bar(args: [1, ""hello"", … (2 more elements) …, ""foo"", ""bar""])
    2: FakeItEasy.Specs.CallMatchingSpecs+IIHaveACollectionParameter.Bar(args: [NULL, 42])

"));
        }
        public static void CollectionParameterContainsNull(
            IIHaveACollectionParameter fake,
            Exception exception)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IIHaveACollectionParameter>());

            "And a call with argument [1, \"hello\", NULL, NULL, \"foo\", \"bar\"] made on this fake"
            .x(() => fake.Bar(new object?[] { 1, "hello", null, null, "foo", "bar" }));

            "When I assert that a call with an argument that contains null has happened on this fake"
            .x(() => exception = Record.Exception(
                   () => A.CallTo(
                       () => fake.Bar(A <object[]> .That.Contains(null)))
                   .MustHaveHappened()));

            "Then the assertion should pass"
            .x(() => exception.Should().BeNull());
        }