using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.IO;
using Rilling.MhtmlLib.Media.Artifacts;
using Rilling.MhtmlLib.Media;
using Rilling.MhtmlLib.Media.Resolvers;
using Rilling.MhtmlLib.Media;
namespace Rilling.Web.Mhtml.TestHarness
{
[TestFixture()]
public class StylesheetLinkResolverTest
{
string[] testVals1 = new string[]
{ "<frame src=\"myframe.wav\"/>",
"<frame src=\"myframe.wav\" xxx=\"nothing\"/>",
"<frame xxx=\"nothing\" src=\"myframe.wav\"/>",
"<frame src='myframe.wav'/>",
"<frame src=myframe.wav/>",
"<iframe src=\"myframe.wav\"/>",
"<iframe src=\"myframe.wav\" xxx=\"nothing\"/>",
"<iframe xxx=\"nothing\" src=\"myframe.wav\"/>",
"<iframe src='myframe.wav'/>",
"<iframe src=myframe.wav/>" };
StylesheetLinkResolver testObj = null;
[SetUp]
public void InitTest()
{
testObj = new StylesheetLinkResolver();
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void Call_LocateReferences_NullParam_ContentData()
{
testObj.LocateReferences(null, new Uri("http://www.rilling.net/"));
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void Call_LocateReferences_NullParam_BaseUrl()
{
testObj.LocateReferences(new TextArtifact(new MemoryStream()), null);
}
private void CallLocateReferencesHelper(string baseUri,
string[] testVals,
string expected)
{
foreach (string testVal in testVals)
{
//
// Prepare the artifact.
//
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(testVal);
writer.Flush();
TextArtifact artifact = new TextArtifact(stream);
artifact.ContentType = ContentTypes.Html;
//
// Try to locate and validate the found link.
//
LinkIdentification[] results =
testObj.LocateReferences(artifact, new Uri(baseUri));
//
// Make sure it is as expected.
//
Assert.AreEqual(1, results.Length, "Unable to locate any links (" + testVal + ")");
Assert.AreEqual(expected, results[0].Url.ToString(), "Unable to locate any links (" + testVal + ")");
}
}
[Test()]
public void Call_LocateReferences_FolderBaseUri()
{
CallLocateReferencesHelper("http://www.rilling.net/nowhere/",
testVals1,
"http://www.rilling.net/nowhere/mystyles.css");
}
[Test()]
public void Call_LocateReferences_FileBaseUri()
{
CallLocateReferencesHelper("http://www.rilling.net/nowhere",
testVals1,
"http://www.rilling.net/mystyles.css");
}
}
}