NUnit.Framework.Assert.Throws(NUnit.Framework.Constraints.IResolveConstraint, NUnit.Framework.TestDelegate)

Here are the examples of the csharp api class NUnit.Framework.Assert.Throws(NUnit.Framework.Constraints.IResolveConstraint, NUnit.Framework.TestDelegate) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

48 Examples 7

1. Example

Project: AutoTest.Net
Source File: Assert.template.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

2. Example

Project: msgpack-cli
Source File: Assert.Exceptions.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

3. Example

Project: msgpack-cli
Source File: Assert.Exceptions.cs
View license
public static TActual Catch<TActual>(TestDelegate code) where TActual : System.Exception
        {
            return (TActual)Throws(new InstanceOfTypeConstraint(typeof(TActual)), code);
        }

4. Example

Project: msgpack-cli
Source File: Assert.Exceptions.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

5. Example

Project: nunitlite
Source File: Assert.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

6. Example

Project: ContinuousTests
Source File: Assert.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

7. Example

Project: nunit
Source File: Assert.Exceptions.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

8. Example

Project: nunit
Source File: Assert.Exceptions.cs
View license
public static TActual Catch<TActual>(TestDelegate code) where TActual : System.Exception
        {
            return (TActual)Throws(new InstanceOfTypeConstraint(typeof(TActual)), code);
        }

9. Example

Project: nunit
Source File: Assert.Exceptions.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

10. Example

Project: AutoTest.Net
Source File: Assert.template.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

11. Example

Project: nunitlite
Source File: Assert.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

12. Example

Project: AutoTest.Net
Source File: Assert.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

13. Example

Project: AutoTest.Net
Source File: Assert.template.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

14. Example

Project: AutoTest.Net
Source File: Assert.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

15. Example

Project: AutoTest.Net
Source File: Assert.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

16. Example

Project: AutoTest.Net
Source File: Assert.template.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

17. Example

Project: AutoTest.Net
Source File: Assert.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

18. Example

Project: AutoTest.Net
Source File: Assert.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

19. Example

Project: AutoTest.Net
Source File: Assert.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

20. Example

Project: msgpack-cli
Source File: Assert.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

21. Example

Project: ContinuousTests
Source File: Assert.template.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

22. Example

Project: ContinuousTests
Source File: Assert.template.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

23. Example

Project: ContinuousTests
Source File: Assert.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

24. Example

Project: ContinuousTests
Source File: Assert.template.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

25. Example

Project: ContinuousTests
Source File: Assert.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

26. Example

Project: ContinuousTests
Source File: Assert.template.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

27. Example

Project: ContinuousTests
Source File: Assert.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

28. Example

Project: ContinuousTests
Source File: Assert.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

29. Example

Project: ContinuousTests
Source File: Assert.cs
View license
public static Exception Catch(TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
        }

30. Example

Project: msgpack-cli
Source File: Assert.cs
View license
public static Exception Catch(Type expectedExceptionType, TestDelegate code)
        {
            return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
        }

31. Example

Project: Unity3D.Amqp
Source File: TestBasicGet.cs
View license
[Test]
        public void TestBasicGetWithClosedChannel()
        {
            WithNonEmptyQueue((_, q) => {
                WithClosedModel((cm) => {
                    Assert.Throws(Is.InstanceOf<AlreadyClosedException>(),
                                 delegate { cm.BasicGet(q, true); });
                });
            });
        }

32. Example

Project: Unity3D.Amqp
Source File: TestBasicGet.cs
View license
[Test]
        public void TestBasicGetWithClosedChannel()
        {
            WithNonEmptyQueue((_, q) => {
                WithClosedModel((cm) => {
                    Assert.Throws(Is.InstanceOf<AlreadyClosedException>(),
                                 delegate { cm.BasicGet(q, true); });
                });
            });
        }

33. Example

Project: Pash
Source File: PSObjectTests.cs
View license
[Test]
        public void PSObjectCannotConstructNull()
        {
            // TODO: check for exception type
            Assert.Throws(Is.InstanceOf(typeof(Exception)), delegate
            {
                new PSObject(null);
            });
        }

