Exemple #1
0
        public void RaisesAny_ThrowsException_WhenNoEventRaised()
        {
            var sut = new AClassWithEvents();

            Assert.Throws <RaisesException>(() =>
                                            Assert.RaisesAny <BaseEventArgs>(
                                                handler => sut.AnEvent += handler,
                                                handler => sut.AnEvent -= handler,
                                                () => sut.Raise(null))
                                            );
        }
Exemple #2
0
        public void Raises_ThrowsException_WhenDerivedArgs()
        {
            var sut = new AClassWithEvents();

            Assert.Throws <RaisesException>(() =>
                                            Assert.Raises <BaseEventArgs>(
                                                handler => sut.AnEvent += handler,
                                                handler => sut.AnEvent -= handler,
                                                () => sut.Raise(new DerivedEventArgs(42, "42")))
                                            );
        }
Exemple #3
0
        public void RaisesAny()
        {
            var sut = new AClassWithEvents();

            var ev = Assert.RaisesAny <BaseEventArgs>(
                handler => sut.AnEvent += handler,
                handler => sut.AnEvent -= handler,
                () => sut.Raise(new BaseEventArgs(42)));

            Assert.Same(sut, ev.Sender);
            Assert.IsType <BaseEventArgs>(ev.Arguments);
            Assert.Equal(42, ev.Arguments.IValue);
        }
Exemple #4
0
        public void RaisesAny_DerivedArgs()
        {
            var sut = new AClassWithEvents();

            var ev = Assert.RaisesAny <BaseEventArgs>(
                handler => sut.AnEvent += handler,
                handler => sut.AnEvent -= handler,
                () => sut.Raise(new DerivedEventArgs(42, "42")));

            Assert.Same(sut, ev.Sender);
            Assert.IsType <DerivedEventArgs>(ev.Arguments);
            Assert.Equal(42, ((ev.Arguments) as DerivedEventArgs).IValue);
            Assert.Equal("42", ((ev.Arguments) as DerivedEventArgs).SValue);
        }