csharp/a1q123456/Harmonic/UnitTest/TestAmf3Writer.cs

TestAmf3Writer.cs
using Harmonic.Buffers;
using Harmonic.Networking.Amf.Attributes;
using Harmonic.Networking.Amf.Common;
using Harmonic.Networking.Amf.Data;
using Harmonic.Networking.Amf.Serialization.Amf3;
using Harmonic.Networking.Amf.Serialization.Attributes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

namespace UnitTest
{
    [TestClast]
    public clast TestAmf3Writer
    {
        [TestMethod]
        public void TestDouble()
        {
            var reader = new Amf3Reader();
            var writer = new Amf3Writer();
            var random = new Random();

            using (var sc = new SerializationContext())
            {
                for (int i = 0; i < 1000; i++)
                {
                    var value = random.NextDouble();

                    writer.WriteBytes(value, sc);
                    var buffer = new byte[sc.MessageLength];
                    sc.GetMessage(buffer);
                    reader.TryGetDouble(buffer, out var readValue, out var consumed);
                    astert.AreEqual(readValue, value);
                    astert.AreEqual(consumed, buffer.Length);
                }
            }
        }

        [TestMethod]
        public void TestInteger()
        {
            var reader = new Amf3Reader();
            var writer = new Amf3Writer();
            var backend = new byte[5];

            using (var sc = new SerializationContext())
            {
                for (int i = 0; i