BtAddrSerialization.cs :  » Business-Application » 32feet.NET » InTheHand » Net » Tests » Bluetooth » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Business Application » 32feet.NET 
32feet.NET » InTheHand » Net » Tests » Bluetooth » BtAddrSerialization.cs
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Xml.Serialization;

namespace InTheHand.Net.Tests.Bluetooth.TestBluetoothAddress{
    [TestFixture]
    public class IFormatterSztn : BtAddrSerialization
    {
        protected override void DoTestRoundTrip(BluetoothAddress obj)
        {
            IFormatter szr = new BinaryFormatter();
            Stream strm = new MemoryStream();
            szr.Serialize(strm, obj);
            //
            strm.Position = 0;
            BluetoothAddress back = (BluetoothAddress)szr.Deserialize(strm);
            Assert.AreEqual(obj, back, "Equals");
            Assert.AreEqual(obj.ToString("C"), back.ToString("C"), "ToString(\"C\")");
        }

        [Test]
        public void OneFormat()
        {
            BluetoothAddress obj = BluetoothAddress.Parse("001122334455");
            //
            IFormatter szr = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
            Stream strm = new MemoryStream();
            szr.Serialize(strm, obj);
            // SZ Format
            const String NewLine = "\r\n";
            String xmlData
                = "<SOAP-ENV:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:clr=\"http://schemas.microsoft.com/soap/encoding/clr/1.0\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + NewLine
                + "<SOAP-ENV:Body>" + NewLine
                + "<a1:BluetoothAddress id=\"ref-1\" xmlns:a1=\"http://schemas.microsoft.com/clr/nsassem/InTheHand.Net/[A-F-N]\">" + NewLine
                + "<dataString id=\"ref-3\">001122334455</dataString>" + NewLine
                + "</a1:BluetoothAddress>" + NewLine
                + "</SOAP-ENV:Body>" + NewLine
                + "</SOAP-ENV:Envelope>" + NewLine
                ;
            strm.Position = 0;
            String result = new StreamReader(strm).ReadToEnd();
            Assert.AreEqual(InsertAssemblyFullNameEscaped(xmlData), result, "Equals");
        }

        internal static string InsertAssemblyFullNameEscaped(string value)
        {
            string fn = typeof(BluetoothAddress).Assembly.FullName;
            string fnE = Uri.EscapeDataString(fn);
            string test = "InTheHand.Net.Personal%2C%20Version%3D3.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull";
            Assert.AreEqual(test, fnE, "weeee");
            string v2 = value.Replace("[A-F-N]", fnE);
            return v2;
        }

    }//class


    [TestFixture]
    public class XmlSztn : BtAddrSerialization
    {
        protected override void DoTestRoundTrip(BluetoothAddress obj)
        {
            XmlSerializer szr = new XmlSerializer(obj.GetType());
            StringWriter wtr = new StringWriter();
            szr.Serialize(wtr, obj);
            //
            StringReader rdr = new StringReader(wtr.ToString());
            BluetoothAddress back = (BluetoothAddress)szr.Deserialize(rdr);
            Assert.AreEqual(obj, back, "Equals");
            Assert.AreEqual(obj.ToString("C"), back.ToString("C"), "ToString(\"C\")");
        }

        [Test]
        public void OneFormat()
        {
            BluetoothAddress obj = BluetoothAddress.Parse("001122334455");
            //
            XmlSerializer szr = new XmlSerializer(obj.GetType());
            StringWriter wtr = new StringWriter();
            szr.Serialize(wtr, obj);
            // SZ Format
            const String NewLine = "\r\n";
            const String XmlHeader = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" + NewLine;
            String xmlData
                = XmlHeader
                + "<BluetoothAddress>001122334455</BluetoothAddress>"
                ;
            Assert.AreEqual(xmlData, wtr.ToString(), "Equals");
        }

    }//class


    public abstract class BtAddrSerialization
    {
        protected abstract void DoTestRoundTrip(BluetoothAddress addr);

        [Test]
        public void One()
        {
            DoTestRoundTrip(BluetoothAddress.Parse("001122334455"));
        }

        [Test]
        public void None()
        {
            DoTestRoundTrip(BluetoothAddress.None);
        }

        [Test]
        public void NoneParsed()
        {
            DoTestRoundTrip(BluetoothAddress.Parse("00:00:00:00:00:00"));
        }

    }//class
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.