PackUriHelperTests.cs :  » 2.6.4-mono-.net-core » System.IO » System » IO » Packaging » Tests » 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 » 2.6.4 mono .net core » System.IO 
System.IO » System » IO » Packaging » Tests » PackUriHelperTests.cs
// PackUriHelperTests.cs created with MonoDevelop
// User: alan at 13:39 28/10/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;
using System.IO.Packaging;
using NUnit.Framework;

namespace System.IO.Packaging.Tests{
  
    [TestFixture]
    [Category ("NotWorking")]
    [Ignore ("This depends on a fix to System.Uri to support the UriParser API")]
    public class PackUriHelperTests {
        static void Main (string [] args)
        {
            PackUriHelperTests t = new PackUriHelperTests ();
            t.ResolvePartUri2 ();
        }


        Uri a;
        Uri b;
        Uri part1 = new Uri ("/file1", UriKind.Relative);
        Uri part2 = new Uri ("/file2", UriKind.Relative);
        Uri main = new Uri ("/main.html", UriKind.Relative);

    [SetUpAttribute]
    public void Setup()
    {
      a = PackUriHelper.Create (new Uri ("http://www.test.com/pack1.pkg"));
      b = PackUriHelper.Create (new Uri ("http://www.test.com/pack2.pkg"));
      Console.WriteLine ("A is: {0}", a);
      Console.WriteLine("B is: {0}", b);
    }
    
        [Test]
        public void ComparePackUriTest ()
        {
            Assert.AreEqual (0, PackUriHelper.ComparePackUri (null, null), "#1");
            Assert.IsTrue (PackUriHelper.ComparePackUri (a, null) > 0, "#2");
            Assert.AreEqual (0, PackUriHelper.ComparePackUri (a, a), "#3");
            Assert.IsTrue (PackUriHelper.ComparePackUri (a, b) < 0, "#4");
        }

        [Test]
        [ExpectedException(typeof(UriFormatException))]
        public void CompareInvalidTest ()
        {
            Uri a = new Uri ("pack://url1");
            PackUriHelper.ComparePackUri (a, a);
        }

        [Test]
        [ExpectedException (typeof (ArgumentException))]
        public void NonPackUriCompareTest ()
        {
            PackUriHelper.ComparePackUri (new Uri ("http://wtest.com"), a);
        }

        [Test]
        [ExpectedException (typeof (ArgumentException))]
        public void NonPackUriCompareRelativeTest ()
        {
            PackUriHelper.ComparePackUri (new Uri ("wtest.com", UriKind.Relative), a);
        }

        [Test]
        [ExpectedException (typeof (ArgumentException))]
        public void InvalidPartUriCompareTest ()
        {
            PackUriHelper.ComparePartUri (a, b);
        }

        [Test]
        public void PartUriCompareTest ()
        {
            Assert.AreEqual (0, PackUriHelper.ComparePartUri (null, null), "#1");
            Assert.IsTrue (PackUriHelper.ComparePartUri (part1, null) > 0, "#2");
            Assert.IsTrue (PackUriHelper.ComparePartUri (part1, part2) < 0, "#3");
        }

        [Test]
        public void CreateTest ()
        {
            Assert.AreEqual ("pack://http:,,www.test.com,pack.pkg/",
                             PackUriHelper.Create (new Uri ("http://www.test.com/pack.pkg")).ToString (), "#1");
            Assert.AreEqual ("pack://http:,,www.test.com,pack.pkg/",
                             PackUriHelper.Create (new Uri ("http://www.test.com/pack.pkg"), null, null).ToString (), "#2");
            Assert.AreEqual ("pack://http:,,www.test.com,pack.pkg/main.html#frag",
                             PackUriHelper.Create (new Uri ("http://www.test.com/pack.pkg"),
                                             new Uri ("/main.html", UriKind.Relative), "#frag").ToString (), "#3");
            Assert.AreEqual ("pack://http:,,www.test.com,pack.pkg/main.html#frag",
                             PackUriHelper.Create (new Uri ("http://www.test.com/pack.pkg"),
                                             new Uri ("/main.html", UriKind.Relative), "#frag").ToString (), "#3");
        }

