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
0
101. Example
Project: Mages
Source File: OperationTests.cs
Source File: OperationTests.cs
[Test] public void InvalidAssignmentPipeWithNumberYieldsError() { Assert.Catch<ParseException>(() => "x = 0; x | = factorial; x".Eval()); }
0
102. Example
Project: GeneticSharp
Source File: BinaryStringRepresentationTest.cs
Source File: BinaryStringRepresentationTest.cs
[Test] public void ToRepresentation_ValuesLenghtDiffTotalBits_Exception() { Assert.Catch<ArgumentException>(delegate { BinaryStringRepresentation.ToRepresentation(new long[] { 1L, 2L, 3L }, new int[] { 4, 6 }); }); }
0
103. Example
Project: GeneticSharp
Source File: BinaryStringRepresentationTest.cs
Source File: BinaryStringRepresentationTest.cs
[Test] public void ToInt64_RepresentationLengthDiffThanTotalBitsSum_Exception() { Assert.Catch<ArgumentException>(delegate { BinaryStringRepresentation.ToInt64("000100001000000011", new int[] { 4, 6, 9 }); }); }
0
104. Example
Project: NodaTime
Source File: InstantTest.Parse.cs
Source File: InstantTest.Parse.cs
[Test, Category("Formatting"), Category("Parse")] public void TestParse_BadValue() { Assert.Catch<FormatException>(() => Instant.Parse("ads")); }
0
105. Example
Project: NodaTime
Source File: InstantTest.Parse.cs
Source File: InstantTest.Parse.cs
[Test, Category("Formatting"), Category("Parse")] public void TestParse_N_extraSpace() { Assert.Catch<FormatException>(() => Instant.Parse(" " + threeMillion.Ticks.ToString("N0"))); }
0
106. Example
Project: Simplify
Source File: FileHelperTester.cs
Source File: FileHelperTester.cs
[Test] public void IsFileLockedForRead() { Assert.Catch<ArgumentNullException>(() => FileHelper.IsFileLockedForRead(null)); Assert.Catch<FileNotFoundException>(() => FileHelper.IsFileLockedForRead("NotFound")); }
0
107. Example
Project: Nustache
Source File: Describe_Parser.cs
Source File: Describe_Parser.cs
[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") })); }
0
108. Example
Project: Nustache
Source File: Describe_Parser.cs
Source File: Describe_Parser.cs
[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") })); }
0
109. Example
Project: Benchmarkable
Source File: BenchmarkTests.cs
Source File: BenchmarkTests.cs
[Test()] public void TestSingleWithException() { Assert.Catch<NullReferenceException>(() => Benchmark.Just.This(() => { throw new NullReferenceException(); })); }
0
110. Example
Project: Benchmarkable
Source File: BenchmarkTests.cs
Source File: BenchmarkTests.cs
[Test()] public void ThrowsExceptionIfNoMethods() { var bench = new Benchmark(); Assert.Catch<ArgumentOutOfRangeException>(() => bench.Run()); }
0
111. Example
Project: linq2db
Source File: AggregationTests.cs
Source File: AggregationTests.cs
[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()); } }
0
112. Example
Project: AngleSharp
Source File: CssSelector.cs
Source File: CssSelector.cs
[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); }); }
0
113. Example
Project: AngleSharp
Source File: CssW3CSelector.cs
Source File: CssW3CSelector.cs
[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")); }
0
114. Example
Project: AngleSharp
Source File: XmlTree.cs
Source File: XmlTree.cs
[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()); }
0
115. Example
Project: journeyofcode
Source File: SingleThreadTaskSchedulerTests.cs
Source File: SingleThreadTaskSchedulerTests.cs
[Test] public void Cannot_Construct_Using_Invalid_Apartement_State() { Assert.Catch<ArgumentException>(() => new SingleThreadTaskScheduler(ApartmentState.Unknown)); Assert.Catch<ArgumentException>(() => new SingleThreadTaskScheduler(() => { }, ApartmentState.Unknown)); }
0
116. Example
Project: journeyofcode
Source File: TaskLazyTests.cs
Source File: TaskLazyTests.cs
[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; }); }
0
117. Example
Project: CppSharp
Source File: Common.Tests.cs
Source File: Common.Tests.cs
[Test] public void TestPassingNullToRef() { using (var foo = new Foo()) { Assert.Catch<ArgumentNullException>(() => foo.TakesRef(null)); } }
0
118. Example
Project: SwissArmyLib
Source File: Grid2DTests.cs
Source File: Grid2DTests.cs
[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); }
0
119. Example
Project: SwissArmyLib
Source File: Grid3DTests.cs
Source File: Grid3DTests.cs
[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); }
0
120. Example
Project: NSubstitute
Source File: ThrowingExceptions.cs
Source File: ThrowingExceptions.cs
[Test] public void ThrowException() { _something.Count().Throws(new Exception()); Assert.Catch<Exception>(() => _something.Count()); }
0
121. Example
Project: NSubstitute
Source File: ThrowingExceptions.cs
Source File: ThrowingExceptions.cs
[Test] public void ThrowOtherException() { _something.Count().Throws(new InvalidOperationException()); Assert.Catch<InvalidOperationException>(() => _something.Count()); }
0
122. Example
Project: NSubstitute
Source File: ThrowingExceptions.cs
Source File: ThrowingExceptions.cs
[Test] public void ThrowExceptionWithDefaultConstructor() { _something.Count().Throws<ArgumentException>(); Assert.Catch<ArgumentException>(() => _something.Count()); }
0
123. Example
Project: NSubstitute
Source File: ThrowingExceptions.cs
Source File: ThrowingExceptions.cs
[Test] public void ThrowExceptionUsingFactoryFunc() { _something.Anything(null).Throws(ci => new ArgumentException("Args:" + ci.Args()[0])); Assert.Catch<ArgumentException>(() => _something.Anything(null)); }
0
124. Example
Project: NSubstitute
Source File: ThrowingExceptions.cs
Source File: ThrowingExceptions.cs
[Test] public void ThrowExceptionForAnyArgs() { _something.Anything(12).ThrowsForAnyArgs(new Exception()); Assert.Catch<Exception>(() => _something.Anything(null)); Assert.Catch<Exception>(() => _something.Anything(12)); }
0
125. Example
Project: NSubstitute
Source File: ThrowingExceptions.cs
Source File: ThrowingExceptions.cs
[Test] public void ThrowExceptionWithDefaultConstructorForAnyArgs() { _something.Anything(12).ThrowsForAnyArgs<InvalidOperationException>(); Assert.Catch<InvalidOperationException>(() => _something.Anything(new object())); }
0
126. Example
Project: NSubstitute
Source File: ThrowingExceptions.cs
Source File: ThrowingExceptions.cs
[Test] public void ThrowExceptionCreatedByFactoryFuncForAnyArgs() { _something.Anything(null).ThrowsForAnyArgs(ci => new ArgumentException("Args:" + ci.Args()[0])); Assert.Catch<ArgumentException>(() => _something.Anything(new object())); }
0
127. Example
Project: Pash
Source File: HereStringTests.cs
Source File: HereStringTests.cs
[Test] // @"...'@ throws public void MixExpandableVerbatimSytnax() { Assert.Catch<ParseException>(delegate { ReferenceHost.Execute("@\"\r\nfoo bar\r\n'@"); }); }
0
128. Example
Project: Cilador
Source File: ClonerBaseFixture.cs
Source File: ClonerBaseFixture.cs
[Test] public void MustCreateTargetTest() { var source = new object(); var cloner = new BadCloner(new FakeCloningConext(), source); Assert.Catch(() => { var t = cloner.Target; }); }
0
129. Example
Project: Buildron
Source File: ModPreferenceProxyTest.cs
Source File: ModPreferenceProxyTest.cs
[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")); }
0
130. Example
Project: Buildron
Source File: ModPreferenceProxyTest.cs
Source File: ModPreferenceProxyTest.cs
[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")); }
0
131. Example
Project: Buildron
Source File: ModPreferenceProxyTest.cs
Source File: ModPreferenceProxyTest.cs
[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")); }
0
132. Example
Project: Buildron
Source File: ModPreferenceProxyTest.cs
Source File: ModPreferenceProxyTest.cs
[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")); }
0
133. Example
Project: riak-dotnet-client
Source File: NValTests.cs
Source File: NValTests.cs
[Test] public void WhenUsingInvalidNVal_ThrowsArgumentException() { Assert.Catch<ArgumentOutOfRangeException>(() => new NVal(-1)); Assert.Catch<ArgumentOutOfRangeException>(() => new NVal(0)); }
0
134. Example
Project: riak-dotnet-client
Source File: QuorumTests.cs
Source File: QuorumTests.cs
[Test] public void WhenUsingInvalidQuorumString_ThrowsArgumentException() { Assert.Catch<ArgumentNullException>(() => new Quorum(string.Empty)); Assert.Catch<ArgumentOutOfRangeException>(() => new Quorum("frazzle")); }
0
135. Example
Project: riak-dotnet-client
Source File: QuorumTests.cs
Source File: QuorumTests.cs
[Test] public void NegOne_IsInvalidQuorum() { Assert.Catch<ArgumentOutOfRangeException>(() => new Quorum(-1)); }
0
136. Example
Project: riak-dotnet-client
Source File: QuorumTests.cs
Source File: QuorumTests.cs
[Test] public void OtherNegValues_AreInvalidQuorums() { Assert.Catch<ArgumentOutOfRangeException>(() => new Quorum(-32)); Assert.Catch<ArgumentOutOfRangeException>(() => new Quorum(-1024)); }
0
137. Example
Project: riak-dotnet-client
Source File: RiakObjectTests.cs
Source File: RiakObjectTests.cs
[Test] public void RiakObject_RequiresNonNullNonEmptyBucketName() { Assert.Catch<ArgumentOutOfRangeException>( () => new RiakObject((string)null, Key, "value"), "Expected ArgumentOutOfRangeException"); }
0
138. Example
Project: riak-dotnet-client
Source File: RiakObjectTests.cs
Source File: RiakObjectTests.cs
[Test] public void RiakObjectId_RequiresNonNullNonEmptyBucketName() { Assert.Catch<ArgumentOutOfRangeException>( () => new RiakObjectId((string)null, Key), "Expected ArgumentOutOfRangeException"); }
0
139. Example
Project: riak-dotnet-client
Source File: RiakObjectTests.cs
Source File: RiakObjectTests.cs
[Test] public void RiakObject_RequiresNonNullObjectId() { Assert.Catch<ArgumentNullException>( () => new RiakObject((RiakObjectId)null, Key, "value"), "Expected ArgumentOutOfRangeException"); }
0
140. Example
Project: riak-dotnet-client
Source File: TimeoutTests.cs
Source File: TimeoutTests.cs
[Test] public void WhenUsingInvalidTimeout_ThrowsArgumentException() { Assert.Catch<ArgumentOutOfRangeException>(() => new Timeout(-1)); }
0
141. Example
Project: riak-dotnet-client
Source File: TimeoutTests.cs
Source File: TimeoutTests.cs
[Test] public void OtherNegValues_AreInvalidTimeouts() { Assert.Catch<ArgumentOutOfRangeException>(() => new Timeout(-32)); Assert.Catch<ArgumentOutOfRangeException>(() => new Timeout(-1024)); }
0
142. Example
Project: sqlformat
Source File: TestIfStatements.cs
Source File: TestIfStatements.cs
[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" ); }
0
143. Example
Project: sqlformat
Source File: TestIfStatements.cs
Source File: TestIfStatements.cs
[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" ); }
0
144. Example
Project: sqlformat
Source File: TestSelectStatementParser.cs
Source File: TestSelectStatementParser.cs
[Test] public void TestNoParserException() { // Exercise Assert.Catch<ParserNotImplementedException>( () => ParserFactory.Execute<SelectStatement>("merge from table").First(), "No parser exists for statement type: merge" ); }
0
145. Example
Project: sqlformat
Source File: TestSelectStatementParser.cs
Source File: TestSelectStatementParser.cs
[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" ); }
0
146. Example
Project: sqlformat
Source File: TestSelectStatementParser.cs
Source File: TestSelectStatementParser.cs
[Test] public void Should_Fail_With_ExpectedSyntaxError_When_Using_Reserved_Word_As_Alias() { // Exercise Assert.Catch<SyntaxException>( () => ParserFactory.Execute<SelectStatement>("select * from table select").First(), "Identifier expected" ); }
0
147. Example
Project: sqlformat
Source File: TestSelectStatementParser.cs
Source File: TestSelectStatementParser.cs
[Test] public void Select_Top_Missing_Top_Param_StarField() { // Exercise Assert.Catch<SyntaxException>( () => ParserFactory.Execute<SelectStatement>("select top * from table").First(), "Expected integer but found: '*'" ); }
0
148. Example
Project: sqlformat
Source File: TestSelectStatementParser.cs
Source File: TestSelectStatementParser.cs
[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" ); }
0
149. Example
Project: sqlformat
Source File: TestSetStatements.cs
Source File: TestSetStatements.cs
[Test] public void Set_Boolean_Option_With_Invalid_Value() { // Setup var sql = "SET XACT_ABORT BLAH"; // Exercise Assert.Catch<SyntaxException>(() => ParserFactory.Execute<SetOptionStatement>(sql)); }
0
150. Example
Project: sqlformat
Source File: TestSetStatements.cs
Source File: TestSetStatements.cs
[Test] public void Set_Statistics_With_Invalid_Value() { // Setup var sql = "SET STATISTICS BLAH OFF"; // Exercise Assert.Catch<SyntaxException>(() => ParserFactory.Execute<SetOptionStatement>(sql)); }