|
using System.ComponentModel;
using Catel.Articles._04___Unit_testing.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Catel.Articles._04___Unit_testing.Test.Models
{
[TestClass]
public class PersonTest
{
[TestMethod]
public void Validation()
{
Person person = new Person();
IDataErrorInfo personAsErrorInfo = (IDataErrorInfo) person;
Assert.IsTrue(person.HasErrors);
Assert.IsFalse(string.IsNullOrEmpty(personAsErrorInfo[person.GenderProperty.Name]));
Assert.IsFalse(string.IsNullOrEmpty(personAsErrorInfo[person.FirstNameProperty.Name]));
Assert.IsTrue(string.IsNullOrEmpty(personAsErrorInfo[person.MiddleNameProperty.Name]));
Assert.IsFalse(string.IsNullOrEmpty(personAsErrorInfo[person.LastNameProperty.Name]));
person.Gender = Gender.Male;
person.FirstName = "John";
person.LastName = "Doe";
Assert.IsFalse(person.HasErrors);
Assert.IsTrue(string.IsNullOrEmpty(personAsErrorInfo[person.GenderProperty.Name]));
Assert.IsTrue(string.IsNullOrEmpty(personAsErrorInfo[person.FirstNameProperty.Name]));
Assert.IsTrue(string.IsNullOrEmpty(personAsErrorInfo[person.MiddleNameProperty.Name]));
Assert.IsTrue(string.IsNullOrEmpty(personAsErrorInfo[person.LastNameProperty.Name]));
}
[TestMethod]
public void FullName()
{
Person person = new Person();
Assert.IsTrue(string.IsNullOrEmpty(person.FullName));
person.FirstName = "Geert";
Assert.AreEqual("Geert", person.FullName);
person.MiddleName = "van";
Assert.AreEqual("Geert van", person.FullName);
person.LastName = "Horrik";
Assert.AreEqual("Geert van Horrik", person.FullName);
person.MiddleName = string.Empty;
Assert.AreEqual("Geert Horrik", person.FullName);
}
}
}
|
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 member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.