Ejemplo n.º 1
0
        public void NullSenderAndCustomEventArguments()
        {
            "Given an event of type EventHandler with custom event arguments type"
            .See(() => nameof(Fake.GenericEvent));

            "When I raise the event specifying the event arguments and a null sender"
            .x(() => Fake.GenericEvent += Raise.With(null, this.customEventArgs));

            "Then null is passed as the event sender"
            .x(() => CapturedSender.Should().BeNull());

            "And the supplied value is passed as the event arguments"
            .x(() => CapturedArgs1.Should().BeSameAs(this.customEventArgs));
        }
Ejemplo n.º 2
0
        public void WithEmpty()
        {
            "Given an event of type EventHandler"
            .See(() => nameof(Fake.SubscribedEvent));

            "When I raise the event without specifying sender or arguments"
            .x(() => Fake.SubscribedEvent += Raise.WithEmpty());

            "Then the fake is passed as the sender"
            .x(() => CapturedSender.Should().BeSameAs(Fake));

            "And an empty EventArgs is passed as the event arguments"
            .x(() => CapturedArgs1.Should().Be(EventArgs.Empty));
        }
Ejemplo n.º 3
0
        public void SenderAndEventArguments()
        {
            "Given an event of type EventHandler"
            .See(() => nameof(Fake.SubscribedEvent));

            "When I raise the event specifying the sender and the event arguments"
            .x(() => Fake.SubscribedEvent += Raise.With(SampleSender, this.eventArgs));

            "Then the supplied sender is passed as the event sender"
            .x(() => CapturedSender.Should().BeSameAs(SampleSender));

            "And the supplied value is passed as the event arguments"
            .x(() => CapturedArgs1.Should().BeSameAs(this.eventArgs));
        }
Ejemplo n.º 4
0
        public void ActionEvent()
        {
            var eventArgs1 = 19;
            var eventArgs2 = true;

            "when raising action event passing arguments"
            .x(() => Fake.ActionEvent += Raise.With <Action <int, bool> >(eventArgs1, eventArgs2));

            "it should pass the first argument"
            .x(() => CapturedArgs1.Should().Be(eventArgs1));

            "it should pass the second argument"
            .x(() => CapturedArgs2.Should().Be(eventArgs2));
        }
Ejemplo n.º 5
0
        public void ActionEvent()
        {
            "Given an event of type Action"
            .See(() => nameof(Fake.ActionEvent));

            "When I raise the event specifying the arguments"
            .x(() => Fake.ActionEvent += Raise.With <Action <int, bool> >(19, true));

            "Then the first value is passed as the first event argument"
            .x(() => CapturedArgs1.Should().Be(19));

            "Then the second value is passed as the second event argument"
            .x(() => CapturedArgs2.Should().Be(true));
        }
Ejemplo n.º 6
0
        public void CustomEventHandler()
        {
            "Given an event of a custom delegate type that takes a sender and event arguments"
            .See(() => nameof(Fake.CustomEvent));

            "When I raise the event specifying the sender and the event arguments"
            .x(() => Fake.CustomEvent += Raise.With <CustomEventHandler>(SampleSender, this.customEventArgs));

            "Then the supplied sender is passed as the event sender"
            .x(() => CapturedSender.Should().BeSameAs(SampleSender));

            "And the supplied value is passed as the event arguments"
            .x(() => CapturedArgs1.Should().BeSameAs(this.customEventArgs));
        }
Ejemplo n.º 7
0
        public void EventArgumentsThatDoNotExtenedEventArg()
        {
            "Given an event of type EventHandler with custom event arguments type that does not extend EventArgs"
            .See(() => nameof(Fake.EventHandlerOfNonEventArgsEvent));

            "When I raise the event specifying only the event arguments"
            .x(() => Fake.EventHandlerOfNonEventArgsEvent += Raise.With(this.referenceTypeEventArgs));

            "Then the fake is passed as the sender"
            .x(() => CapturedSender.Should().BeSameAs(Fake));

            "And the supplied value is passed as the event arguments"
            .x(() => CapturedArgs1.Should().BeSameAs(this.referenceTypeEventArgs));
        }
Ejemplo n.º 8
0
        public void ReferenceTypeEventHandlerWithDerivedArguments()
        {
            "Given an event of a custom delegate type taking only a reference type as an argument"
            .See(() => nameof(Fake.ReferenceTypeEvent));

            "When I raise the event specifying an argument of a derived type"
            .x(() => Fake.ReferenceTypeEvent +=
#pragma warning disable CS0618 // Type or member is obsolete
                   Raise.With <ReferenceTypeEventHandler>(this.derivedReferenceTypeEventArgs));
#pragma warning restore CS0618 // Type or member is obsolete

            "Then the supplied value is passed as the event argument"
            .x(() => CapturedArgs1.Should().BeSameAs(this.derivedReferenceTypeEventArgs));
        }
Ejemplo n.º 9
0
        public void ActionEvent()
        {
            "Given an event of type Action"
            .See(() => nameof(Fake.ActionEvent));

            "When I raise the event specifying the arguments"
#pragma warning disable CS0618 // Type or member is obsolete
            .x(() => Fake.ActionEvent += Raise.With <Action <int, bool> >(19, true));
#pragma warning restore CS0618 // Type or member is obsolete

            "Then the first value is passed as the first event argument"
            .x(() => CapturedArgs1.Should().Be(19));

            "Then the second value is passed as the second event argument"
            .x(() => CapturedArgs2.Should().Be(true));
        }