Merge pull request #2768 from lambdageek/dev/monoerror-cominterop
[mono.git] / mcs / class / System / Test / System.Security.Cryptography.X509Certificates / X509Certificate2Test.cs
index 9fceaca05cac364bf580c8b503efd8b7f5465e22..a7e48646d05dcf3b87af070d4ee4cb66ac045634 100644 (file)
@@ -28,7 +28,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 
 using System;
 using System.IO;
@@ -1466,17 +1465,35 @@ WYpnKQqsKIzlSqv9wwXs7B1iA7ZdvHk3TAnSnLP1o2H7ME05UnZPKCvraONdezon
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void GetNameInfo_Invalid_True ()
                {
-                       new X509Certificate2 ().GetNameInfo ((X509NameType) Int32.MinValue, true);
+                       try {
+                               // MS throws ArgumentException, Mono's new implementation throws
+                               // CryptographicException, which is consistent with other "certificate
+                               // instance is empty" situations.
+                               new X509Certificate2 ().GetNameInfo ((X509NameType) Int32.MinValue, true);
+                               Assert.Fail ("Expected exception.");
+                       } catch (ArgumentException) {
+                       } catch (CryptographicException) {
+                       } catch (Exception ex) {
+                               Assert.Fail ("Expected 'ArgumentException' or 'CryptographicException', got '{0}'", ex.GetType ());
+                       }
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void GetNameInfo_Invalid_False ()
                {
-                       new X509Certificate2 ().GetNameInfo ((X509NameType) Int32.MinValue, false);
+                       try {
+                               // MS throws ArgumentException, Mono's new implementation throws
+                               // CryptographicException, which is consistent with other "certificate
+                               // instance is empty" situations.
+                               new X509Certificate2 ().GetNameInfo ((X509NameType) Int32.MinValue, false);
+                               Assert.Fail ("Expected exception.");
+                       } catch (ArgumentException) {
+                       } catch (CryptographicException) {
+                       } catch (Exception ex) {
+                               Assert.Fail ("Expected 'ArgumentException' or 'CryptographicException', got '{0}'", ex.GetType ());
+                       }
                }
 
                [Test]
@@ -1487,10 +1504,19 @@ WYpnKQqsKIzlSqv9wwXs7B1iA7ZdvHk3TAnSnLP1o2H7ME05UnZPKCvraONdezon
                }
 
                [Test]
-               [ExpectedException (typeof (NullReferenceException))]
                public void Empty_GetNameInfo_DnsName ()
                {
-                       new X509Certificate2 ().GetNameInfo (X509NameType.DnsName, true);
+                       try {
+                               // MS throws NullReferenceException, Mono's new implementation throws
+                               // CryptographicException, which is consistent with other "certificate
+                               // instance is empty" situations.
+                               new X509Certificate2 ().GetNameInfo (X509NameType.DnsName, true);
+                               Assert.Fail ("Expected exception.");
+                       } catch (NullReferenceException) {
+                       } catch (CryptographicException) {
+                       } catch (Exception ex) {
+                               Assert.Fail ("Expected 'NullReferenceException' or 'CryptographicException', got '{0}'", ex.GetType ());
+                       }
                }
 
                [Test]
@@ -1652,4 +1678,3 @@ WYpnKQqsKIzlSqv9wwXs7B1iA7ZdvHk3TAnSnLP1o2H7ME05UnZPKCvraONdezon
        }
 }
 
-#endif