Example #1
0
        public void RemoveAnyEvent(IFoo fake, EventHandler barHandler, EventHandler bazHandler, EventHandler removedHandlers)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IFoo>());

            "And event handlers for Bar and Baz"
            .x(() => (barHandler, bazHandler) = (A.Fake <EventHandler>(), A.Fake <EventHandler>()));

            "And unsubscription from any event of the fake is configured to update a delegate"
            .x(() => A.CallTo(fake, EventAction.Remove()).Invokes((EventHandler h) => removedHandlers += h));

            "When the handler for Bar is unsubscribed from the Bar event"
            .x(() => fake.Bar -= barHandler);

            "And the handler for Baz is unsubscribed from the Baz event"
            .x(() => fake.Baz -= bazHandler);

            "Then the removed handler list contains the handler for Bar"
            .x(() => removedHandlers.GetInvocationList().Should().Contain(barHandler));

            "And the removed handler list contains the handler for Baz"
            .x(() => removedHandlers.GetInvocationList().Should().Contain(bazHandler));
        }
Example #2
0
        public void UnnaturalFakeRemoveSpecificEvent(Fake <IFoo> fake, EventHandler barHandler, EventHandler bazHandler, EventHandler removedHandlers)
        {
            "Given a fake"
            .x(() => fake = new Fake <IFoo>());

            "And event handlers for Bar and Baz"
            .x(() => (barHandler, bazHandler) = (A.Fake <EventHandler>(), A.Fake <EventHandler>()));

            "And unsubscription from the Bar event of the fake is configured to update a delegate"
            .x(() => fake.CallsTo(EventAction.Remove(nameof(IFoo.Bar))).Invokes((EventHandler h) => removedHandlers += h));

            "When the handler for Bar is unsubscribed from the Bar event"
            .x(() => fake.FakedObject.Bar -= barHandler);

            "And the handler for Baz is unsubscribed from the Baz event"
            .x(() => fake.FakedObject.Baz -= bazHandler);

            "Then the removed handler list contains the handler for Bar"
            .x(() => removedHandlers.GetInvocationList().Should().Contain(barHandler));

            "And the removed handler list doesn't contain the handler for Baz"
            .x(() => removedHandlers.GetInvocationList().Should().NotContain(bazHandler));
        }