- mhtmllib_src.zip
- Rilling.MhtmlLib
- docs
- api
- design
- ClassDiagram.vsd
- tutorials
- MhtmlLib.sln
- src
- Rilling.Web.Mhtml.TestHarness
- Rilling.Web.Mhtml.TestHarness_old
- Rilling.Web.Mhtml.TestSite
- Rilling.Web.Mhtml
- WinCapture
- mhtmllib_demo.zip
|
using System;
using System.Text;
using Rilling.Web.Mhtml.Mime.Artifacts;
using System.IO;
using NUnit.Framework;
namespace Rilling.Web.Mhtml.Mime.Artifacts
{
[TestFixture()]
public class TextArtifactTest
{
private const string sampleArtifactPath = "SampleData/TextSample.txt";
private TextArtifact CreateTestArtifact()
{
FileStream fs = new FileStream(sampleArtifactPath, FileMode.Open, FileAccess.Read, FileShare.Read);
TextArtifact artifact = new TextArtifact(fs);
fs.Close();
return (artifact);
}
[Test()]
public void CreateInstance()
{
TextArtifact artifact = CreateTestArtifact();
//
// Verify that the stream contents are correct.
//
FileStream tmp = new FileStream(sampleArtifactPath, FileMode.Open);
StreamReader sr1 = new StreamReader(tmp);
StreamReader sr2 = new StreamReader(artifact.BaseStream);
string origContent = sr1.ReadToEnd();
string newContent = sr2.ReadToEnd();
Assert.AreEqual(origContent.Length,
newContent.Length);
Assert.AreEqual(origContent, newContent);
tmp.Close();
}
[Test()]
[ExpectedException(typeof(ArgumentNullException))]
public void CreateInstance_NullReference()
{
TextArtifact artifact = new TextArtifact(null);
}
[Test()]
public void EncodingProperty()
{
TextArtifact artifact = CreateTestArtifact();
Encoding testValue = Encoding.UTF8;
//
// Verify the before and after state of the property.
//
Assert.IsNull(artifact.Encoding);
artifact.Encoding = Encoding.UTF8;
Assert.IsNotNull(artifact.Encoding);
Assert.AreSame(testValue, artifact.Encoding);
Assert.AreEqual("utf-8", artifact.CharacterSet);
}
[Test()]
public void CharacterSetProperty()
{
TextArtifact artifact = CreateTestArtifact();
string testValue = "utf-8";
artifact.CharacterSet = testValue;
Assert.AreEqual(testValue, artifact.CharacterSet);
Assert.AreSame(Encoding.UTF8, artifact.Encoding);
}
[Test()]
public void ToStringMethod()
{
TextArtifact artifact = CreateTestArtifact();
//
// Verify that the stream contents are correct.
//
FileStream tmp = new FileStream(sampleArtifactPath, FileMode.Open);
StreamReader sr1 = new StreamReader(tmp);
string origContent = sr1.ReadToEnd();
string newContent = artifact.ToString();
Assert.AreEqual(origContent, newContent);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.