Test.CBORObjectTest.TestAsInt16 C# (CSharp) Méthode

TestAsInt16() private méthode

private TestAsInt16 ( ) : void
Résultat void
        public void TestAsInt16()
        {
            try {
            CBORObject.NewArray().AsInt16();
            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().AsInt16();
            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.AsInt16();
            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.AsInt16();
            Assert.Fail("Should have failed");
              } catch (InvalidOperationException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            CBORObject.Undefined.AsInt16();
            Assert.Fail("Should have failed");
              } catch (InvalidOperationException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            CBORObject.FromObject(String.Empty).AsInt16();
            Assert.Fail("Should have failed");
              } catch (InvalidOperationException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              CBORObject numbers = GetNumberData();
              for (int i = 0; i < numbers.Count; ++i) {
            CBORObject numberinfo = numbers[i];
            CBORObject cbornumber =
              CBORObject.FromObject(
            EDecimal.FromString(numberinfo["number"].AsString()));
            if (numberinfo["int16"].AsBoolean()) {
              Assert.AreEqual(
            StringToInt(numberinfo["integer"].AsString()),
            cbornumber.AsInt16());
            } else {
              try {
            cbornumber.AsInt16();
            Assert.Fail("Should have failed " + cbornumber);
              } catch (OverflowException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString() + cbornumber);
            throw new InvalidOperationException(String.Empty, ex);
              }
            }
              }
        }
CBORObjectTest