示例#1
0
        public void SerializeXMLTest()
        {
            fileAssistant = new FileAssistant();
            fileAssistant.SerializationType = "XML";
            var aElem = MockObjects.GetAnimationElement();

            byte[] bytes = fileAssistant.Serialize(aElem);
            string xml   = new string(Encoding.Unicode.GetChars(bytes));

            if (bytes == null || bytes.Length == 0 && XDocument.Parse(xml) == null)
            {
                throw new Exception("Assert Fails");
            }
        }
示例#2
0
        public void SaveSerializedObject <T>(T obj, string type, string name) where T : class
        {
            var    bytes = _fileAssistant.Serialize(obj);
            string path  = _fileAssistant.GetFullPathForFolderName(type, RESOURCE_PATH);

            if (!name.Contains("."))
            {
                name += "." + _fileAssistant.SerializationType.ToLower();
            }

            AddResourceToList(name, type, bytes);

            string fullPath = Path.Combine(path, name);

            File.WriteAllBytes(fullPath, bytes);
        }
示例#3
0
        public void DeserializeJSONTest()
        {
            fileAssistant = new FileAssistant();
            fileAssistant.SerializationType = "JSON";

            var aElem = MockObjects.GetAnimationElement();

            byte[] bytes = fileAssistant.Serialize(aElem);
            string xml   = new string(Encoding.Unicode.GetChars(bytes));

            if (bytes == null || bytes.Length == 0 && XDocument.Parse(xml) == null)
            {
                throw new Exception("Assert Fails");
            }

            var aElem2 = fileAssistant.Deserialize <AnimationSingleElement>(bytes);

            if (aElem.Shape.TypeName != aElem2.Shape.TypeName)
            {
                throw new Exception("Assert Fails");
            }
        }