Ejemplo n.º 1
0
        public void TestReadNumber()
        {
            var reader = new Amf0Reader();

            var files = Directory.GetFiles("../../../../samples/amf0/number");

            foreach (var file in files)
            {
                var value = double.Parse(Path.GetFileNameWithoutExtension(file));
                using (var f = new FileStream(file, FileMode.Open))
                {
                    var data = new byte[f.Length];
                    f.Read(data);
                    Assert.IsTrue(reader.TryGetNumber(data, out var dataRead, out var consumed));
                    Assert.AreEqual(dataRead, value);
                    Assert.AreEqual(consumed, f.Length);
                }
            }
        }
Ejemplo n.º 2
0
        public void TestNumber()
        {
            var random = new Random();
            var writer = new Amf0Writer();
            var reader = new Amf0Reader();

            using (var sc = new SerializationContext())
            {
                for (int i = 0; i < 1000; i++)
                {
                    var num = random.NextDouble() * 10 - 5;
                    writer.WriteBytes(num, sc);
                    var buffer = new byte[sc.MessageLength];
                    sc.GetMessage(buffer);

                    reader.TryGetNumber(buffer, out var readValue, out var consumed);
                    Assert.AreEqual(num, readValue);
                    Assert.AreEqual(buffer.Length, consumed);
                }
            }
        }