using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using ImageSorter;
using System.IO;
namespace ImageSorterTests
{
[TestFixture]
public class TestSaveLoad
{
const string c_simpleImageList = @"
";
[Test]
public void TestSimpleLoad()
{
doSImpleLoadTest(c_simpleImageList);
}
private static void doSImpleLoadTest(string fileToLoad)
{
ImageCollection images;
using (StringReader rdr = new StringReader(fileToLoad))
{
images = new ImageCollection(rdr);
}
Assert.AreEqual(1, images.Count);
Assert.AreEqual("IMG_2097.JPG", images[0].Filename);
Assert.IsTrue(images[0].HasTag("bike"));
Assert.IsFalse(images[0].HasTag("sunshine"));
Assert.AreEqual(1, images.Tags.Count);
List tags = new List(images.Tags);
Assert.AreEqual("bike", tags[0]);
}
[Test]
public void TestSave()
{
// GIVEN an image collection loaded from the
// simple file above
ImageCollection images;
using (StringReader rdr = new StringReader(c_simpleImageList))
{
images = new ImageCollection(rdr);
}
// WHEN we save it again
string saveFile;
using (StringWriter wrt = new StringWriter())
{
images.WriteTo(wrt);
saveFile = wrt.ToString();
}
// THEN the save file should be reasonable
StringAssert.Contains("IMG_2097.JPG", saveFile);
StringAssert.Contains("bike", saveFile);
// and it should be possible to re-read
// it, with the same results as the original
// save file.
doSImpleLoadTest(saveFile);
}
}
}