public void TestConvertFrom() { Assert.AreEqual(imageFmt, (ImageFormat)imgFmtConv.ConvertFrom(null, CultureInfo.InvariantCulture, ImageFormat.Bmp.ToString()), "CF#1"); try { imgFmtConv.ConvertFrom("System.Drawing.String"); Assert.Fail("CF#2: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#2"); } try { imgFmtConv.ConvertFrom(null, CultureInfo.InvariantCulture, "System.Drawing.String"); Assert.Fail("CF#2a: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#2a"); } try { imgFmtConv.ConvertFrom(null, CultureInfo.InvariantCulture, ImageFormat.Bmp); Assert.Fail("CF#3: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#3"); } try { imgFmtConv.ConvertFrom(null, CultureInfo.InvariantCulture, ImageFormat.Bmp.Guid); Assert.Fail("CF#4: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#4"); } try { imgFmtConv.ConvertFrom(null, CultureInfo.InvariantCulture, new Object()); Assert.Fail("CF#5: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#5"); } try { imgFmtConv.ConvertFrom(null, CultureInfo.InvariantCulture, 10); Assert.Fail("CF#6: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#6"); } Assert.AreEqual(imageFmt, (ImageFormat)imgFmtConvFrmTD.ConvertFrom(null, CultureInfo.InvariantCulture, ImageFormat.Bmp.ToString()), "CF#1A"); try { imgFmtConvFrmTD.ConvertFrom("System.Drawing.String"); Assert.Fail("CF#2A: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#2A"); } try { imgFmtConvFrmTD.ConvertFrom(null, CultureInfo.InvariantCulture, "System.Drawing.String"); Assert.Fail("CF#2aA: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#2aA"); } try { imgFmtConvFrmTD.ConvertFrom(null, CultureInfo.InvariantCulture, ImageFormat.Bmp); Assert.Fail("CF#3A: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#3A"); } try { imgFmtConvFrmTD.ConvertFrom(null, CultureInfo.InvariantCulture, ImageFormat.Bmp.Guid); Assert.Fail("CF#4A: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#4A"); } try { imgFmtConvFrmTD.ConvertFrom(null, CultureInfo.InvariantCulture, new Object()); Assert.Fail("CF#5A: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#5A"); } try { imgFmtConvFrmTD.ConvertFrom(null, CultureInfo.InvariantCulture, 10); Assert.Fail("CF#6A: must throw NotSupportedException"); } catch (Exception e) { Assert.IsTrue(e is NotSupportedException, "CF#6A"); } }
public void TestConvertFrom_ImageFormatToString() { Assert.Equal(_imageFmt, (ImageFormat)_imgFmtConv.ConvertFrom(null, CultureInfo.InvariantCulture, ImageFormat.Bmp.ToString())); Assert.Equal(_imageFmt, (ImageFormat)_imgFmtConvFrmTD.ConvertFrom(null, CultureInfo.InvariantCulture, ImageFormat.Bmp.ToString())); }