NUnit.Framework.Assert.Catch(NUnit.Framework.TestDelegate)

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

153 Examples 7

1. Example

Project: Mages
Source File: OperationTests.cs
View license
[Test]
        public void InvalidAssignmentPowerWithNumberYieldsError()
        {
            Assert.Catch<ParseException>(() => "x = 0; x ^ = 2; x".Eval());
        }

2. Example

Project: Mages
Source File: OperationTests.cs
View license
[Test]
        public void InvalidAssignmentPipeWithNumberYieldsError()
        {
            Assert.Catch<ParseException>(() => "x = 0; x | = factorial; x".Eval());
        }

3. Example

Project: Mages
Source File: OperationTests.cs
View license
[Test]
        public void InvalidAssignmentMultiplyWithNumberYieldsError()
        {
            Assert.Catch<ParseException>(() => "x = 0; x * = 2; x".Eval());
        }

4. Example

Project: Mages
Source File: OperationTests.cs
View license
[Test]
        public void InvalidAssignmentAddWithNumberYieldsError()
        {
            Assert.Catch<ParseException>(() => "x = 0; x + = 2; x".Eval());
        }

5. Example

View license
[Test]
		public void ToRepresentation_ValuesLenghtDiffTotalBits_Exception()
		{
			Assert.Catch<ArgumentException>(delegate
			{
				BinaryStringRepresentation.ToRepresentation(new long[] { 1L, 2L, 3L }, new int[] { 4, 6 });
			});
		}

6. Example

View license
[Test]
		public void ToInt64_RepresentationLengthDiffThanTotalBitsSum_Exception()
		{
			Assert.Catch<ArgumentException>(delegate
			{
				BinaryStringRepresentation.ToInt64("000100001000000011", new int[] { 4, 6, 9 });
			});
		}

7. Example

Project: NodaTime
Source File: InstantTest.Parse.cs
View license
[Test, Category("Formatting"), Category("Parse")]
        public void TestParse_BadValue()
        {
            Assert.Catch<FormatException>(() => Instant.Parse("ads"));
        }

8. Example

Project: NodaTime
Source File: InstantTest.Parse.cs
View license
[Test, Category("Formatting"), Category("Parse")]
        public void TestParse_N_extraSpace()
        {
            Assert.Catch<FormatException>(() => Instant.Parse(" " + threeMillion.Ticks.ToString("N0")));
        }

9. Example

Project: Simplify
Source File: FileHelperTester.cs
View license
[Test]
		public void IsFileLockedForRead()
		{
			Assert.Catch<ArgumentNullException>(() => FileHelper.IsFileLockedForRead(null));
			Assert.Catch<FileNotFoundException>(() => FileHelper.IsFileLockedForRead("NotFound"));
		}

10. Example

Project: Nustache
Source File: Describe_Parser.cs
View license
[Test]
        public void It_throws_when_the_end_section_does_not_match_any_start_section()
        {
            var parser = new Parser();
            var template = new Template();

            Assert.Catch<NustacheException>(
                () => parser.Parse(template,
                                   new Part[]
                                       {
                                           new LiteralText("before"),
                                           new EndSection("foo"),
                                           new LiteralText("after")
                                       }));
        }

11. Example

Project: Nustache
Source File: Describe_Parser.cs
View license
[Test]
        public void It_throws_when_the_end_section_does_not_match_the_start_section()
        {
            var parser = new Parser();
            var template = new Template();

            Assert.Catch<NustacheException>(
                () => parser.Parse(template,
                                   new Part[]
                                       {
                                           new LiteralText("before"),
                                           new Block("foo"),
                                           new LiteralText("inside"),
                                           new EndSection("bar"),
                                           new LiteralText("after")
                                       }));
        }

12. Example

Project: Benchmarkable
Source File: BenchmarkTests.cs
View license
[Test()]
        public void TestSingleWithException()
        {
            Assert.Catch<NullReferenceException>(() => Benchmark.Just.This(() => { throw new NullReferenceException(); }));
        }

