Click here to Skip to main content
12,350,728 members (24,317 online)
Click here to Skip to main content
Articles » Languages » XML » Serializing » Downloads

Stats

195.5K views
269 downloads
205 bookmarked
Posted

Yet Another XML Serialization Library for the .NET Framework

, 2 Oct 2012 MIT
A flexible XML serialization library that lets developers design the XML file structure, and select the exception handling policy. YAXLib supports polymorphic serialization and serializing generic and non-generic collection classes and arrays.
YAXLib
DemoApplication
Properties
SampleClasses
YAXLib
Properties
LocalTestRun.testrunconfig
YAXLib.vsmdi
YAXLibTests
Properties
Test References
// Copyright 2009 - 2010 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
//-----------------------------------------------------------------------

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YAXLib;

namespace YAXLibTests
{
    /// <summary>
    /// Summary description for StringUtilsTest
    /// </summary>
    [TestClass]
    public class StringUtilsTest
    {
        [TestMethod]
        public void RefineElementNameTest()
        {
            Assert.AreEqual(StringUtils.RefineLocationString(".."), "..");
            Assert.AreEqual(StringUtils.RefineLocationString("."), ".");
            Assert.AreEqual(StringUtils.RefineLocationString("      "), ".");
            Assert.AreEqual(StringUtils.RefineLocationString(" /      \\ "), ".");
            Assert.AreEqual(StringUtils.RefineLocationString("ans"), "ans");
            Assert.AreEqual(StringUtils.RefineLocationString("/ans"), "ans");
            Assert.AreEqual(StringUtils.RefineLocationString("/ans/"), "ans");
            Assert.AreEqual(StringUtils.RefineLocationString("ans/"), "ans");
            Assert.AreEqual(StringUtils.RefineLocationString("ans/////"), "ans");
            Assert.AreEqual(StringUtils.RefineLocationString("ans\\\\\\"), "ans");
            Assert.AreEqual(StringUtils.RefineLocationString("..."), "___");
            Assert.AreEqual(StringUtils.RefineLocationString("one / two / three / four "), "one/two/three/four");
            Assert.AreEqual(StringUtils.RefineLocationString("one / two \\ three / four "), "one/two/three/four");
            Assert.AreEqual(StringUtils.RefineLocationString("one / two / three and else / four "), "one/two/three_and_else/four");
            Assert.AreEqual(StringUtils.RefineLocationString("one / two / .. / four "), "one/two/../four");
            Assert.AreEqual(StringUtils.RefineLocationString("one / two / .. / four / "), "one/two/../four");
            Assert.AreEqual(StringUtils.RefineLocationString("one / two / . . / four / "), "one/two/___/four");
            Assert.AreEqual(StringUtils.RefineLocationString("one / two / two:words.are / four "), "one/two/two_words_are/four");
        }

        [TestMethod]
        public void IsLocationAllGenericTest()
        {
            Assert.IsTrue(StringUtils.IsLocationAllGeneric(".."));
            Assert.IsTrue(StringUtils.IsLocationAllGeneric("."));
            Assert.IsTrue(StringUtils.IsLocationAllGeneric("./.."));
            Assert.IsTrue(StringUtils.IsLocationAllGeneric("../.."));

            Assert.IsFalse(StringUtils.IsLocationAllGeneric("../one/.."));
            Assert.IsFalse(StringUtils.IsLocationAllGeneric("../one"));
            Assert.IsFalse(StringUtils.IsLocationAllGeneric("one/.."));
            Assert.IsFalse(StringUtils.IsLocationAllGeneric("one"));
            Assert.IsFalse(StringUtils.IsLocationAllGeneric("one/../two"));
            Assert.IsFalse(StringUtils.IsLocationAllGeneric("../one/../two"));
            Assert.IsFalse(StringUtils.IsLocationAllGeneric("../one/../two/.."));
            Assert.IsFalse(StringUtils.IsLocationAllGeneric("one/../two/.."));
        }

        [TestMethod]
        public void DivideLocationOneStepTest()
        {
            bool returnValue = false;
            string location = "..";
            string newLocation = "";
            string newElement = "";

            location = "..";
            returnValue = StringUtils.DivideLocationOneStep(location, out newLocation, out newElement);
            Assert.AreEqual(newLocation, "..");
            Assert.AreEqual(newElement, null);
            Assert.AreEqual(returnValue, false);

            location = ".";
            returnValue = StringUtils.DivideLocationOneStep(location, out newLocation, out newElement);
            Assert.AreEqual(newLocation, ".");
            Assert.AreEqual(newElement, null);
            Assert.AreEqual(returnValue, false);

            location = "../..";
            returnValue = StringUtils.DivideLocationOneStep(location, out newLocation, out newElement);
            Assert.AreEqual(newLocation, "../..");
            Assert.AreEqual(newElement, null);
            Assert.AreEqual(returnValue, false);

            location = "../../folder";
            returnValue = StringUtils.DivideLocationOneStep(location, out newLocation, out newElement);
            Assert.AreEqual(newLocation, "../..");
            Assert.AreEqual(newElement, "folder");
            Assert.AreEqual(returnValue, true);

            location = "../../folder/..";
            returnValue = StringUtils.DivideLocationOneStep(location, out newLocation, out newElement);
            Assert.AreEqual(newLocation, "../../folder/..");
            Assert.AreEqual(newElement, null);
            Assert.AreEqual(returnValue, false);

            location = "one/two/three/four";
            returnValue = StringUtils.DivideLocationOneStep(location, out newLocation, out newElement);
            Assert.AreEqual(newLocation, "one/two/three");
            Assert.AreEqual(newElement, "four");
            Assert.AreEqual(returnValue, true);

            location = "one";
            returnValue = StringUtils.DivideLocationOneStep(location, out newLocation, out newElement);
            Assert.AreEqual(newLocation, ".");
            Assert.AreEqual(newElement, "one");
            Assert.AreEqual(returnValue, true);

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License

Share

About the Author

Sina Iravanian
Software Developer
Australia Australia
A software designer and developer

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 2 Oct 2012
Article Copyright 2009 by Sina Iravanian
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid