public static void GotExpectedEvent()
 {
     var x = new RaisingClass();
     var evt = Assert.RaisesAny<EventArgs>(
         h => x.Completed += h,
         h => x.Completed -= h,
         () => x.RaiseWithArgs(EventArgs.Empty));
     Assert.NotNull(evt);
     Assert.Equal(x, evt.Sender);
     Assert.Equal(EventArgs.Empty, evt.Arguments);
 }
Exemple #2
0
        public static void GotExpectedEvent()
        {
            var x = new RaisingClass();

            var evt = Assert.RaisesAny <EventArgs>(
                h => x.Completed += h,
                h => x.Completed -= h,
                () => x.RaiseWithArgs(EventArgs.Empty));

            Assert.NotNull(evt);
            Assert.Equal(x, evt.Sender);
            Assert.Equal(EventArgs.Empty, evt.Arguments);
        }
Exemple #3
0
        public static async Task GotExpectedEvent()
        {
            var x = new RaisingClass();

            var evt = await Assert.RaisesAsync <EventArgs>(
                h => x.Completed += h,
                h => x.Completed -= h,
                () => Task.Run(() => x.RaiseWithArgs(EventArgs.Empty)));

            Assert.NotNull(evt);
            Assert.Equal(x, evt.Sender);
            Assert.Equal(EventArgs.Empty, evt.Arguments);
        }
Exemple #4
0
        public static void GotDerivedEvent()
        {
            var x    = new RaisingClass();
            var args = new DerivedEventArgs();

            var evt = Assert.RaisesAny <EventArgs>(
                h => x.Completed += h,
                h => x.Completed -= h,
                () => x.RaiseWithArgs(args));

            Assert.NotNull(evt);
            Assert.Equal(x, evt.Sender);
            Assert.Equal(args, evt.Arguments);
        }
Exemple #5
0
        public static async Task GotDerivedEvent()
        {
            var x    = new RaisingClass();
            var args = new DerivedEventArgs();

            var evt = await Assert.RaisesAnyAsync <EventArgs>(
                h => x.Completed += h,
                h => x.Completed -= h,
                () => Task.Run(() => x.RaiseWithArgs(args)));

            Assert.NotNull(evt);
            Assert.Equal(x, evt.Sender);
            Assert.Equal(args, evt.Arguments);
        }
Exemple #6
0
        public static void ExpectedEventButRaisesEventWithDerivedArgs()
        {
            var x = new RaisingClass();

            var recorded = Record.Exception(() =>
                Assert.Raises<EventArgs>(
                    h => x.Completed += h,
                    h => x.Completed -= h,
                    () => x.RaiseWithArgs(new DerivedEventArgs())));

            var exception = Assert.IsType<RaisesException>(recorded);
            Assert.Equal("DerivedEventArgs", exception.Actual);
            Assert.Equal("EventArgs", exception.Expected);
            Assert.Equal("(Raised event did not match expected event)", exception.UserMessage);
        }
Exemple #7
0
        public static void GotExpectedEvent()
        {
            var x             = new RaisingClass();
            var genericObject = new object();

            var evt = Assert.RaisesAny <object>(
                h => x.Completed += h,
                h => x.Completed -= h,
                () => x.RaiseWithArgs(genericObject)
                );

            Assert.NotNull(evt);
            Assert.Equal(x, evt.Sender);
            Assert.Equal(genericObject, evt.Arguments);
        }
Exemple #8
0
        public static async Task GotExpectedEvent()
        {
            var x             = new RaisingClass();
            var genericObject = new object();

            var evt = await Assert.RaisesAsync <object>(
                h => x.Completed += h,
                h => x.Completed -= h,
                () => Task.Run(() => x.RaiseWithArgs(genericObject))
                );

            Assert.NotNull(evt);
            Assert.Equal(x, evt.Sender);
            Assert.Equal(genericObject, evt.Arguments);
        }
Exemple #9
0
        public static void ExpectedEventButRaisesEventWithDerivedArgs()
        {
            var x = new RaisingClass();

            var recorded = Record.Exception(() =>
                                            Assert.Raises <EventArgs>(
                                                h => x.Completed += h,
                                                h => x.Completed -= h,
                                                () => x.RaiseWithArgs(new DerivedEventArgs())));

            var exception = Assert.IsType <RaisesException>(recorded);

            Assert.Equal("DerivedEventArgs", exception.Actual);
            Assert.Equal("EventArgs", exception.Expected);
            Assert.Equal("(Raised event did not match expected event)", exception.UserMessage);
        }
 public static void ExpectedEventButRaisesEventWithDerivedArgs()
 {
     try
     {
         var x = new RaisingClass();
         Assert.Raises<EventArgs>(
             h => x.Completed += h,
             h => x.Completed -= h,
             () => x.RaiseWithArgs(new DerivedEventArgs()));
     }
     catch (RaisesException exception)
     {
         Assert.Equal("DerivedEventArgs", exception.Actual);
         Assert.Equal("EventArgs", exception.Expected);
         Assert.Equal("(Raised event did not match expected event)", exception.UserMessage);
     }
 }
Exemple #11
0
        public static async Task ExpectedEventButRaisesEventWithDerivedObject()
        {
            var x = new RaisingClass();

            var recorded = await Record.ExceptionAsync(() =>
                                                       Assert.RaisesAsync <object>(
                                                           h => x.Completed += h,
                                                           h => x.Completed -= h,
                                                           () => Task.Run(() => x.RaiseWithArgs(new DerivedObject()))
                                                           )
                                                       );

            var exception = Assert.IsType <RaisesException>(recorded);

            Assert.Equal("DerivedObject", exception.Actual);
            Assert.Equal("Object", exception.Expected);
            Assert.Equal("(Raised event did not match expected event)", exception.UserMessage);
        }
Exemple #12
0
        public static void GotDerivedEvent()
        {
            var x = new RaisingClass();
            var args = new DerivedEventArgs();

            var evt = Assert.RaisesAny<EventArgs>(
                h => x.Completed += h,
                h => x.Completed -= h,
                () => x.RaiseWithArgs(args));

            Assert.NotNull(evt);
            Assert.Equal(x, evt.Sender);
            Assert.Equal(args, evt.Arguments);
        }
Exemple #13
0
        public static async Task GotExpectedEvent()
        {
            var x = new RaisingClass();

            var evt = await Assert.RaisesAsync<EventArgs>(
                h => x.Completed += h,
                h => x.Completed -= h,
                () => Task.Run(() => x.RaiseWithArgs(EventArgs.Empty)));

            Assert.NotNull(evt);
            Assert.Equal(x, evt.Sender);
            Assert.Equal(EventArgs.Empty, evt.Arguments);
        }
Exemple #14
0
        public static async Task GotDerivedEvent()
        {
            var x = new RaisingClass();
            var args = new DerivedEventArgs();

            var evt = await Assert.RaisesAnyAsync<EventArgs>(
                h => x.Completed += h,
                h => x.Completed -= h,
                () => Task.Run(() => x.RaiseWithArgs(args)));

            Assert.NotNull(evt);
            Assert.Equal(x, evt.Sender);
            Assert.Equal(args, evt.Arguments);
        }