コード例 #1
0
        public void ClearAllDataErrorInfo_GetErrorsShouldReturnEmptySet()
        {
            var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" };
            var objectDataErrorInfo1 = new DataErrorInfo ( "ObjectLevelError1", ErrorLevel.Error );
            var objectDataErrorInfo2 = new DataErrorInfo ( "ObjectLevelError2", ErrorLevel.Error );
            var propertyDataErrorInfo = new DataErrorInfo ( "PropertyLevelError", ErrorLevel.Error, "FirstName" );
            var crossDataErrorInfo = new DataErrorInfo ( "CrossPropertyLevelError", ErrorLevel.Error, "FirstName",
                                                         "LastName" );

            personDto.AddDataErrorInfo ( objectDataErrorInfo1 );
            personDto.AddDataErrorInfo ( objectDataErrorInfo2 );
            personDto.AddDataErrorInfo ( propertyDataErrorInfo );
            personDto.AddDataErrorInfo ( crossDataErrorInfo );

            personDto.ClearAllDataErrorInfo ();

            IEnumerable<DataErrorInfo> errors = personDto.GetErrors ( null ) as IEnumerable<DataErrorInfo>;
            List<DataErrorInfo> returnedList = new List<DataErrorInfo> ( errors );

            Assert.IsTrue ( returnedList.Count () == 0 );
        }
コード例 #2
0
        public void ClearAllDataErrorInfo_ErrorsChangedEventShouldFire()
        {
            var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" };
            var objectDataErrorInfo1 = new DataErrorInfo ( "ObjectLevelError1", ErrorLevel.Error );
            var objectDataErrorInfo2 = new DataErrorInfo ( "ObjectLevelError2", ErrorLevel.Error );
            var propertyDataErrorInfo = new DataErrorInfo ( "PropertyLevelError", ErrorLevel.Error, "FirstName" );
            var crossDataErrorInfo = new DataErrorInfo ( "CrossPropertyLevelError", ErrorLevel.Error, "FirstName",
                                                         "LastName" );

            HashSet<string> referenceNames = new HashSet<string> { "FirstName", "", "LastName" };
            HashSet<string> propertyNames = new HashSet<string> ();

            personDto.AddDataErrorInfo ( objectDataErrorInfo1 );
            personDto.AddDataErrorInfo ( objectDataErrorInfo2 );
            personDto.AddDataErrorInfo ( propertyDataErrorInfo );
            personDto.AddDataErrorInfo ( crossDataErrorInfo );
            personDto.ErrorsChanged += ( s, e ) => propertyNames.Add ( e.PropertyName );

            personDto.ClearAllDataErrorInfo ();

            AssertSetsEqual ( referenceNames, propertyNames );
        }