using System.ComponentModel; using CodeProject.ComponentModel; using CodeProject.VisualStudio.QualityTools.UnitTestFramework; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Test.CodeProjectCore { [TestClass] public class TestDataErrorInfo { private class TestObject : IDataErrorInfo { private DataErrorInfo errorInfo; public TestObject() { errorInfo = new DataErrorInfo(this); } public bool IsValid { get { errorInfo.Update(); return errorInfo.IsValid; } } [StringLengthValidator(Max=5)] public string StringProperty { get; set; } #region IDataErrorInfo Members public string Error { get { return errorInfo.Error; } } public string this[string columnName] { get { return errorInfo[columnName]; } } #endregion } public TestDataErrorInfo() { } 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 DataErrorInfo_should_construct_with_IsValid_true() { object target = new object(); DataErrorInfo errorInfo = new DataErrorInfo(target); Specify.That(errorInfo.IsValid).ShouldBeTrue(); } [TestMethod] public void TestObject_should_construct_with_IsValid_true() { TestObject target = new TestObject(); Specify.That(target.IsValid).ShouldBeTrue(); } [TestMethod] public void StringProperty_assignment_to_string_longer_than_5_characters_should_set_IsValid_false() { TestObject target = new TestObject(); target.StringProperty = "123456"; Specify.That(target.IsValid).ShouldBeFalse(); } } }
By viewing downloads associated with this article you agree to the Terms of use 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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Skills that self-taught computer programmers lack