311 references to Throws
InMemory.FunctionalTests (1)
HttpsConnectionMiddlewareTests.cs (1)
1451Assert.Throws<NotSupportedException>(() => CreateMiddleware(httpConnectionAdapterOptions, HttpProtocols.Http2));
Microsoft.AspNetCore.Components.Tests (7)
Rendering\ArrayBuilderTest.cs (1)
295Assert.Throws<ObjectDisposedException>(() => builder.Append(1));
Routing\RouteTableFactoryTests.cs (6)
803Assert.Throws<InvalidOperationException>(() => new TestRouteTableBuilder() 821Assert.Throws<RoutePatternException>(() => new TestRouteTableBuilder() 836Assert.Throws<InvalidOperationException>(() => new TestRouteTableBuilder() 847var exception = Assert.Throws<InvalidOperationException>(() => new TestRouteTableBuilder() 900Assert.Throws<RoutePatternException>(() => new TestRouteTableBuilder() 1044var exception = Assert.Throws<InvalidOperationException>(() => new TestRouteTableBuilder()
Microsoft.AspNetCore.DataProtection.Extensions.Tests (3)
TimeLimitedDataProtectorTests.cs (3)
126var ex = Assert.Throws<CryptographicException>(() 143var ex = Assert.Throws<CryptographicException>(() 171Assert.Throws<CryptographicException>(() => timeLimitedProtector.Unprotect(ephemeralProtectedPayload, out actualExpiration));
Microsoft.AspNetCore.DataProtection.Tests (1)
ActivatorTests.cs (1)
62var ex = Assert.Throws<InvalidCastException>(
Microsoft.AspNetCore.Http.Abstractions.Tests (3)
EndpointFilterInvocationContextOfTTests.cs (3)
16Assert.Throws<NotSupportedException>(() => context.Remove("string")); 17Assert.Throws<NotSupportedException>(() => context.Clear()); 43Assert.Throws<InvalidCastException>(() => context[0] = 4);
Microsoft.AspNetCore.Http.Extensions.Tests (6)
ParameterBindingMethodCacheTests.cs (6)
618var ex = Assert.Throws<InvalidOperationException>( 642var ex = Assert.Throws<InvalidOperationException>(() => cache.FindBindAsyncMethod(parameter)); 683var ex = Assert.Throws<InvalidOperationException>(() => cache.FindConstructor(type)); 693var ex = Assert.Throws<InvalidOperationException>(() => cache.FindConstructor(type)); 703var ex = Assert.Throws<InvalidOperationException>(() => cache.FindConstructor(type)); 715var ex = Assert.Throws<InvalidOperationException>(() => cache.FindConstructor(type));
Microsoft.AspNetCore.Http.Tests (1)
ResponseCookiesTest.cs (1)
270Assert.Throws<ArgumentException>(() => cookies.Append(key, "1"));
Microsoft.AspNetCore.Mvc.RazorPages.Test (2)
Infrastructure\DefaultPageHandlerMethodSelectorTest.cs (2)
661var ex = Assert.Throws<InvalidOperationException>(() => selector.Select(pageContext)); 721var ex = Assert.Throws<InvalidOperationException>(() => selector.Select(pageContext));
Microsoft.AspNetCore.Routing.Tests (4)
Builder\GroupTest.cs (4)
138var ex = Assert.Throws<ArgumentNullException>(() => builder.MapGroup((string)null!)); 140ex = Assert.Throws<ArgumentNullException>(() => builder.MapGroup((RoutePattern)null!)); 145ex = Assert.Throws<ArgumentNullException>(() => builder!.MapGroup(RoutePatternFactory.Parse("/"))); 147ex = Assert.Throws<ArgumentNullException>(() => builder!.MapGroup("/"));
Microsoft.AspNetCore.Server.HttpSys.FunctionalTests (5)
Listener\RequestBodyTests.cs (1)
31Assert.Throws<InvalidOperationException>(() => context.Request.Body.Read(input, 0, input.Length));
Listener\ResponseBodyTests.cs (4)
31Assert.Throws<InvalidOperationException>(() => context.Response.Body.Flush()); 32Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(new byte[10], 0, 10)); 33Assert.Throws<InvalidOperationException>(() => context.Response.Body.Flush()); 261Assert.Throws<ObjectDisposedException>(() => context.Response.Body.Write(Utilities.WriteBuffer, 0, Utilities.WriteBuffer.Length));
Microsoft.AspNetCore.Server.Kestrel.Core.Tests (7)
HttpRequestHeadersTests.cs (2)
401var exception = Assert.Throws<BadHttpRequestException>( 685Assert.Throws<InvalidOperationException>(() => headers.Append(acceptNameBytes, headerValueBytes, checkForNewlineChars: false));
HttpResponseHeadersTests.cs (2)
267Assert.Throws<InvalidOperationException>(() => ((IDictionary<string, StringValues>)headers).Add("my-header", new[] { "value" })); 330var exception = Assert.Throws<InvalidOperationException>(() => ((IHeaderDictionary)headers)["Content-Length"] = contentLength);
KestrelServerTests.cs (1)
318var exception = Assert.Throws<InvalidOperationException>(() =>
src\Shared\test\Shared.Tests\runtime\Http2\DynamicTableTest.cs (2)
67Assert.Throws<IndexOutOfRangeException>(() => dynamicTable[0]); 70Assert.Throws<IndexOutOfRangeException>(() => dynamicTable[1]);
Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests (4)
QuicConnectionContextTests.cs (1)
764Assert.Throws<ArgumentOutOfRangeException>(() => protocolErrorCodeFeature.Error = errorCode);
QuicStreamContextTests.cs (3)
554Assert.Throws<ArgumentOutOfRangeException>(() => protocolErrorCodeFeature.Error = errorCode); 581Assert.Throws<ArgumentOutOfRangeException>(() => protocolErrorCodeFeature.AbortRead(errorCode, new ConnectionAbortedException())); 582Assert.Throws<ArgumentOutOfRangeException>(() => protocolErrorCodeFeature.AbortWrite(errorCode, new ConnectionAbortedException()));
Microsoft.AspNetCore.SignalR.Tests (1)
Internal\MessageBufferTests.cs (1)
237Assert.Throws<InvalidOperationException>(() => messageBuffer.ShouldProcessMessage(new SequenceMessage(2)));
Microsoft.CodeAnalysis.CSharp.Emit.UnitTests (5)
CodeGen\CodeGenTupleTest.cs (3)
6283var e = Assert.Throws<ArgumentException>(() => comp.CreateTupleTypeSymbol(intType)); 6871var e = Assert.Throws<ArgumentException>(() => comp.CreateTupleTypeSymbol(elementTypes, elementNullableAnnotations: ImmutableArray<CodeAnalysis.NullableAnnotation>.Empty)); 6911var e = Assert.Throws<ArgumentException>(() => comp.CreateTupleTypeSymbol(elementTypes, elementNullableAnnotations: CreateAnnotations(CodeAnalysis.NullableAnnotation.NotAnnotated, 8)));
Emit\CompilationEmitTests.cs (2)
5488Assert.Throws<OperationCanceledException>(() => comp.Emit(peStream, 5510Assert.Throws<OperationCanceledException>(() => compilation.Emit(broken));
Microsoft.CodeAnalysis.CSharp.Emit2.UnitTests (1)
PDB\PDBTests.cs (1)
106Assert.Throws<ArgumentException>(() => context.AddSource("hint3", SourceText.From("class G3 { void F() {} }", encoding: null, checksumAlgorithm: SourceHashAlgorithm.Sha256)));
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (10)
Attributes\AttributeTests.cs (6)
5757Assert.Throws<InvalidOperationException>(() => args[0].Value); 5761Assert.Throws<InvalidOperationException>(() => args[1].Value); 5767Assert.Throws<InvalidOperationException>(() => named["P"].Value); 5771Assert.Throws<InvalidOperationException>(() => named["F"].Value); 5801Assert.Throws<InvalidOperationException>(() => args[0].Values); 5805Assert.Throws<InvalidOperationException>(() => args[1].Values);
Attributes\AttributeTests_WellKnownAttributes.cs (4)
865Assert.Throws<InvalidOperationException>(() => ps[0].ExplicitDefaultValue); 931Assert.Throws<InvalidOperationException>(() => ps[0].ExplicitDefaultValue); 1020Assert.Throws<InvalidOperationException>(() => ps[0].ExplicitDefaultValue); 1064Assert.Throws<InvalidOperationException>(() => ps[0].ExplicitDefaultValue);
Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests (25)
Semantics\AccessCheckTests.cs (2)
1525Assert.Throws<ArgumentException>(() => ((Compilation)comp2).IsSymbolAccessibleWithin(ptr1, b)); 1526Assert.Throws<ArgumentException>(() => ((Compilation)comp2).IsSymbolAccessibleWithin(ptr2, b));
Semantics\MemberResolutionResultTests.cs (1)
23Assert.Throws<NotSupportedException>(() => d.Equals(d));
Semantics\NamedAndOptionalTests.cs (18)
2054Assert.Throws<InvalidOperationException>(() => parameters[0].ExplicitDefaultValue); 2072Assert.Throws<InvalidOperationException>(() => parameters[3].ExplicitDefaultValue); 2078Assert.Throws<InvalidOperationException>(() => parameters[4].ExplicitDefaultValue); 2085Assert.Throws<InvalidOperationException>(() => parameters[5].ExplicitDefaultValue); 2137Assert.Throws<InvalidOperationException>(() => parameters[0].ExplicitDefaultValue); 2148Assert.Throws<InvalidOperationException>(() => parameters[2].ExplicitDefaultValue); 2187Assert.Throws<InvalidOperationException>(() => parameters[0].ExplicitDefaultValue); 2205Assert.Throws<InvalidOperationException>(() => parameters[3].ExplicitDefaultValue); 2211Assert.Throws<InvalidOperationException>(() => parameters[4].ExplicitDefaultValue); 2224Assert.Throws<InvalidOperationException>(() => parameters[6].ExplicitDefaultValue); 2270Assert.Throws<InvalidOperationException>(() => parameters[0].ExplicitDefaultValue); 2288Assert.Throws<InvalidOperationException>(() => parameters[3].ExplicitDefaultValue); 2294Assert.Throws<InvalidOperationException>(() => parameters[4].ExplicitDefaultValue); 2301Assert.Throws<InvalidOperationException>(() => parameters[5].ExplicitDefaultValue); 2352Assert.Throws<InvalidOperationException>(() => parameters[0].ExplicitDefaultValue); 2364Assert.Throws<InvalidOperationException>(() => parameters[2].ExplicitDefaultValue); 2370Assert.Throws<InvalidOperationException>(() => parameters[3].ExplicitDefaultValue); 2377Assert.Throws<InvalidOperationException>(() => parameters[4].ExplicitDefaultValue);
SourceGeneration\GeneratorDriverTests.cs (4)
1653Assert.Throws<UserFunctionException>(() => userThrowsFunc(20, CancellationToken.None)); 1666Assert.Throws<OperationCanceledException>(() => userTimeoutFunc(30, new CancellationToken(true))); 1670Assert.Throws<UserFunctionException>(() => userOtherTimeoutFunc(30, CancellationToken.None)); 2874Assert.Throws<ArgumentNullException>(() => driver.ReplaceAdditionalText(additionalText1, null!));
Microsoft.CodeAnalysis.CSharp.Symbol.UnitTests (7)
Symbols\ExtensionMethodTests.cs (3)
2699Assert.Throws<ArgumentNullException>(() => nonGenericExtension.ReduceExtensionMethod(receiverType: null, compilation: null!)); 2702Assert.Throws<ArgumentNullException>(() => genericExtension.ReduceExtensionMethod(receiverType: null, compilation: null!)); 2743Assert.Throws<InvalidOperationException>(() => methodSymbol.ThisParameter);
Symbols\Retargeting\RetargetCustomAttributes.cs (4)
309Assert.Throws<InvalidOperationException>(() => args[0].Value); 313Assert.Throws<InvalidOperationException>(() => args[1].Value); 319Assert.Throws<InvalidOperationException>(() => named["P"].Value); 323Assert.Throws<InvalidOperationException>(() => named["F"].Value);
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (37)
Syntax\SeparatedSyntaxListTests.cs (8)
219Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, nodeD)); 221Assert.Throws<ArgumentOutOfRangeException>(() => list.InsertRange(-1, new[] { nodeD })); 223Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(-1)); 225Assert.Throws<ArgumentOutOfRangeException>(() => list.Replace(nodeD, nodeE)); 226Assert.Throws<ArgumentOutOfRangeException>(() => list.ReplaceRange(nodeD, new[] { nodeE })); 227Assert.Throws<ArgumentNullException>(() => list.AddRange((IEnumerable<SyntaxNode>)null)); 228Assert.Throws<ArgumentNullException>(() => list.InsertRange(0, (IEnumerable<SyntaxNode>)null)); 229Assert.Throws<ArgumentNullException>(() => list.ReplaceRange(elementA, (IEnumerable<SyntaxNode>)null));
Syntax\SyntaxListTests.cs (9)
171Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, nodeD)); 173Assert.Throws<ArgumentOutOfRangeException>(() => list.InsertRange(-1, new[] { nodeD })); 175Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(-1)); 176Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(list.Count)); 177Assert.Throws<ArgumentException>(() => list.Replace(nodeD, nodeE)); 178Assert.Throws<ArgumentException>(() => list.ReplaceRange(nodeD, new[] { nodeE })); 179Assert.Throws<ArgumentNullException>(() => list.AddRange((IEnumerable<SyntaxNode>)null)); 180Assert.Throws<ArgumentNullException>(() => list.InsertRange(0, (IEnumerable<SyntaxNode>)null)); 181Assert.Throws<ArgumentNullException>(() => list.ReplaceRange(elementA, (IEnumerable<SyntaxNode>)null));
Syntax\SyntaxNodeOrTokenListTests.cs (11)
158Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, tokenD)); 160Assert.Throws<ArgumentOutOfRangeException>(() => list.InsertRange(-1, new[] { tokenD })); 162Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(-1)); 163Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(list.Count)); 164Assert.Throws<ArgumentOutOfRangeException>(() => list.Replace(tokenD, nameE)); 165Assert.Throws<ArgumentOutOfRangeException>(() => list.ReplaceRange(tokenD, new[] { nameE })); 166Assert.Throws<ArgumentOutOfRangeException>(() => list.Add(default(SyntaxNodeOrToken))); 167Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(0, default(SyntaxNodeOrToken))); 168Assert.Throws<ArgumentNullException>(() => list.AddRange((IEnumerable<SyntaxNodeOrToken>)null)); 169Assert.Throws<ArgumentNullException>(() => list.InsertRange(0, (IEnumerable<SyntaxNodeOrToken>)null)); 170Assert.Throws<ArgumentNullException>(() => list.ReplaceRange(elementA, (IEnumerable<SyntaxNodeOrToken>)null));
Syntax\SyntaxTokenListTests.cs (9)
180Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, tokenD)); 182Assert.Throws<ArgumentOutOfRangeException>(() => list.InsertRange(-1, new[] { tokenD })); 184Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(-1)); 185Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(list.Count)); 186Assert.Throws<ArgumentOutOfRangeException>(() => list.Add(default(SyntaxToken))); 187Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(0, default(SyntaxToken))); 188Assert.Throws<ArgumentNullException>(() => list.AddRange((IEnumerable<SyntaxToken>)null)); 189Assert.Throws<ArgumentNullException>(() => list.InsertRange(0, (IEnumerable<SyntaxToken>)null)); 190Assert.Throws<ArgumentNullException>(() => list.ReplaceRange(elementA, (IEnumerable<SyntaxToken>)null));
Microsoft.CodeAnalysis.Features.UnitTests (4)
EditAndContinue\EditAndContinueWorkspaceServiceTests.cs (4)
4408Assert.Throws<ObjectDisposedException>(() => debuggingSession.BreakStateOrCapabilitiesChanged(inBreakState: true)); 4409Assert.Throws<ObjectDisposedException>(() => debuggingSession.DiscardSolutionUpdate()); 4410Assert.Throws<ObjectDisposedException>(() => debuggingSession.CommitSolutionUpdate()); 4411Assert.Throws<ObjectDisposedException>(() => debuggingSession.EndSession(out _));
Microsoft.CodeAnalysis.UnitTests (85)
Collections\HashSet\SegmentedHashSet_Generic_Tests`1.cs (2)
271Assert.Throws<ArgumentOutOfRangeException>(() => set.CopyTo(arr, 0, -1)); 272Assert.Throws<ArgumentOutOfRangeException>(() => set.CopyTo(arr, 0, int.MinValue));
Collections\ImmutableArrayExtensionsTests.cs (7)
233Assert.Throws<InvalidOperationException>(() => roa.Last()); 235Assert.Throws<InvalidOperationException>(() => roa.Last(i => i < 1)); 257Assert.Throws<InvalidOperationException>(() => roa.SingleOrDefault()); 314Assert.Throws<KeyNotFoundException>(() => dict["One"]); 320Assert.Throws<KeyNotFoundException>(() => dict[""]); 326Assert.Throws<KeyNotFoundException>(() => dict["THREE"]); 332Assert.Throws<KeyNotFoundException>(() => dict["four"]);
Collections\ImmutableSegmentedDictionaryBuilderTest.cs (1)
113Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
Collections\ImmutableSegmentedDictionaryTest.cs (1)
299var exception = Assert.Throws<KeyNotFoundException>(() => map[missingKey]);
Collections\ImmutableSegmentedListBuilderTest.cs (1)
107Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
Collections\ImmutableSegmentedListTest.cs (4)
623Assert.Throws<ArgumentException>(() => list.RemoveRange(4, 0)); 624Assert.Throws<ArgumentException>(() => list.RemoveRange(0, 4)); 625Assert.Throws<ArgumentException>(() => list.RemoveRange(2, 2)); 832Assert.Throws<ArgumentOutOfRangeException>(() => list.ItemRef(5));
Collections\List\SegmentedList.Generic.Tests.AddRange.cs (4)
117Assert.Throws<ArgumentNullException>(() => list.AddRange(null!)); 139Assert.Throws<InvalidOperationException>(() => list.AddRange(list.Where(_ => true))); 141Assert.Throws<InvalidOperationException>(() => list.AddRange(list.Where(_ => true))); 151Assert.Throws<OverflowException>(() => list.AddRange(collection));
Collections\List\SegmentedList.Generic.Tests.BinarySearch.cs (2)
70Assert.Throws<ArgumentOutOfRangeException>(() => list.BinarySearch(-1, count, element, GetIComparer())); //"ArgumentOutOfRangeException should be thrown on negative index." 71Assert.Throws<ArgumentOutOfRangeException>(() => list.BinarySearch(0, -1, element, GetIComparer())); //"ArgumentOutOfRangeException should be thrown on negative count."
Collections\List\SegmentedList.Generic.Tests.IndexOf.cs (20)
196Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, count + 1)); //"Expect ArgumentOutOfRangeException for index greater than length of list.." 197Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, count + 10)); //"Expect ArgumentOutOfRangeException for index greater than length of list.." 198Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, -1)); //"Expect ArgumentOutOfRangeException for negative index." 199Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, int.MinValue)); //"Expect ArgumentOutOfRangeException for negative index." 208Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, count, 1)); //"ArgumentOutOfRangeException expected on index larger than array." 209Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, count + 1, 1)); //"ArgumentOutOfRangeException expected on index larger than array." 210Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, 0, count + 1)); //"ArgumentOutOfRangeException expected on count larger than array." 211Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, count / 2, count / 2 + 2)); //"ArgumentOutOfRangeException expected.." 212Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, 0, count + 1)); //"ArgumentOutOfRangeException expected on count larger than array." 213Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, 0, -1)); //"ArgumentOutOfRangeException expected on negative count." 214Assert.Throws<ArgumentOutOfRangeException>(() => list.IndexOf(element, -1, 1)); //"ArgumentOutOfRangeException expected on negative index." 223Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, count)); //"ArgumentOutOfRangeException expected." 227Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, -1)); 239Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, 0, count + 1)); //"Expected ArgumentOutOfRangeException." 240Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, count / 2, count / 2 + 2)); //"Expected ArgumentOutOfRangeException." 241Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, 0, count + 1)); //"Expected ArgumentOutOfRangeException." 242Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, 0, -1)); //"Expected ArgumentOutOfRangeException." 243Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, -1, count)); //"Expected ArgumentOutOfRangeException." 244Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, -1, 1)); //"Expected ArgumentOutOfRangeException." Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, count, 0)); //"Expected ArgumentOutOfRangeException." 245Assert.Throws<ArgumentOutOfRangeException>(() => list.LastIndexOf(element, count, 1)); //"Expected ArgumentOutOfRangeException."
Collections\List\SegmentedList.Generic.Tests.Misc.cs (2)
187Assert.Throws<ArgumentOutOfRangeException>(() => list.InsertRange(bad[i], constructIEnumerable(items))); //"ArgumentOutOfRangeException expected" 190Assert.Throws<ArgumentNullException>(() => list.InsertRange(0, null!)); //"ArgumentNullException expected."
Collections\List\SegmentedList.Generic.Tests.Reverse.cs (1)
163Assert.Throws<ArgumentOutOfRangeException>(() => list.Reverse(invalidSet.Item1, invalidSet.Item2));
Collections\List\SegmentedList.Generic.Tests.Sort.cs (1)
182Assert.Throws<ArgumentOutOfRangeException>(() => list.Sort(invalidSet.Item1, invalidSet.Item2, GetIComparer()));
Collections\SegmentedArrayTests.cs (20)
52Assert.Throws<NullReferenceException>(() => data[0]); 53Assert.Throws<NullReferenceException>(() => ((IReadOnlyList<IntPtr>)data)[0]); 54Assert.Throws<NullReferenceException>(() => ((IList<IntPtr>)data)[0]); 55Assert.Throws<NullReferenceException>(() => ((IList<IntPtr>)data)[0] = IntPtr.Zero); 64Assert.Throws<NullReferenceException>(() => data.CopyTo(Array.Empty<IntPtr>(), 0)); 65Assert.Throws<NullReferenceException>(() => ((ICollection<IntPtr>)data).CopyTo(Array.Empty<IntPtr>(), 0)); 76Assert.Throws<NotSupportedException>(() => ((IList)data).Add(IntPtr.Zero)); 77Assert.Throws<NotSupportedException>(() => ((ICollection<IntPtr>)data).Add(IntPtr.Zero)); 78Assert.Throws<NotSupportedException>(() => ((ICollection<IntPtr>)data).Clear()); 79Assert.Throws<NotSupportedException>(() => ((IList)data).Insert(0, IntPtr.Zero)); 80Assert.Throws<NotSupportedException>(() => ((IList<IntPtr>)data).Insert(0, IntPtr.Zero)); 81Assert.Throws<NotSupportedException>(() => ((IList)data).Remove(IntPtr.Zero)); 82Assert.Throws<NotSupportedException>(() => ((ICollection<IntPtr>)data).Remove(IntPtr.Zero)); 83Assert.Throws<NotSupportedException>(() => ((IList)data).RemoveAt(0)); 84Assert.Throws<NotSupportedException>(() => ((IList<IntPtr>)data).RemoveAt(0)); 86Assert.Throws<NullReferenceException>(() => ((IList)data).Clear()); 87Assert.Throws<NullReferenceException>(() => ((IList)data).Contains(IntPtr.Zero)); 88Assert.Throws<NullReferenceException>(() => ((ICollection<IntPtr>)data).Contains(IntPtr.Zero)); 89Assert.Throws<NullReferenceException>(() => ((IList)data).IndexOf(IntPtr.Zero)); 90Assert.Throws<NullReferenceException>(() => ((IList<IntPtr>)data).IndexOf(IntPtr.Zero));
Collections\TemporaryArrayTests.cs (1)
69Assert.Throws<IndexOutOfRangeException>(() => array[i]);
Diagnostics\OperationTests.cs (6)
33Assert.Throws<InvalidOperationException>(() => dynamicExpression.GetArgumentName(0)); 34Assert.Throws<InvalidOperationException>(() => dynamicExpression.GetArgumentRefKind(0)); 63Assert.Throws<ArgumentOutOfRangeException>(() => dynamicExpression.GetArgumentName(-1)); 64Assert.Throws<ArgumentOutOfRangeException>(() => dynamicExpression.GetArgumentRefKind(-1)); 67Assert.Throws<ArgumentOutOfRangeException>(() => dynamicExpression.GetArgumentName(100)); 68Assert.Throws<ArgumentOutOfRangeException>(() => dynamicExpression.GetArgumentRefKind(100));
InternalUtilities\OneOrManyTests.cs (4)
213Assert.Throws<IndexOutOfRangeException>(() => single[1]); 214Assert.Throws<IndexOutOfRangeException>(() => single[-1]); 215Assert.Throws<IndexOutOfRangeException>(() => quad[5]); 216Assert.Throws<IndexOutOfRangeException>(() => quad[-1]);
InternalUtilities\SpecializedCollectionsTests.cs (8)
39Assert.Throws<NotSupportedException>(() => ((ICollection<int>)(emptySet)).Add(0)); 40Assert.Throws<NotSupportedException>(() => emptySet.Remove(0)); 41Assert.Throws<NotSupportedException>(() => emptySet.Clear()); 58Assert.Throws<NotSupportedException>(() => emptySet.Add(0)); 59Assert.Throws<NotSupportedException>(() => emptySet.ExceptWith(new int[0])); 60Assert.Throws<NotSupportedException>(() => emptySet.IntersectWith(new int[0])); 61Assert.Throws<NotSupportedException>(() => emptySet.SymmetricExceptWith(new int[0])); 62Assert.Throws<NotSupportedException>(() => emptySet.UnionWith(new int[0]));
Microsoft.CodeAnalysis.Workspaces.UnitTests (43)
Options\OptionKeyTests.cs (2)
26Assert.Throws<ArgumentNullException>(() => new Option<bool>("X", "Test Name", false, storageLocations: [null!])); 35Assert.Throws<ArgumentNullException>(() => new PerLanguageOption<bool>("X", "Test Name", false, storageLocations: [null!]));
SolutionTests\DocumentInfoTests.cs (1)
27Assert.Throws<ArgumentNullException>(() => DocumentInfo.Create(documentId, "doc", folders: ["folder", null]));
SolutionTests\ProjectInfoTests.cs (4)
30Assert.Throws<ArgumentNullException>(() => ProjectInfo.Create(pid, VersionStamp.Default, name: "Goo", assemblyName: "Bar", language: "C#", 43Assert.Throws<ArgumentNullException>(() => ProjectInfo.Create(pid, VersionStamp.Default, name: "Goo", assemblyName: "Bar", language: "C#", 49Assert.Throws<ArgumentNullException>(() => ProjectInfo.Create(pid, VersionStamp.Default, name: "Goo", assemblyName: "Bar", language: "C#", 63Assert.Throws<ArgumentNullException>(() => ProjectInfo.Create(pid, VersionStamp.Default, name: "Goo", assemblyName: "Bar", language: "C#",
SolutionTests\SolutionInfoTests.cs (1)
24Assert.Throws<ArgumentNullException>(() => SolutionInfo.Create(solutionId, version, projects: [projectInfo, null]));
SolutionTests\SolutionTests.cs (32)
214Assert.Throws<ArgumentNullException>(() => solution.WithDocumentFolders(documentId, folders: [null!])); 411Assert.Throws<ArgumentNullException>(() => solution.WithDocumentText((DocumentId[])null!, text, PreservationMode.PreserveIdentity)); 975Assert.Throws<ArgumentNullException>(() => solution.WithAnalyzerConfigDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity)); 976Assert.Throws<ArgumentOutOfRangeException>(() => solution.WithAnalyzerConfigDocumentText(documentId, text, (PreservationMode)(-1))); 999Assert.Throws<ArgumentNullException>(() => solution.WithAnalyzerConfigDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity)); 1000Assert.Throws<ArgumentOutOfRangeException>(() => solution.WithAnalyzerConfigDocumentText(documentId, textAndVersion, (PreservationMode)(-1))); 1022Assert.Throws<ArgumentOutOfRangeException>(() => solution.WithDocumentTextLoader(documentId, loader, (PreservationMode)(-1))); 1024Assert.Throws<ArgumentNullException>(() => solution.WithDocumentTextLoader(null!, loader, PreservationMode.PreserveIdentity)); 1025Assert.Throws<InvalidOperationException>(() => solution.WithDocumentTextLoader(s_unrelatedDocumentId, loader, PreservationMode.PreserveIdentity)); 1044Assert.Throws<ArgumentOutOfRangeException>(() => solution.WithAdditionalDocumentTextLoader(documentId, loader, (PreservationMode)(-1))); 1046Assert.Throws<ArgumentNullException>(() => solution.WithAdditionalDocumentTextLoader(null!, loader, PreservationMode.PreserveIdentity)); 1047Assert.Throws<InvalidOperationException>(() => solution.WithAdditionalDocumentTextLoader(s_unrelatedDocumentId, loader, PreservationMode.PreserveIdentity)); 1065Assert.Throws<ArgumentNullException>(() => solution.WithAnalyzerConfigDocumentTextLoader(documentId, null!, PreservationMode.PreserveIdentity)); 1066Assert.Throws<ArgumentOutOfRangeException>(() => solution.WithAnalyzerConfigDocumentTextLoader(documentId, loader, (PreservationMode)(-1))); 1068Assert.Throws<ArgumentNullException>(() => solution.WithAnalyzerConfigDocumentTextLoader(null!, loader, PreservationMode.PreserveIdentity)); 1069Assert.Throws<InvalidOperationException>(() => solution.WithAnalyzerConfigDocumentTextLoader(s_unrelatedDocumentId, loader, PreservationMode.PreserveIdentity)); 1935Assert.Throws<InvalidOperationException>(() => solution.WithProjectReferences(ProjectId.CreateNewId(), [projectRef])); 1938Assert.Throws<InvalidOperationException>(() => solution2.WithProjectReferences(projectId2, [new ProjectReference(projectId)])); 1939Assert.Throws<InvalidOperationException>(() => solution.WithProjectReferences(projectId, [new ProjectReference(projectId)])); 1993Assert.Throws<InvalidOperationException>(() => solution.AddProjectReferences(projectId3, [projectRef2])); 1996Assert.Throws<InvalidOperationException>(() => solution3.AddProjectReferences(projectId2, [projectRef3])); 1997Assert.Throws<InvalidOperationException>(() => solution3.AddProjectReferences(projectId, [new ProjectReference(projectId)])); 2063Assert.Throws<InvalidOperationException>(() => solution.AddProjectReferences(submissionId2, [new ProjectReference(submissionId3)])); 2064Assert.Throws<InvalidOperationException>(() => solution.WithProjectReferences(submissionId1, [new ProjectReference(submissionId2), new ProjectReference(submissionId3)])); 2067Assert.Throws<InvalidOperationException>(() => solution.AddProjectReferences(projectId0, [new ProjectReference(submissionId1)])); 2068Assert.Throws<InvalidOperationException>(() => solution.WithProjectReferences(projectId0, [new ProjectReference(submissionId1)])); 2086Assert.Throws<InvalidOperationException>(() => solution.WithProjectMetadataReferences(ProjectId.CreateNewId(), [metadataRef])); 2111Assert.Throws<InvalidOperationException>(() => solution3.AddMetadataReferences(projectId, [metadataRef1])); 2156Assert.Throws<InvalidOperationException>(() => solution.WithProjectAnalyzerReferences(ProjectId.CreateNewId(), [analyzerRef])); 2184Assert.Throws<InvalidOperationException>(() => solution3.AddAnalyzerReferences(projectId, [analyzerRef1])); 2211Assert.Throws<InvalidOperationException>(() => solution.RemoveAnalyzerReference(ProjectId.CreateNewId(), analyzerRef1)); 2378Assert.Throws<InvalidOperationException>(() => solution.AddDocument(documentId: DocumentId.CreateNewId(ProjectId.CreateNewId()), "name", loader));
UtilityTest\AsyncLazyTests.cs (1)
296: Assert.Throws<ArgumentException>(() => lazy.GetValue(CancellationToken.None));
WorkspaceTests\WorkspaceTests.cs (2)
64Assert.Throws<NotSupportedException>(() => ws.TryApplyChanges(changedDoc.Project.Solution)).Message); 109Assert.Throws<NotSupportedException>(() => ws.TryApplyChanges(newSolution)).Message);
Microsoft.Extensions.AsyncState.Tests (2)
AsyncStateTests.cs (2)
114Assert.Throws<InvalidOperationException>(() => state.Get(token)); 187Assert.Throws<InvalidOperationException>(() => state.Get(token));
Microsoft.Extensions.Http.Resilience.Tests (1)
Routing\RoutingStrategyTest.cs (1)
85Assert.Throws<OptionsValidationException>(() => CreateStrategy());
Microsoft.Extensions.Telemetry.Tests (6)
Latency\Internal\LatencyContextRegistrySetTests.cs (6)
49Assert.Throws<ArgumentException>(() => GetRegistry(n, e, e)); 50Assert.Throws<ArgumentException>(() => GetRegistry(e, n, e)); 51Assert.Throws<ArgumentException>(() => GetRegistry(e, e, n)); 54Assert.Throws<ArgumentException>(() => GetRegistry(n, e, e)); 55Assert.Throws<ArgumentException>(() => GetRegistry(e, n, e)); 56Assert.Throws<ArgumentException>(() => GetRegistry(e, e, n));
Microsoft.Gen.Metrics.Generated.Tests (4)
MetricTests.cs (2)
476var ex = Assert.Throws<ArgumentNullException>(() => recorder.Record(4L, null!)); 483var ex = Assert.Throws<ArgumentNullException>(() => counter.Add(4M, null!));
MetricTests.Ext.cs (2)
21var ex = Assert.Throws<ArgumentNullException>(() => recorder.Record(4L, null!)); 28var ex = Assert.Throws<ArgumentNullException>(() => counter.Add(4M, null!));
Microsoft.ML.TestFramework (1)
DataPipe\Parquet.cs (1)
31var ex = Assert.Throws<InvalidOperationException>(() => TestCore(pathData, false, new[] { "loader=Parquet{bigIntDates=+}" }, forceDense: true));
Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests (18)
CodeModel\FileCodeFunctionTests.cs (1)
514Assert.Throws<COMException>(() =>
ProjectSystemShim\CPS\SourceFileHandlingTests.cs (17)
314Assert.Throws<ArgumentException>(() => project.ReorderSourceFiles([sourceFileFullPath4, sourceFileFullPath5])); 317Assert.Throws<InvalidOperationException>(() => project.ReorderSourceFiles([@"C:\invalid source file", sourceFileFullPath2, sourceFileFullPath3, sourceFileFullPath4, sourceFileFullPath5])); 319Assert.Throws<ArgumentOutOfRangeException>(() => project.ReorderSourceFiles(new List<string>())); 320Assert.Throws<ArgumentOutOfRangeException>(() => project.ReorderSourceFiles(null)); 341Assert.Throws<ArgumentException>(() => project.ReorderSourceFiles([sourceFileFullPath4, sourceFileFullPath5])); 342Assert.Throws<ArgumentException>(() => project.ReorderSourceFiles([@"C:\invalid source file"])); // no files were added, therefore we should get an argument exception 343Assert.Throws<ArgumentOutOfRangeException>(() => project.ReorderSourceFiles(new List<string>())); 344Assert.Throws<ArgumentOutOfRangeException>(() => project.ReorderSourceFiles(null)); 349Assert.Throws<ArgumentException>(() => project.ReorderSourceFiles([sourceFileFullPath4, sourceFileFullPath5])); 350Assert.Throws<InvalidOperationException>(() => project.ReorderSourceFiles([@"C:\invalid source file"])); 351Assert.Throws<ArgumentOutOfRangeException>(() => project.ReorderSourceFiles(new List<string>())); 352Assert.Throws<ArgumentOutOfRangeException>(() => project.ReorderSourceFiles(null)); 365Assert.Throws<ArgumentException>(() => project.ReorderSourceFiles([sourceFileFullPath4, sourceFileFullPath5])); 366Assert.Throws<InvalidOperationException>(() => project.ReorderSourceFiles([@"C:\invalid source file", sourceFileFullPath2, sourceFileFullPath3, sourceFileFullPath4, sourceFileFullPath5])); 367Assert.Throws<ArgumentOutOfRangeException>(() => project.ReorderSourceFiles(new List<string>())); 368Assert.Throws<ArgumentOutOfRangeException>(() => project.ReorderSourceFiles(null)); 390Assert.Throws<InvalidOperationException>(() => project.ReorderSourceFiles([sourceFileFullPath2]));
Shared.Tests (1)
EmptyCollections\EmptyReadonlyDictionaryTests.cs (1)
17Assert.Throws<KeyNotFoundException>(() => instance[5]);
System.Drawing.Common.Tests (6)
mono\System.Drawing\GraphicsTests.cs (1)
729Assert.Throws<ArgumentException>(() => g.DrawCurve(Pens.Black, [new(10, 10)], 0.5f));
System\Drawing\Drawing2D\PathGradientBrushTests.cs (1)
327Assert.Throws<ArgumentNullException>(() => brush.Blend = new Blend() { Factors = null, Positions = [] });
System\Drawing\GraphicsTests.cs (2)
1894Assert.Throws<InvalidOperationException>(() => graphics.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Page, [Point.Empty])); 1895Assert.Throws<InvalidOperationException>(() => graphics.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Page, [PointF.Empty]));
System\Drawing\Imaging\EncoderParameterTests.cs (1)
295Assert.Throws<NullReferenceException>(() => new EncoderParameter(null, [], false));
System\Drawing\StringFormatTests.cs (1)
177Assert.Throws<NotImplementedException>(() => format.SetTabStops(0, [float.NegativeInfinity]));
System.Windows.Forms.Primitives.Tests (1)
Interop\Kernel32\SYSTEMTIMETests.cs (1)
73Assert.Throws<ArgumentOutOfRangeException>(() => dt = (DateTime)st); // cast to DateTime implicitly with incorrect arguments
System.Windows.Forms.Tests (9)
System\Windows\Forms\AccessibleObjects\Button.ButtonAccessibleObjectTests.cs (1)
15Assert.Throws<ArgumentException>(() => new ButtonAccessibleObject(null));
System\Windows\Forms\AccessibleObjects\PropertyGridView.GridViewListBoxItemAccessibleObjectTests.cs (1)
27Assert.Throws<TargetInvocationException>(() => (AccessibleObject)Activator.CreateInstance(type, [control, null]));
System\Windows\Forms\AxHostTests.cs (1)
1601Assert.Throws<InvalidCastException>(() => SubAxHost.GetPictureFromIPicture(iPicture));
System\Windows\Forms\ControlTests.Methods.cs (2)
4012Assert.Throws<DivideByZeroException>(() => control.Invoke(method, [1])); 4076Assert.Throws<DivideByZeroException>(() => control.Invoke(method, [1]));
System\Windows\Forms\ImageList.ImageCollectionTests.cs (1)
884Assert.Throws<ArgumentException>(() => collection.AddRange([value]));
System\Windows\Forms\ListBox.ObjectCollectionTests.cs (1)
3694Assert.Throws<OutOfMemoryException>(() => collection.AddRange((object[])[1]));
System\Windows\Forms\ListViewGroupCollectionTests.cs (1)
1096Assert.Throws<InvalidOperationException>(() => listView.Groups.AddRange((ListViewGroup[])[new(), new()]));
System\Windows\Forms\PropertyGridTests.cs (1)
2708Assert.Throws<ArgumentException>(() => control.SelectedObjects = [null]);