+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ParseExtraJunkN ()
+ {
+ new Guid ("000102030405060708090a0b0c0d0e0faaaaaa");
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ParseExtraJunkD ()
+ {
+ new Guid ("00010203-0405-0607-0809-0a0b0c0d0e0faaaaaa");
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ParseExtraJunkB ()
+ {
+ new Guid ("{00010203-0405-0607-0809-0A0B0C0D0E0F}aaaa");
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ParseExtraJunkP ()
+ {
+ new Guid ("(00010203-0405-0607-0809-0A0B0C0D0E0F)aaaa");
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ParseExtraJunkX ()
+ {
+ new Guid ("{0x00010203,0x0405,0x0607,{0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}}aaaa");
+ }
+
+#if NET_4_0
+
+ /*
+ N = new Guid ("000102030405060708090a0b0c0d0e0f");
+ D = new Guid ("00010203-0405-0607-0809-0a0b0c0d0e0f");
+ B = new Guid ("{00010203-0405-0607-0809-0A0B0C0D0E0F}");
+ P = new Guid ("(00010203-0405-0607-0809-0A0B0C0D0E0F)");
+ X = new Guid ("{0x00010203,0x0405,0x0607,{0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}}");
+
+ string expected = "00010203-0405-0607-0809-0a0b0c0d0e0f";
+ */
+
+ [Test]
+ public void ParseExact ()
+ {
+ const string expected = "00010203-0405-0607-0809-0a0b0c0d0e0f";
+
+ var guid = Guid.ParseExact ("000102030405060708090a0b0c0d0e0f", "N");
+ Assert.AreEqual (expected, guid.ToString ());
+
+ guid = Guid.ParseExact ("00010203-0405-0607-0809-0a0b0c0d0e0f", "D");
+ Assert.AreEqual (expected, guid.ToString ());
+
+ guid = Guid.ParseExact ("00010203-0405-0607-0809-0a0b0c0d0e0f", "d");
+ Assert.AreEqual (expected, guid.ToString ());
+
+ guid = Guid.ParseExact ("{00010203-0405-0607-0809-0A0B0C0D0E0F}", "B");
+ Assert.AreEqual (expected, guid.ToString ());
+
+ guid = Guid.ParseExact ("{00010203-0405-0607-0809-0A0B0C0D0E0F}", "b");
+ Assert.AreEqual (expected, guid.ToString ());
+
+ guid = Guid.ParseExact ("(00010203-0405-0607-0809-0A0B0C0D0E0F)", "P");
+ Assert.AreEqual (expected, guid.ToString ());
+
+ guid = Guid.ParseExact ("{0x00010203,0x0405,0x0607,{0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}}", "X");
+ Assert.AreEqual (expected, guid.ToString ());
+
+ guid = Guid.ParseExact ("\t {\t 0x00000001 , 0x0002 , \t 0x0003 \t , { 0x04 , 0x05 , \t 0x06\t,\t0x07 , 0x08 , 0x09 , 0x0a , 0x0b } \t }\t ", "X");
+ Assert.AreEqual ("00000001-0002-0003-0405-060708090a0b", guid.ToString (), "#8");
+ }
+
+ [Test]
+ public void Parse ()
+ {
+ var guid = Guid.Parse ("\t {\t 0x00000001 , 0x0002 , \t 0x0003 \t , { 0x04 , 0x05 , \t 0x06\t,\t0x07 , 0x08 , 0x09 , 0x0a , 0x0b } \t }\t ");
+ Assert.AreEqual ("00000001-0002-0003-0405-060708090a0b", guid.ToString (), "#1");
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ParseError_1 ()
+ {
+ Guid.Parse("08888888-0444-444-0444-012121212121");
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ParseExactN ()
+ {
+ Guid.ParseExact ("00010203-0405-0607-0809-0a0b0c0d0e0f", "N");
+ }
+
+ [Test]
+ [ExpectedException (typeof (FormatException))]
+ public void ParseExactD ()
+ {
+ Guid.ParseExact ("{0x00010203,0x0405,0x0607,{0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}}", "D");
+ }
+
+ [Test]
+ public void TryParse()
+ {
+ Guid guid;
+ Assert.IsFalse (Guid.TryParse(null, out guid), "A1");
+ Assert.AreEqual (Guid.Empty, guid, "A2");
+ Assert.IsFalse (Guid.TryParse("", out guid), "A3");
+ Assert.AreEqual (Guid.Empty, guid, "A4");
+ Assert.IsFalse (Guid.TryParse("foobar", out guid), "A5");
+ Assert.AreEqual (Guid.Empty, guid, "A6");
+ Assert.IsFalse (Guid.TryParse ("08888888-0444-444-0444-012121212121", out guid), "A7");
+ }
+
+ [Test]
+ public void TryParseExact()
+ {
+ Guid guid;
+ Assert.IsFalse (Guid.TryParseExact(null, null, out guid), "A1");
+ Assert.AreEqual (Guid.Empty, guid, "A2");
+ Assert.IsFalse (Guid.TryParseExact("", null, out guid), "A3");
+ Assert.AreEqual (Guid.Empty, guid, "A4");
+ Assert.IsFalse (Guid.TryParseExact("foobar", null, out guid), "A5");
+ Assert.AreEqual (Guid.Empty, guid, "A6");
+ }
+#endif