﻿using Arch.CFramework.Utility.Serialize;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;

namespace Arch.CFramework.Utility.Test
{ 
    /// <summary>
    ///This is a test class for Base64SerializerTest and is intended
    ///to contain all Base64SerializerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class Base64SerializerTest
    { 
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion
         
        /// <summary>
        ///A test for Base64Serializer Constructor
        ///</summary>
        [TestMethod()]
        public void Base64SerializerConstructorTest()
        {
            Base64Serializer target = new Base64Serializer();
            Assert.IsNotNull(target);
        }
        [Serializable]
        public class MyClass
        {
            public string Code { get; set; }
            public string Name { get; set; }
            public MyClass()
            { }

            public MyClass(string code, string name)
            {
                Code = code;
                Name = name;
            }
        }
        /// <summary>
        ///A test for Deserialize
        ///</summary>
        public void DeserializeTestHelper<T>()
            where T : class
        {
            Base64Serializer target = new Base64Serializer();
            string source = "AAEAAAD/////AQAAAAAAAAAMAgAAAFNBcmNoLkNGcmFtZXdvcmsuVXRpbGl0eS5UZXN0LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAOUFyY2guQ0ZyYW1ld29yay5VdGlsaXR5LlRlc3QuQmFzZTY0U2VyaWFsaXplclRlc3QrTXlDbGFzcwIAAAAVPENvZGU+a19fQmFja2luZ0ZpZWxkFTxOYW1lPmtfX0JhY2tpbmdGaWVsZAEBAgAAAAYDAAAAAkFBBgQAAAACQkIL";
            MyClass expected = new MyClass("AA", "BB");
            MyClass actual;
            actual = target.Deserialize<MyClass>(source);
            Assert.AreEqual(expected.Name, actual.Name); 
        }

        [TestMethod()]
        public void DeserializeTest()
        {
            DeserializeTestHelper<MyClass>();
        }
         

        /// <summary>
        ///A test for Serialize
        ///</summary>
        public void SerializeTestHelper<T>()
            where T : class
        {
            Base64Serializer target = new Base64Serializer(); 
            //T t = default(T);  
            MyClass t = new MyClass("AA", "BB");
            string expected = "AAEAAAD/////AQAAAAAAAAAMAgAAAFNBcmNoLkNGcmFtZXdvcmsuVXRpbGl0eS5UZXN0LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAOUFyY2guQ0ZyYW1ld29yay5VdGlsaXR5LlRlc3QuQmFzZTY0U2VyaWFsaXplclRlc3QrTXlDbGFzcwIAAAAVPENvZGU+a19fQmFja2luZ0ZpZWxkFTxOYW1lPmtfX0JhY2tpbmdGaWVsZAEBAgAAAAYDAAAAAkFBBgQAAAACQkIL";  
            string actual;
            actual = target.Serialize<MyClass>(t);
            Assert.AreEqual(expected, actual); 
        }

        [TestMethod()]
        public void SerializeTest()
        {
            SerializeTestHelper<MyClass>();
        }
    }
}