        [Test]
        [ExpectedException (typeof (ArgumentException))]
        public void CreateInvalidTest ()
        {
            PackUriHelper.Create (new Uri ("http://www.test.com/pack.pkg"), new Uri ("/main.html", UriKind.Relative), "notfrag");
        }

        [Test]
        [ExpectedException (typeof (ArgumentException))]
        public void CreateInvalidTest2 ()
        {
            PackUriHelper.Create (new Uri ("http://www.test.com/pack.pkg"), new Uri ("/main.html", UriKind.Relative), "");
        }

        [Test]
        [ExpectedException (typeof (ArgumentException))]
        public void CreateInvalidTest3 ()
        {
            PackUriHelper.Create (new Uri ("http://www.test.com/pack.pkg"), new Uri ("/main.html", UriKind.Relative), "");
        }

        [Test]
        public void CreateInvalidTest4 ()
        {
            PackUriHelper.Create (new Uri ("http://www.test.com/pack.pkg"), new Uri ("/main.html", UriKind.Relative));
        }

        [Test]
        public void CreatePartUri ()
        {
            Assert.IsFalse (PackUriHelper.CreatePartUri (part1).IsAbsoluteUri, "#1");
            Assert.AreEqual (new Uri (part1.ToString (), UriKind.Relative), PackUriHelper.CreatePartUri (part1), "#2");
        }

        [Test]
        [ExpectedException (typeof (ArgumentNullException))]
        public void CreatePartUri2 ()
        {
            PackUriHelper.CreatePartUri (null);
        }

        [Test]
        public void GetNormalizedPartUriTest ()
        {
            Uri uri = new Uri ("/test.com".ToUpperInvariant (), UriKind.Relative);
            Assert.IsTrue (uri == PackUriHelper.GetNormalizedPartUri (uri));
        }
        [Test]
        public void GetNormalisedPartUritest4 ()
        {
            PackUriHelper.GetNormalizedPartUri (part1);
        }

        [Test]
        [ExpectedException (typeof (ArgumentNullException))]
        public void GetNormalizedPartUriTest2 ()
        {
            PackUriHelper.GetNormalizedPartUri (null);
        }

        [Test]
        [ExpectedException (typeof (UriFormatException))]
        public void GetNormalizedPartUriTest3 ()
        {
            Assert.AreEqual (new Uri (a.ToString ().ToUpperInvariant (), UriKind.Relative), PackUriHelper.GetNormalizedPartUri (a));
        }

        [Test]
        public void GetPackageUriTest ()
        {
            Assert.AreEqual (a, PackUriHelper.GetPackageUri (PackUriHelper.Create (a, new Uri ("/test.html", UriKind.Relative))));
        }

        [Test]
        [ExpectedException (typeof (ArgumentNullException))]
        public void GetPackageUri2 ()
        {
            PackUriHelper.GetPackageUri (null);
        }

        [Test]
        [ExpectedException (typeof (ArgumentException))]
        public void GetPackageUri3 ()
        {
            PackUriHelper.GetPackageUri (part1);
        }

        [Test]
        public void GetPartUriTest ()
        {
            Assert.IsNull (PackUriHelper.GetPartUri (a), "#1");
            Assert.AreEqual (main, PackUriHelper.GetPartUri (PackUriHelper.Create (a, main)), "#2");
        }

        [Test]
        [ExpectedException (typeof (ArgumentNullException))]
        public void GetPartUriTest2 ()
        {
            PackUriHelper.GetPartUri (null);
        }

        [Test]
        [ExpectedException (typeof (ArgumentException))]
        public void GetPartUriTest3 ()
        {
            PackUriHelper.GetPartUri (part1);
        }

