|
using System.IO;
using CodeProject.VisualStudio.QualityTools.UnitTestFramework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TaskList.DataModel;
namespace Test.TaskList.DataModel
{
[TestClass]
public class TaskCollectionTest
{
public TaskCollectionTest()
{
}
private TestContext testContextInstance;
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void TaskCollection_should_construct_empty()
{
TaskCollection target = new TaskCollection();
Specify.That(target).ShouldBeEmpty();
}
[TestMethod]
public void TaskCollection_should_construct_with_IsDirty_false()
{
TaskCollection target = new TaskCollection();
Specify.That(target.IsDirty).ShouldBeFalse();
}
[TestMethod]
public void IsDirty_assignment_should_notify_property_changed()
{
TaskCollection target = new TaskCollection();
PropertyChangedWatcher watcher = new PropertyChangedWatcher(target);
target.IsDirty = true;
Specify.That(watcher).ShouldHaveSeen("IsDirty");
}
[TestMethod]
public void Add_should_set_IsDirty_true()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
target.Add(item);
Specify.That(target.IsDirty).ShouldBeTrue();
}
[TestMethod]
public void Add_should_notify_IsDirty_changed()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
PropertyChangedWatcher watcher = new PropertyChangedWatcher(target);
target.Add(item);
Specify.That(watcher).ShouldHaveSeen("IsDirty");
}
[TestMethod]
public void Remove_should_set_IsDirty_true()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
target.Add(item);
target.IsDirty = false;
target.Remove(item);
Specify.That(target.IsDirty).ShouldBeTrue();
}
[TestMethod]
public void Remove_should_notify_IsDirty_changed()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
target.Add(item);
target.IsDirty = false;
PropertyChangedWatcher watcher = new PropertyChangedWatcher(target);
target.Remove(item);
Specify.That(watcher).ShouldHaveSeen("IsDirty");
}
[TestMethod]
public void Clear_should_set_IsDirty_true()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
target.Add(item);
target.IsDirty = false;
target.Clear();
Specify.That(target.IsDirty).ShouldBeTrue();
}
[TestMethod]
public void Clear_should_not_set_IsDirty_true_when_already_empty()
{
TaskCollection target = new TaskCollection();
target.Clear();
Specify.That(target.IsDirty).ShouldBeFalse();
}
[TestMethod]
public void Clear_should_notify_IsDirty_changed()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
target.Add(item);
target.IsDirty = false;
PropertyChangedWatcher watcher = new PropertyChangedWatcher(target);
target.Clear();
Specify.That(watcher).ShouldHaveSeen("IsDirty");
}
[TestMethod]
public void Item_assignment_should_set_IsDirty_true()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
target.Add(item);
target.IsDirty = false;
target[0] = null;
Specify.That(target.IsDirty).ShouldBeTrue();
}
[TestMethod]
public void Item_assignment_to_same_item_should_not_set_IsDirty_true()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
target.Add(item);
target.IsDirty = false;
target[0] = item;
Specify.That(target.IsDirty).ShouldBeFalse();
}
[TestMethod]
public void Item_assignment_should_notify_IsDirty_changed()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
target.Add(item);
target.IsDirty = false;
PropertyChangedWatcher watcher = new PropertyChangedWatcher(target);
target[0] = null;
Specify.That(watcher).ShouldHaveSeen("IsDirty");
}
[TestMethod]
public void Move_should_set_IsDirty_true()
{
TaskCollection target = new TaskCollection();
Task first = new Task();
Task second = new Task();
target.Add(first);
target.Add(second);
target.IsDirty = false;
target.Move(0, 1);
Specify.That(target.IsDirty).ShouldBeTrue();
}
[TestMethod]
public void Move_should_notify_IsDirty_changed()
{
TaskCollection target = new TaskCollection();
Task first = new Task();
Task second = new Task();
target.Add(first);
target.Add(second);
target.IsDirty = false;
PropertyChangedWatcher watcher = new PropertyChangedWatcher(target);
target.Move(0, 1);
Specify.That(watcher).ShouldHaveSeen("IsDirty");
}
[TestMethod]
public void TaskCollection_should_be_serializable()
{
TaskCollection target = new TaskCollection();
string expectedTitle = "xyzzy";
Task item = new Task();
item.Title = expectedTitle;
target.Add(item);
TaskCollection clone = target.SerializeClone();
Specify.That(clone[0].Title).ShouldEqual(expectedTitle);
}
[TestMethod]
public void Modifying_item_should_set_IsDirty_true()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
target.Add(item);
target.IsDirty = false;
item.Title = "xyzzy";
Specify.That(target.IsDirty).ShouldBeTrue();
}
[TestMethod]
public void Modifying_item_should_notify_IsDirty_changed()
{
TaskCollection target = new TaskCollection();
Task item = new Task();
target.Add(item);
target.IsDirty = false;
PropertyChangedWatcher watcher = new PropertyChangedWatcher(target);
item.Title = "xyzzy";
Specify.That(watcher).ShouldHaveSeen("IsDirty");
}
[TestMethod]
public void Save_should_create_file()
{
string fileName = Path.GetTempFileName();
try
{
File.Delete(fileName);
TaskCollection target = new TaskCollection();
Task item = new Task();
item.Title = "xyzzy";
target.Add(item);
target.Save(fileName);
Specify.That(File.Exists(fileName));
}
finally
{
File.Delete(fileName);
}
}
[TestMethod]
public void Load_should_load_new_TaskCollection()
{
string fileName = Path.GetTempFileName();
try
{
File.Delete(fileName);
TaskCollection target = new TaskCollection();
string expectedTitle = "xyzzy";
Task item = new Task();
item.Title = expectedTitle;
target.Add(item);
target.Save(fileName);
TaskCollection loaded = TaskCollection.Load(fileName);
Specify.That(loaded[0].Title).ShouldEqual(expectedTitle);
}
finally
{
File.Delete(fileName);
}
}
}
}
|
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.
Windows developer with 10+ years experience working in the banking industry.