13. Example

Project: Benchmarkable
Source File: BenchmarkTests.cs
View license
[Test()]
        public void ThrowsExceptionIfNoMethods()
        {
            var bench = new Benchmark();

            Assert.Catch<ArgumentOutOfRangeException>(() => bench.Run());
        }

14. Example

Project: linq2db
Source File: AggregationTests.cs
View license
[Test, DataContextSource]
		public void NonNullableMax2(string context)
		{
			using (var db = GetDataContext(context))
			{
				var q =
					from p in db.Parent
					select new
					{
						max = p.Children.Where(_ => _.ParentID < 0).Max(_ => _.ParentID)
					};

				Assert.Catch<InvalidOperationException>(() => q.ToList());
			}
		}

15. Example

Project: AngleSharp
Source File: CssSelector.cs
View license
[Test]
        public void NthChildInvalidSelector()
        {
            var source = @"<span>1</span><span class=italic>2</span><span class=this>3</span><span>4</span><span class=that>5</span><span class=this>6</span>";

            var document = source.ToHtmlDocument();
            var selector = "span:nth-child(10n+-1) ";

            Assert.Catch<DomException>(() =>
            {
                var result = document.QuerySelectorAll(selector);
            });
        }

16. Example

Project: AngleSharp
Source File: CssW3CSelector.cs
View license
[Test]
        public void ParsingColonVsColonColonA()
        {
            var source = @"<p xmlns=""http://www.w3.org/1999/xhtml"">When you select this text, it shouldn't go red.</p>";
            var doc = source.ToHtmlDocument();

            Assert.Catch(() => doc.QuerySelectorAll("p:selection"));
        }

17. Example

