#region CPL License /* Nuclex Framework Copyright (C) 2002-2012 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion #if UNITTEST using System; using NUnit.Framework; namespace Nuclex.Support { /// Unit tests for the observable helper [TestFixture] internal class ObservableHelperTest { #region class TestReferenceType /// Example class on which unit test generates change notifications public class TestReferenceType { /// Example property that will be reported to have changed public int SomeProperty { get; set; } } #endregion // class TestReferenceType #region struct TestValueType /// Example class on which unit test generates change notifications public struct TestValueType { /// Example property that will be reported to have changed public int SomeProperty { get; set; } } #endregion // struct TestValueType /// /// Verifies that the name of a property accessed in a lambda expression /// can be obtained. /// [Test] public void CanObtainPropertyNameFromLambdaExpression() { string propertyName = ObservableHelper.GetPropertyName( () => SomeReferenceType.SomeProperty ); Assert.AreEqual("SomeProperty", propertyName); } /// /// Verifies that the name of a property assigned in a lambda expression /// can be obtained. /// [Test] public void CanObtainPropertyNameFromBoxedLambdaExpression() { string propertyName = ObservableHelper.GetPropertyName( () => (object)(SomeValueType.SomeProperty) ); Assert.AreEqual("SomeProperty", propertyName); } /// Helper used to construct lambda expressions protected static TestReferenceType SomeReferenceType { get; set; } /// Helper used to construct lambda expressions protected static TestValueType SomeValueType { get; set; } } } #endif // UNITTEST