34. Example

Project: RampUp
Source File: StreamTests.cs
View license
private static void Throws(TestDelegate testDelegate)
        {
            Assert.Throws(Is.AssignableTo(typeof (Exception)), testDelegate);
        }

35. Example

Project: RampUp
Source File: BusTests.cs
View license
[Test]
        public void WhenNotRegisteredMessageSent_ThenThrows()
        {
            Assert.Throws(Is.AssignableTo<Exception>(), () =>
            {
                var msg = new NotRegistered();
                _bus.Publish(ref msg);
            });
        }

36. Example

Project: Pash
Source File: PSObjectTests.cs
View license
[Test]
        public void AsPSObjectCannotWrapNull()
        {
            // TODO: check for exception type
            Assert.Throws(Is.InstanceOf(typeof(Exception)), delegate
            {
                PSObject.AsPSObject(null);
            });
        }

37. Example

View license
[Test]
        public void ShouldRaiseFriendErrorWhenAccessUnknownCarIdx()
        {
            Assert.Throws(Is.TypeOf<Exception>().And.Message.EqualTo("Attempt to load car details for unknown carIndex.  carIdx: 5, maxNumber: 0"), () => { var a = telemetry.Cars[5]; });
        }

38. Example

View license
[Test]
        public void should_release_acquired_buffers_if_size_requirement_cant_be_satisfied()
        {
            global::BufferManager.BufferManager manager = new global::BufferManager.BufferManager(1, 1000, 1, false);
            Assert.Throws(Is.InstanceOf(typeof(Exception)), () => manager.CheckOut(2));
            Assert.AreEqual(1, manager.AvailableBuffers);
        }

39. Example

View license
[Test]
        public void TooManyAdapterElements()
        {
            const string xml =
    @"<?xml version='1.0' encoding='UTF-8' ?>
    <logging>
      <factoryAdapter type='Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging'>
      </factoryAdapter>
      <factoryAdapter type='Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging'>
      </factoryAdapter>
    </logging>";
            StandaloneConfigurationReader reader = new StandaloneConfigurationReader(xml);
            Assert.Throws( Is.TypeOf<ConfigurationException>()
                            .And.Message.EqualTo("Only one <factoryAdapter> element allowed")
                            , delegate {
                            reader.GetSection(null);
                        });
        }

40. Example

Project: google-maps
Source File: GeocodingTests.cs
View license
[Test]
        public void GeocodingAsync_Cancel_Throws()
        {
            var request = new GeocodingRequest { Address = "285 Bedford Ave, Brooklyn, NY 11211, USA" };

            var tokeSource = new CancellationTokenSource();
            var task = GoogleMaps.Geocode.QueryAsync(request, tokeSource.Token);
            tokeSource.Cancel();

            Assert.Throws(Is.TypeOf<AggregateException>().And.InnerException.TypeOf<TaskCanceledException>(),
                () => task.Wait());
        }

41. Example

Project: google-maps
Source File: GeocodingTests.cs
View license
[Test]
        public void GeocodingAsync_WithPreCanceledToken_Cancels()
        {
            var request = new GeocodingRequest { Address = "285 Bedford Ave, Brooklyn, NY 11211, USA" };
            var cts = new CancellationTokenSource();
            cts.Cancel();

            var task = GoogleMaps.Geocode.QueryAsync(request, cts.Token);

            Assert.Throws(Is.TypeOf<AggregateException>().And.InnerException.TypeOf<TaskCanceledException>(),
                            () => task.Wait());
        }

42. Example

View license
[Test]
        public void ClassicPageWithSeleniumDriverFailsToLocateDeferredElementOfListByVisibility()
        {
            var page = PageFactory.InitElements<PageWithDeferredWebElementOfList>(driver);
            Thread.Sleep(300);
            Assert.Throws(Is.TypeOf(typeof(ElementNotVisibleException)), () => {
                page.Elements[1].Click();
            });
            Assert.IsFalse(driver.Url.Contains("second"));
        }

