BtEndPointSerialization.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 » BtEndPointSerialization.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;
using InTheHand.Net.Bluetooth;

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

        [Test]
        public void OneFormat()
        {
            BluetoothEndPoint obj = new BluetoothEndPoint(
                BluetoothAddress.Parse("001122334455"), BluetoothService.SerialPort);
            //
            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:BluetoothEndPoint id=\"ref-1\" xmlns:a1=\"http://schemas.microsoft.com/clr/nsassem/InTheHand.Net/[A-F-N]\">" + NewLine
                + "<m_id href=\"#ref-3\"/>" + NewLine
                + "<m_service>" + NewLine
                + "<_a>4353</_a>" + NewLine
                + "<_b>0</_b>" + NewLine
                + "<_c>4096</_c>" + NewLine
                + "<_d>128</_d>" + NewLine
                + "<_e>0</_e>" + NewLine
                + "<_f>0</_f>" + NewLine
                + "<_g>128</_g>" + NewLine
                + "<_h>95</_h>" + NewLine
                + "<_i>155</_i>" + NewLine
                + "<_j>52</_j>" + NewLine
                + "<_k>251</_k>" + NewLine
                + "</m_service>" + NewLine
                + "<m_port>-1</m_port>" + NewLine
                + "</a1:BluetoothEndPoint>" + NewLine
                + "<a1:BluetoothAddress id=\"ref-3\" xmlns:a1=\"http://schemas.microsoft.com/clr/nsassem/InTheHand.Net/[A-F-N]\">" + NewLine
                + "<dataString id=\"ref-4\">001122334455</dataString>" + NewLine
                + "</a1:BluetoothAddress>" + NewLine
                + "</SOAP-ENV:Body>" + NewLine
                + "</SOAP-ENV:Envelope>" + NewLine
                ;
            strm.Position = 0;
            String result = new StreamReader(strm).ReadToEnd();
            string expected = InTheHand.Net.Tests.Bluetooth.TestBluetoothAddress.IFormatterSztn
                .InsertAssemblyFullNameEscaped(xmlData);
            Assert.AreEqual(expected, result, "Equals");
        }

    }//class


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

        [Test]
        public void OneFormat()
        {
            BluetoothEndPoint obj = new BluetoothEndPoint(
                BluetoothAddress.Parse("001122334455"), BluetoothService.SerialPort);
            //
            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
                + "<BluetoothEndPoint xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + NewLine
                + "  <Address>001122334455</Address>" + NewLine
                + "  <Service>00001101-0000-1000-8000-00805f9b34fb</Service>" + NewLine
                + "  <Port>-1</Port>" + NewLine
                + "</BluetoothEndPoint>"
                ;
            Assert.AreEqual(xmlData, wtr.ToString(), "Equals");
        }

    }//class


    public abstract class Serialization
    {
        protected abstract void DoTestRoundTrip(BluetoothEndPoint addr);

        [Test]
        public void One()
        {
            DoTestRoundTrip(new BluetoothEndPoint(
                BluetoothAddress.Parse("001122334455"), BluetoothService.SerialPort));
        }

        [Test]
        public void Two()
        {
            DoTestRoundTrip(new BluetoothEndPoint(
                BluetoothAddress.Parse("FFEEDDCCBBAA"), 
                new Guid("{3906B199-5B79-4326-B18E-B065B211C14E}")));
        }

        [Test]
        public void None()
        {
            DoTestRoundTrip(new BluetoothEndPoint(BluetoothAddress.None, BluetoothService.Empty));
        }

    }//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.