Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ExceptionTests.cs « tests « System.Reflection « src - github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: adcd9c516fe4b693d1a8c7166bb900b58fe4fde9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Xunit;
using System;
using System.Reflection;
using System.Collections.Generic;

#pragma warning disable 0414

namespace System.Reflection.Tests
{
    public class ExceptionTests
    {

        public static void TargetException()
        {
            Exception ex = new TargetException();
            Assert.NotNull(ex);
            Assert.Equal(ex.GetType(), typeof(TargetException));

            string s = "My exception";
            ex = new TargetException();
            Assert.NotNull(ex);
            Assert.Equal(ex.GetType(), typeof(TargetException));
            Assert.Equal(s, ex.Message);

            s = "My exception";
            Exception innerException = new Exception();
            ex = new TargetException(s, innerException);
            Assert.NotNull(ex);
            Assert.Equal(ex.GetType(), typeof(TargetException));
            Assert.Equal(innerException, ex.InnerException);
            Assert.Equal(s, ex.Message);

            // Throw the exception from a method.
            try
            {
                ThrowTargetException(s, innerException);
                Assert.True(false);
            }
            catch (TargetException tex)
            {
                Assert.Equal(innerException, tex.InnerException);
                Assert.Equal(s, tex.Message);
            }
            catch (Exception)
            {
                Assert.True(false);
            }
        }

        private static void ThrowTargetException(string s, Exception innerException)
        {
            throw new TargetException(s, innerException);
        }

        private static void ThrowInvalidFilterCriteriaException(string s, Exception innerException)
        {
            throw new InvalidFilterCriteriaException(s, innerException);
        }



        public static void InvalidFilterCriteriaException()
        {
            Exception ex = new InvalidFilterCriteriaException();
            Assert.NotNull(ex);
            Assert.Equal(ex.GetType(), typeof(InvalidFilterCriteriaException));

            string s = "My exception";
            ex = new InvalidFilterCriteriaException();
            Assert.NotNull(ex);
            Assert.Equal(ex.GetType(), typeof(InvalidFilterCriteriaException));
            Assert.Equal(s, ex.Message);

            s = "My exception";
            Exception innerException = new Exception();
            ex = new InvalidFilterCriteriaException(s, innerException);
            Assert.NotNull(ex);
            Assert.Equal(ex.GetType(), typeof(InvalidFilterCriteriaException));
            Assert.Equal(innerException, ex.InnerException);
            Assert.Equal(s, ex.Message);

            // Throw the exception from a method.
            try
            {
                ThrowInvalidFilterCriteriaException(s, innerException);
                Assert.True(false);
            }
            catch (InvalidFilterCriteriaException tex)
            {
                Assert.Equal(innerException, tex.InnerException);
                Assert.Equal(s, tex.Message);
            }
            catch (Exception)
            {
                Assert.True(false);
            }
        }
    }
}