43. Example

View license
[Test]
        public void ClassicPageWithSeleniumDriverFailsToLocateDeferredElementOfListByAppearance()
        {
            var page = PageFactory.InitElements<PageWithDeferredWebElementOfList>(driver);
            Assert.Throws(Is.TypeOf(typeof(TargetInvocationException))
                          .And.InnerException.TypeOf(typeof(ArgumentOutOfRangeException)), () => {
                page.Elements[1].Click();
            });
            Assert.IsFalse(driver.Url.Contains("second"));
        }

44. Example

View license
[Test]
        public void ClassicPageWithSeleniumDriverFailsToLocateDeferredElementByAppearance()
        {
            var page = new PageWithDeferredWebElement(driver);
            Assert.Throws(Is.TypeOf(typeof(NoSuchElementException)), () => {
                page.Element.Click();
            });
            Assert.IsFalse(driver.Url.Contains("second"));
        }

45. Example

View license
[Test]
        public void ClassicPageWithDecoratedByNSeleneDriverFailsToLocateDeferredElementByAppearance()
        {
            var page = PageFactory.InitElements<PageWithDeferredWebElementOfList>(new SeleneDriver(driver));
            /* same as the following
            var page = PageFactory.InitElements<PageWithDeferredWebElementOfList>(new DefaultElementLocator(new SDriver(driver)));
             */
            Assert.Throws(Is.TypeOf(typeof(TargetInvocationException))
                          .And.InnerException.TypeOf(typeof(ArgumentOutOfRangeException)), () => {
                page.Elements[1].Click();
            });
            Assert.IsFalse(driver.Url.Contains("second"));
        }

46. Example

Project: NodaTime
Source File: FormattingTestSupport.cs
View license
private static void DoRunParseTest<TInput, T>(AbstractFormattingData<T> data, Func<TInput, T> test, TInput pattern, bool isMulti)
        {
            Func<TInput, T> doit = s =>
            {
                using (CultureSaver.SetCultures(data.ThreadCulture, data.ThreadUiCulture))
                {
                    return test(s);
                }
            };
            if (data.Exception == null)
            {
                var actual = doit(pattern);
                Assert.AreEqual(data.PV, actual);
            }
            else if (data.Message != null)
            {
                var message = string.Format(data.Message, data.Parameters.ToArray());
                Assert.Throws(Is.TypeOf(data.Exception).And.Message.EqualTo(message), () => doit(pattern));
            }
            else
            {
                Assert.Throws(Is.TypeOf(data.Exception), () => doit(pattern));
            }
        }

47. Example

Project: NodaTime
Source File: FormattingTestSupport.cs
View license
public static void RunFormatTest<T>(AbstractFormattingData<T> data, Func<string> test)
        {
            if (data.P != null)
            {
                if (data.P.Split('\0').Length != 1)
                {
                    return;
                }
            }
            Func<string> doit = () =>
            {
                using (CultureSaver.SetCultures(data.ThreadCulture, data.ThreadUiCulture))
                {
                    return test();
                }
            };
            if (data.Exception == null)
            {
                Assert.AreEqual(data.S, doit());
            }
            else if (data.Message != null)
            {
                var message = string.Format(data.Message, data.Parameters.ToArray());
                Assert.Throws(Is.TypeOf(data.Exception).And.Message.EqualTo(message), () => doit());
            }
            else
            {
                Assert.Throws(Is.TypeOf(data.Exception), () => doit());
            }
        }

48. Example

View license
[Test]
        public void ClassicPageWithSeleniumDriverFailsToLocateDeferredElementByVisibility()
        {
            var page = new PageWithDeferredWebElement(driver);
            Thread.Sleep(300);
            Assert.Throws(Is.TypeOf(typeof(TargetInvocationException))
                          .And.InnerException.TypeOf(typeof(ElementNotVisibleException)), () => {
                page.Element.Click();
            });
            Assert.IsFalse(driver.Url.Contains("second"));
        }