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

TestAsByte() private méthode

private TestAsByte ( ) : void
Résultat void
        public void TestAsByte()
        {
            try {
            CBORObject.NewArray().AsByte();
            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().AsByte();
            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.AsByte();
            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.AsByte();
            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.AsByte();
            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).AsByte();
            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["byte"].AsBoolean()) {
              Assert.AreEqual(
            StringToInt(numberinfo["integer"].AsString()),
            ((int)cbornumber.AsByte()) & 0xff);
            } else {
              try {
            cbornumber.AsByte();
            Assert.Fail("Should have failed " + cbornumber);
              } catch (OverflowException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString() + cbornumber);
            throw new InvalidOperationException(String.Empty, ex);
              }
            }
              }
              for (var i = 0; i < 255; ++i) {
            Assert.AreEqual((byte)i, CBORObject.FromObject(i).AsByte());
              }
              for (int i = -200; i < 0; ++i) {
            try {
              CBORObject.FromObject(i).AsByte();
            } catch (OverflowException) {
              new Object();
            } catch (Exception ex) {
              Assert.Fail(ex.ToString()); throw new
            InvalidOperationException(String.Empty, ex);
            }
              }
              for (int i = 256; i < 512; ++i) {
            try {
              CBORObject.FromObject(i).AsByte();
            } catch (OverflowException) {
              new Object();
            } catch (Exception ex) {
              Assert.Fail(ex.ToString()); throw new
            InvalidOperationException(String.Empty, ex);
            }
              }
        }
CBORObjectTest