ExceptionExtensionsTests.cs (2442B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="ExceptionExtensionsTests.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.Management.Configuration.UnitTests.Tests 8 { 9 using System; 10 using Microsoft.Management.Configuration.Processor.Extensions; 11 using Microsoft.Management.Configuration.UnitTests.Fixtures; 12 using Microsoft.Management.Configuration.UnitTests.Helpers; 13 using Microsoft.PowerShell.Commands; 14 using Xunit; 15 using Xunit.Abstractions; 16 17 /// <summary> 18 /// Exception extension tests. 19 /// </summary> 20 [Collection("UnitTestCollection")] 21 [InProc] 22 public class ExceptionExtensionsTests 23 { 24 private readonly UnitTestFixture fixture; 25 private readonly ITestOutputHelper log; 26 27 /// <summary> 28 /// Initializes a new instance of the <see cref="ExceptionExtensionsTests"/> class. 29 /// </summary> 30 /// <param name="fixture">Unit test fixture.</param> 31 /// <param name="log">Log helper.</param> 32 public ExceptionExtensionsTests(UnitTestFixture fixture, ITestOutputHelper log) 33 { 34 this.fixture = fixture; 35 this.log = log; 36 } 37 38 /// <summary> 39 /// Tests GetMostInnerException. 40 /// </summary> 41 [Fact] 42 public void GetMostInnerException_Test() 43 { 44 var exception = new Exception( 45 "message1", 46 new WriteErrorException( 47 "WriteException", 48 new ArgumentNullException())); 49 50 var mostInner = exception.GetMostInnerException(); 51 Assert.IsType<ArgumentNullException>(mostInner); 52 53 var exception2 = new Exception( 54 "message2", 55 new WriteErrorException( 56 "WriteException2")); 57 58 mostInner = exception2.GetMostInnerException(); 59 Assert.IsType<WriteErrorException>(mostInner); 60 61 var exception3 = new ArgumentOutOfRangeException("message2"); 62 mostInner = exception3.GetMostInnerException(); 63 Assert.IsType<ArgumentOutOfRangeException>(mostInner); 64 } 65 } 66 }