Project: AngleSharp
Source File: XmlTree.cs
View license
[Test]
        public void XmlInvalidDocumentMismatchedEndTag()
        {
            Assert.Catch<XmlParseException>(() => (@"<?xml version=""1.0"" encoding=""ISO-8859-1""?>
<!-- Edited by XMLSpy® -->
<note>
	<to>Tove</to>
	<from>Jani</Ffrom>
	<heading>Reminder</heading>
	<body>Don't forget me this weekend!</body>
</note>").ToXmlDocument());
        }

18. Example

Project: journeyofcode
Source File: TaskLazyTests.cs
View license
[Test]
        public void Cannot_Access_Value_Before_Completion()
        {
            var taskCompletionSource = new TaskCompletionSource<int>();
            var taskLazy = new TaskLazy<int>(taskCompletionSource.Task);

            Assert.Catch<InvalidOperationException>(() =>
            {
                var temp = taskLazy.Value;
            });
        }

19. Example

View license
[Test]
        public void Cannot_Construct_Using_Invalid_Apartement_State()
        {
            Assert.Catch<ArgumentException>(() => new SingleThreadTaskScheduler(ApartmentState.Unknown));
            Assert.Catch<ArgumentException>(() => new SingleThreadTaskScheduler(() => { }, ApartmentState.Unknown));
        }

20. Example

Project: CppSharp
Source File: Common.Tests.cs
View license
[Test]
    public void TestPassingNullToRef()
    {
        using (var foo = new Foo())
        {
            Assert.Catch<ArgumentNullException>(() => foo.TakesRef(null));
        }
    }

21. Example

Project: SwissArmyLib
Source File: Grid2DTests.cs
View license
[Test]
        public void OutOfBoundsThrowsException()
        {
            var grid = new Grid2D<int>(10, 10);
            var i = 0;
            
            // getter
            Assert.Catch<IndexOutOfRangeException>(() => i = grid[-1, 0]);
            Assert.Catch<IndexOutOfRangeException>(() => i = grid[0, -1]);
            Assert.Catch<IndexOutOfRangeException>(() => i = grid[10, 0]);
            Assert.Catch<IndexOutOfRangeException>(() => i = grid[0, 10]);

            // setter
            Assert.Catch<IndexOutOfRangeException>(() => grid[-1, 0] = 5);
            Assert.Catch<IndexOutOfRangeException>(() => grid[0, -1] = 5);
            Assert.Catch<IndexOutOfRangeException>(() => grid[10, 0] = 5);
            Assert.Catch<IndexOutOfRangeException>(() => grid[0, 10] = 5);
        }

22. Example

Project: SwissArmyLib
Source File: Grid3DTests.cs
View license
[Test]
        public void OutOfBoundsThrowsException()
        {
            var grid = new Grid3D<int>(10, 10, 10);
            var i = 0;
            
            // getter
            Assert.Catch<IndexOutOfRangeException>(() => i = grid[-1, 0, 0]);
            Assert.Catch<IndexOutOfRangeException>(() => i = grid[0, -1, 0]);
            Assert.Catch<IndexOutOfRangeException>(() => i = grid[0, 0, -1]);
            Assert.Catch<IndexOutOfRangeException>(() => i = grid[10, 0, 0]);
            Assert.Catch<IndexOutOfRangeException>(() => i = grid[0, 10, 0]);
            Assert.Catch<IndexOutOfRangeException>(() => i = grid[0, 0, 10]);

            // setter
            Assert.Catch<IndexOutOfRangeException>(() => grid[-1, 0, 0] = 5);
            Assert.Catch<IndexOutOfRangeException>(() => grid[0, -1, 0] = 5);
            Assert.Catch<IndexOutOfRangeException>(() => grid[0, 0, -1] = 5);
            Assert.Catch<IndexOutOfRangeException>(() => grid[10, 0, 0] = 5);
            Assert.Catch<IndexOutOfRangeException>(() => grid[0, 10, 0] = 5);
            Assert.Catch<IndexOutOfRangeException>(() => grid[0, 0, 10] = 5);
        }

23. Example

Project: NSubstitute
Source File: ThrowingExceptions.cs
View license
[Test]
        public void ThrowOtherException()
        {
            _something.Count().Throws(new InvalidOperationException());

            Assert.Catch<InvalidOperationException>(() => _something.Count());
        }

24. Example

Project: NSubstitute
Source File: ThrowingExceptions.cs
View license
[Test]
        public void ThrowExceptionUsingFactoryFunc()
        {
            _something.Anything(null).Throws(ci => new ArgumentException("Args:" + ci.Args()[0]));

            Assert.Catch<ArgumentException>(() => _something.Anything(null));
        }

25. Example

Project: NSubstitute
Source File: ThrowingExceptions.cs
View license
[Test]
        public void ThrowExceptionForAnyArgs()
        {
            _something.Anything(12).ThrowsForAnyArgs(new Exception());

            Assert.Catch<Exception>(() => _something.Anything(null));
            Assert.Catch<Exception>(() => _something.Anything(12));
        }

26. Example

Project: NSubstitute
Source File: ThrowingExceptions.cs
View license
[Test]
        public void ThrowExceptionCreatedByFactoryFuncForAnyArgs()
        {
            _something.Anything(null).ThrowsForAnyArgs(ci => new ArgumentException("Args:" + ci.Args()[0]));

            Assert.Catch<ArgumentException>(() => _something.Anything(new object()));
        }

27. Example

Project: NSubstitute
Source File: ThrowingExceptions.cs
View license
[Test]
        public void ThrowException()
        {
            _something.Count().Throws(new Exception());            

            Assert.Catch<Exception>(() => _something.Count());
        }

28. Example

Project: NSubstitute
Source File: ThrowingExceptions.cs
View license
[Test]
        public void ThrowExceptionWithDefaultConstructorForAnyArgs()
        {
            _something.Anything(12).ThrowsForAnyArgs<InvalidOperationException>();

            Assert.Catch<InvalidOperationException>(() => _something.Anything(new object()));
        }

29. Example

Project: NSubstitute
Source File: ThrowingExceptions.cs
View license
[Test]
        public void ThrowExceptionWithDefaultConstructor()
        {
            _something.Count().Throws<ArgumentException>();

            Assert.Catch<ArgumentException>(() => _something.Count());
        }

30. Example

Project: Pash
Source File: HereStringTests.cs
View license
[Test] // @"...'@ throws
        public void MixExpandableVerbatimSytnax()
        {
            Assert.Catch<ParseException>(delegate
            {
                ReferenceHost.Execute("@\"\r\nfoo bar\r\n'@");
            });
        }

31. Example

Project: Cilador
Source File: ClonerBaseFixture.cs
View license
[Test]
        public void MustCreateTargetTest()
        {
            var source = new object();
            var cloner = new BadCloner(new FakeCloningConext(), source);
            Assert.Catch(() => { var t = cloner.Target; });
        }

32. Example

Project: Buildron
Source File: ModPreferenceProxyTest.cs
View license
[Test]
        public void RemoveValue_NotRegisteredPreference_Exception()
        {
            var info = new ModInfo("test");
            var target = new ModPreferencesProxy(info);
            var preferences = new Preference[]
            {
                new Preference("P1", "Preference one", PreferenceKind.String, "one"),
            };
			target.Register(preferences);

            Assert.Catch<ArgumentException>(() => target.RemoveValue<string>("two"));
        }

33. Example

Project: Buildron
Source File: ModPreferenceProxyTest.cs
View license
[Test]
        public void GetValue_NotRegisteredPreference_Exception()
        {
            var info = new ModInfo("test");
            var target = new ModPreferencesProxy(info);
            var preferences = new Preference[]
            {
                new Preference("P1", "Preference one", PreferenceKind.String, "one"),
            };

			target.Register(preferences);

            Assert.Catch<ArgumentException>(() => target.GetValue<string>("two"));
        }

34. Example

Project: Buildron
Source File: ModPreferenceProxyTest.cs
View license
[Test]
        public void GetValue_RegisteredPreferenceDefaultInvalidKind_Exception()
        {
            var info = new ModInfo("test");
            var target = new ModPreferencesProxy(info);
            var preferences = new Preference[]
            {
				new Preference("P1", "Preference one", PreferenceKind.Int, 1),
            };
			target.Register(preferences);
			target.RemoveValue<int> ("P1");
		
            Assert.Catch<InvalidCastException>(() => target.GetValue<string>("P1"));
        }

35. Example

Project: Buildron
Source File: ModPreferenceProxyTest.cs
View license
[Test]
        public void SetValue_NotRegisteredPreference_Exception()
        {
            var info = new ModInfo("test");
            var target = new ModPreferencesProxy(info);
            var preferences = new Preference[]
            {
                new Preference("P1", "Preference one", PreferenceKind.String, "one"),
            };
			target.Register(preferences);

            Assert.Catch<ArgumentException>(() => target.SetValue("two", "2"));
        }

36. Example

Project: riak-dotnet-client
Source File: QuorumTests.cs
View license
[Test]
        public void NegOne_IsInvalidQuorum()
        {
            Assert.Catch<ArgumentOutOfRangeException>(() => new Quorum(-1));
        }

37. Example

View license
[Test]
        public void RiakObject_RequiresNonNullNonEmptyBucketName()
        {
            Assert.Catch<ArgumentOutOfRangeException>(
                () => new RiakObject((string)null, Key, "value"),
                "Expected ArgumentOutOfRangeException");
        }

38. Example

Project: riak-dotnet-client
Source File: TimeoutTests.cs
View license
[Test]
        public void WhenUsingInvalidTimeout_ThrowsArgumentException()
        {
            Assert.Catch<ArgumentOutOfRangeException>(() => new Timeout(-1));
        }

39. Example

Project: riak-dotnet-client
Source File: QuorumTests.cs
View license
[Test]
        public void WhenUsingInvalidQuorumString_ThrowsArgumentException()
        {
            Assert.Catch<ArgumentNullException>(() => new Quorum(string.Empty));
            Assert.Catch<ArgumentOutOfRangeException>(() => new Quorum("frazzle"));
        }

40. Example

View license
[Test]
        public void RiakObjectId_RequiresNonNullNonEmptyBucketName()
        {
            Assert.Catch<ArgumentOutOfRangeException>(
                () => new RiakObjectId((string)null, Key),
                "Expected ArgumentOutOfRangeException");
        }

41. Example

View license
[Test]
        public void RiakObject_RequiresNonNullObjectId()
        {
            Assert.Catch<ArgumentNullException>(
                () => new RiakObject((RiakObjectId)null, Key, "value"),
                "Expected ArgumentOutOfRangeException");
        }

42. Example

Project: riak-dotnet-client
Source File: NValTests.cs
View license
[Test]
        public void WhenUsingInvalidNVal_ThrowsArgumentException()
        {
            Assert.Catch<ArgumentOutOfRangeException>(() => new NVal(-1));
            Assert.Catch<ArgumentOutOfRangeException>(() => new NVal(0));
        }

43. Example

Project: riak-dotnet-client
Source File: QuorumTests.cs
View license
[Test]
        public void OtherNegValues_AreInvalidQuorums()
        {
            Assert.Catch<ArgumentOutOfRangeException>(() => new Quorum(-32));
            Assert.Catch<ArgumentOutOfRangeException>(() => new Quorum(-1024));
        }

44. Example

Project: riak-dotnet-client
Source File: TimeoutTests.cs
View license
[Test]
        public void OtherNegValues_AreInvalidTimeouts()
        {
            Assert.Catch<ArgumentOutOfRangeException>(() => new Timeout(-32));
            Assert.Catch<ArgumentOutOfRangeException>(() => new Timeout(-1024));
        }

45. Example

Project: sqlformat
Source File: TestSetStatements.cs
View license
[Test]
        public void Set_Boolean_Option_With_Invalid_Value()
        {
            // Setup
            var sql = "SET XACT_ABORT BLAH";

            // Exercise
            Assert.Catch<SyntaxException>(() => ParserFactory.Execute<SetOptionStatement>(sql));
        }

46. Example

Project: sqlformat
Source File: TestIfStatements.cs
View license
[Test]
        public void Declare_Statement_With_No_Variables_Should_Fail()
        {
            // Setup
            var sql = "IF";

            // Exercise
            Assert.Catch<SyntaxException>(
                () => ParserFactory.Execute<IfStatement>(sql),
                "missing condition for IF"
            );
        }

47. Example

View license
[Test]
        public void When_Join_Is_Missing_On_Clause_Throw_SyntaxError()
        {
            var sql = @"
                select * from Table Outer
                join (
                    select * from Table
                ) Inner --on inner.Value = Outer.Value
            ";

            Assert.Catch<ExpectedTokenNotFoundException>(
                () => ParserFactory.Execute<SelectStatement>(sql),
                "Expected: 'ON' but found: 'EOF' at Row: 6, Col: 13"
            );
        }

48. Example

Project: sqlformat
Source File: TestSetStatements.cs
View license
[Test]
        public void Set_Unknown_Option()
        {
            // Setup
            var sql = "SET BLAH OFF";

            // Exercise
            Assert.Catch<ParserNotImplementedException>(() => ParserFactory.Execute<SetOptionStatement>(sql));
        }

49. Example

View license
[Test]
        public void TestExpectedError()
        {
            // Exercise
            Assert.Catch<ExpectedTokenNotFoundException>(
                () => ParserFactory.Execute<SelectStatement>("select * from table order field").First(),
                "Expected: 'BY' but found: 'field' at Row: 1, Col: 27"
            );
        }

50. Example

Project: sqlformat
Source File: TestIfStatements.cs
View license
[Test]
        public void If_Statement_Without_Statement_Should_Fail()
        {
            // Setup
            var sql = "IF @A = 1";

            // Exercise
            Assert.Catch<SyntaxException>(
                () => ParserFactory.Execute<IfStatement>(sql),
                "missing success block for IF"
            );
        }