Exemplo n.º 1
0
 public void TestMediaTypeBuilder()
 {
     MediaTypeBuilder builder;
       try {
     Assert.AreEqual(null, new MediaTypeBuilder(null));
     Assert.Fail("Should have failed");
       } catch (ArgumentNullException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       builder = new MediaTypeBuilder("text", "plain");
       try {
     builder.SetTopLevelType(null);
     Assert.Fail("Should have failed");
       } catch (ArgumentNullException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     builder.SetParameter(null, "v");
     Assert.Fail("Should have failed");
       } catch (ArgumentNullException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     builder.SetParameter(null, null);
     Assert.Fail("Should have failed");
       } catch (ArgumentNullException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     builder.SetParameter(String.Empty, "v");
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     builder.SetParameter("v", null);
     Assert.Fail("Should have failed");
       } catch (ArgumentNullException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     builder.SetTopLevelType(String.Empty);
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     builder.SetTopLevelType("e=");
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     builder.SetTopLevelType("e/e");
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     new MediaTypeBuilder().SetSubType(null);
     Assert.Fail("Should have failed");
       } catch (ArgumentNullException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     new MediaTypeBuilder().RemoveParameter(null);
     Assert.Fail("Should have failed");
       } catch (ArgumentNullException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     new MediaTypeBuilder().RemoveParameter(String.Empty);
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     new MediaTypeBuilder().RemoveParameter("v");
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     new MediaTypeBuilder().SetSubType(String.Empty);
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     new MediaTypeBuilder().SetSubType("x;y");
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     new MediaTypeBuilder().SetSubType("x/y");
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     new MediaTypeBuilder().SetParameter("x", String.Empty);
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     new MediaTypeBuilder().SetParameter("x;y", "v");
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     new MediaTypeBuilder().SetParameter("x/y", "v");
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
 }