示例#1
0
        public void TestCBORObjectArgumentValidation()
        {
            try {
                CBORObject.FromObject('\udddd');
                Assert.Fail("Should have failed");
            } catch (ArgumentException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            Assert.AreEqual(CBORObject.Null, CBORObject.FromObject((byte[])null));
            Assert.AreEqual(
                CBORObject.Null,
                CBORObject.FromObject((CBORObject[])null));
            Assert.AreEqual(CBORObject.True, CBORObject.FromObject(true));
            Assert.AreEqual(CBORObject.False, CBORObject.FromObject(false));
            Assert.AreEqual(CBORObject.FromObject(8), CBORObject.FromObject((byte)8));
            try {
                CBORObject.AddConverter(null, new FakeConverter());
                Assert.Fail("Should have failed");
            } catch (ArgumentNullException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            try {
                CBORObject.AddConverter(typeof(String), new FakeConverter());
                Assert.Fail("Should have failed");
            } catch (ArgumentException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            EInteger eintNull = null;

            try {
                CBORObject.AddTagHandler(eintNull, null);
                Assert.Fail("Should have failed");
            } catch (ArgumentNullException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            try {
                CBORObject.True.Abs();
                Assert.Fail("Should have failed");
            } catch (InvalidOperationException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            try {
                CBORObject.False.Abs();
                Assert.Fail("Should have failed");
            } catch (InvalidOperationException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            try {
                CBORObject.NewArray().Abs();
                Assert.Fail("Should have failed");
            } catch (InvalidOperationException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            try {
                CBORObject.NewMap().Abs();
                Assert.Fail("Should have failed");
            } catch (InvalidOperationException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            try {
                CBORObject.True.AsERational();
                Assert.Fail("Should have failed");
            } catch (InvalidOperationException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            try {
                CBORObject.False.AsERational();
                Assert.Fail("Should have failed");
            } catch (InvalidOperationException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            try {
                CBORObject.NewArray().AsERational();
                Assert.Fail("Should have failed");
            } catch (InvalidOperationException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
            try {
                CBORObject.NewMap().AsERational();
                Assert.Fail("Should have failed");
            } catch (InvalidOperationException) {
                new Object();
            } catch (Exception ex) {
                Assert.Fail(ex.ToString());
                throw new InvalidOperationException(String.Empty, ex);
            }
        }