view Xml/XmlResourceResolverTests.cs @ 49:99e4c1949c92 default tip

* Update to v2.6 of NUnit and new syntax/API changes
author IBBoard <dev@ibboard.co.uk>
date Sun, 28 Apr 2013 19:32:14 +0100
parents 1e731dda7608
children
line wrap: on
line source

//  This file (XmlResourceResolverTests.cs) is a part of the IBBoard.Tests project and is copyright 2012 IBBoard
//
//  The file and the library/program it is in are licensed and distributed, without warranty, under the GNU LGPL, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
using System;
using NUnit.Framework;
using System.Reflection;
using System.IO;

namespace IBBoard.Xml
{
	[TestFixture()]
	public class XmlResourceResolverTests
	{
		[Test()]
		public void TestGettingStreamForAddedResource()
		{
			Assembly localAssembly = Assembly.GetExecutingAssembly();
			XmlResourceResolver resolver = new XmlResourceResolver(localAssembly);
			string uriString = "http://ibboard.co.uk/some.xsd";
			string resourceID = "IBBoard.test-data.ResourceResolver.some.xsd";
			resolver.AddMapping(uriString, resourceID);
			Assert.That(resolver.ResolveUri(null, uriString), Is.EqualTo(new Uri(uriString)));
			Stream resolvedStream = (Stream)resolver.GetEntity(new Uri(uriString), null, typeof(Stream));
			Assert.That(resolvedStream, Is.EqualTo(localAssembly.GetManifestResourceStream(resourceID)));
		}

		[Test()]
		public void TestGettingStreamForNonStandardURI()
		{
			Assembly localAssembly = Assembly.GetExecutingAssembly();
			XmlResourceResolver resolver = new XmlResourceResolver(localAssembly);
			string dtdString = "-//W3C//ENTITIES Latin 1 for XHTML//EN";
			string uriString = "http://w3c.org/latin.xsd";
			string resourceID = "IBBoard.test-data.ResourceResolver.some.xsd";
			resolver.AddMapping(dtdString, uriString, resourceID);
			Assert.That(resolver.ResolveUri(null, dtdString), Is.EqualTo(new Uri(uriString)));
			Stream resolvedStream = (Stream)resolver.GetEntity(new Uri(uriString), null, typeof(Stream));
			Assert.That(resolvedStream, Is.EqualTo(localAssembly.GetManifestResourceStream(resourceID)));
		}
	}
}