        [Test]
        public void GetRelationshipPartUriTest ()
        {
            Assert.AreEqual ("/_rels/file1.rels", PackUriHelper.GetRelationshipPartUri (part1).ToString());
        }

        [Test]
        [ExpectedException (typeof (ArgumentNullException))]
        public void GetRelationshipPartUriTest2 ()
        {
            PackUriHelper.GetRelationshipPartUri (null);
        }

        [Test]
        public void GetRelativeUriTest ()
        {
            Uri src = new Uri ("/1/2/3/file.jpg", UriKind.Relative);
            Uri dest = new Uri ("/file2.png", UriKind.Relative);
            Assert.AreEqual (new Uri ("../../../file2.png", UriKind.Relative), PackUriHelper.GetRelativeUri (src, dest), "#1");

            dest = new Uri ("/1/2", UriKind.Relative);
            Assert.AreEqual (new Uri ("../../2", UriKind.Relative), PackUriHelper.GetRelativeUri (src, dest), "#2");

            dest = new Uri ("/1/2/", UriKind.Relative);
            Assert.AreEqual (new Uri ("", UriKind.Relative), PackUriHelper.GetRelativeUri (src, src), "#4");
        }

        [Test]
        [ExpectedException (typeof(ArgumentException))]
        public void GetRelativeUriTest2 ()
        {
            Uri src = new Uri ("/1/2/3/file.jpg", UriKind.Relative);
            Uri dest = new Uri ("/1/2/", UriKind.Relative);
            Assert.AreEqual (new Uri ("../file2.png", UriKind.Relative), PackUriHelper.GetRelativeUri (src, dest), "#3");
        }

        [Test]
        public void IsRelationshipPartUriTest ()
        {
            Assert.IsFalse (PackUriHelper.IsRelationshipPartUri (new Uri ("/_rels/Whatever", UriKind.Relative)));
            Assert.IsTrue (PackUriHelper.IsRelationshipPartUri (new Uri ("/_rels/Whatever.rels", UriKind.Relative)));
        }

        [Test]
        public void IsRelationshipPartUriTest2 ()
        {
            Uri uri = new Uri ("/test/uri", UriKind.Relative);
            PackUriHelper.IsRelationshipPartUri (uri);
        }

        [Test]
        [ExpectedException(typeof(UriFormatException))]
        public void ResolvePartUri ()
        {
            Uri src = new Uri ("/1/2/3/4", UriKind.Relative);
            Uri dest = new Uri ("/MyFile", UriKind.Relative);

            // Can't be empty url
            Assert.AreEqual (new Uri (""), PackUriHelper.ResolvePartUri (src, dest), "#1");
        }


        [Test]
        //[ExpectedException (typeof (UriFormatException))]
        public void ResolvePartUri2 ()
        {
            Uri src = new Uri ("/1/2/3/4", UriKind.Relative);
            Uri dest = new Uri ("/1/2/MyFile", UriKind.Relative);

            // Can't be empty url
            Assert.AreEqual (new Uri ("/1/2/MyFile", UriKind.Relative), PackUriHelper.ResolvePartUri (src, dest), "#1");
            Assert.AreEqual (new Uri ("/1/2/3/4", UriKind.Relative), PackUriHelper.ResolvePartUri (dest, src), "#1");
        }

        [Test]
        [ExpectedException (typeof (ArgumentException))]
        public void ResolvePartUri3 ()
        {
            Uri src = new Uri ("/1/2/3/4", UriKind.Relative);
            Uri dest = new Uri ("http://www.example.com", UriKind.Absolute);
            PackUriHelper.ResolvePartUri (src, dest);
        }

        [Test]
        public void ResolvePartUri4 ()
        {
            Uri src = new Uri ("/", UriKind.Relative);
            Uri dest = new Uri ("word/document.xml", UriKind.Relative);

            Uri result = PackUriHelper.ResolvePartUri (src, dest);
            Assert.IsFalse(result.IsAbsoluteUri, "#1");
            Assert.AreEqual ("/word/document.xml", result.ToString(), "#2");
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.