예제 #1
0
 /// <summary>
 /// Tries the add data error info.
 /// </summary>
 /// <param name="dataErrorInfo">The data error info.</param>
 public void TryAddDataErrorInfo(DataErrorInfo dataErrorInfo)
 {
     if (!DataErrorInfoCollection.Contains(dataErrorInfo))
     {
         AddDataErrorInfo(dataErrorInfo);
     }
 }
예제 #2
0
        public void AddDataErrorInfo_AddsPropertyLevelError_Succeeds()
        {
            var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "PropertyLevelError", ErrorLevel.Error, "FirstName" );
            personDto.AddDataErrorInfo ( dataErrorInfo );

            IList referenceCollection = new ArrayList { dataErrorInfo };

            CollectionAssert.AreEqual ( referenceCollection, personDto.DataErrorInfoCollection.ToList () );
        }
예제 #3
0
        public void AddDataErrorInfo_AddingACrossPropertyLevelError_ErrorsChangedEventShouldFire()
        {
            var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "EntityLevelError", ErrorLevel.Error, "FirstName", "LastName" );
            List<string> propertyNames = new List<string> { "FirstName", "LastName" };

            personDto.ErrorsChanged += ( s, e ) => RemoveFromList ( propertyNames, e.PropertyName );

            personDto.AddDataErrorInfo ( dataErrorInfo );

            Assert.IsTrue ( propertyNames.Count == 0 );
        }
예제 #4
0
        /// <summary>
        /// Adds the data error info.
        /// </summary>
        /// <param name="dataErrorInfo">
        /// The data error info.
        /// </param>
        public void AddDataErrorInfo(DataErrorInfo dataErrorInfo)
        {
            if (dataErrorInfo.DataErrorInfoType != DataErrorInfoType.ObjectLevel)
            {
                foreach (var propertyName in dataErrorInfo.Properties)
                {
                    ValidatePropertyExists(propertyName);
                }
            }

            _dataErrorInfoCollection.Add(dataErrorInfo);
            ReportErrorsChanged(dataErrorInfo);
        }
예제 #5
0
 /// <summary>
 /// Reports when errors have changed.
 /// </summary>
 /// <param name="dataErrorInfo">Error Info.</param>
 partial void ReportErrorsChanged(DataErrorInfo dataErrorInfo)
 {
     if (dataErrorInfo.DataErrorInfoType == DataErrorInfoType.ObjectLevel)
     {
         ReportErrorsChanged(string.Empty);
     }
     else
     {
         foreach (var propertyName in dataErrorInfo.Properties)
         {
             ReportErrorsChanged(propertyName);
         }
     }
 }
예제 #6
0
        public void AddDataErrorInfo_AddingACrossPropertyLevelError_GetErrorsShouldReturnGivenErrorForLastNameProperty()
        {
            var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "PropertyLevelError", ErrorLevel.Error, "FirstName", "LastName" );

            personDto.AddDataErrorInfo ( dataErrorInfo );

            IEnumerable<DataErrorInfo> errors = personDto.GetErrors ( "LastName" ) as IEnumerable<DataErrorInfo>;

            List<DataErrorInfo> returnedList = new List<DataErrorInfo> ( errors );
            List<DataErrorInfo> referenceList = new List<DataErrorInfo> { dataErrorInfo };

            CollectionAssert.AreEqual ( returnedList, referenceList );
        }
예제 #7
0
        public void ClearAllDataErrorInfo_HasObjectLevelErrorsAndPropertyLevelErrorsAndCrossPropertyLevelErrors_ClearsAllErrors()
        {
            var personDto = new PersonDto{ FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo1 = new DataErrorInfo("SomeErrorMessage1", ErrorLevel.Error, "FirstName", "LastName");
            var dataErrorInfo2 = new DataErrorInfo("SomeErrorMessage2", ErrorLevel.Error);
            var dataErrorInfo3 = new DataErrorInfo("SomeErrorMessage3", ErrorLevel.Error, "FirstName" );
            personDto.AddDataErrorInfo(dataErrorInfo1);
            personDto.AddDataErrorInfo(dataErrorInfo2);
            personDto.AddDataErrorInfo(dataErrorInfo3);

            personDto.ClearAllDataErrorInfo ();

            Assert.IsTrue(personDto.DataErrorInfoCollection.Count() == 0);
        }
예제 #8
0
        /// <summary>
        /// Removes the data error info.
        /// </summary>
        /// <param name="dataErrorInfo">The data error info.</param>
        public void RemoveDataErrorInfo(DataErrorInfo dataErrorInfo)
        {
            ISet <string> propertyNames = new HashSet <string> ();

            _dataErrorInfoCollection.Remove(dataErrorInfo);
            if (dataErrorInfo.DataErrorInfoType == DataErrorInfoType.ObjectLevel)
            {
                propertyNames.Add(string.Empty);
            }
            else
            {
                foreach (string name in dataErrorInfo.Properties)
                {
                    propertyNames.Add(name);
                }
            }

            foreach (string reportablePropertyName in propertyNames)
            {
                ReportErrorsChanged(reportablePropertyName);
            }
        }
예제 #9
0
 public void DataTransferObject_NonExistingCrossProperty_ThrowsPropertyNotFoundException()
 {
     var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" };
     var dataErrorInfo = new DataErrorInfo ( "NonExistingCrossProperty", ErrorLevel.Error, "FirstName", "Foo" );
     personDto.AddDataErrorInfo ( dataErrorInfo );
 }
예제 #10
0
 public void AddDataErrorInfo_NonExistingSingleProperty_ThrowsPropertyNotFoundException()
 {
     var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" };
     var dataErrorInfo = new DataErrorInfo ( "NonExistingProperty", ErrorLevel.Error, "Foo" );
     personDto.AddDataErrorInfo ( dataErrorInfo );
 }
예제 #11
0
 public void DataErrorInfo_ObjectLevelError_DataErrorInfoTypeIsObjectLevel()
 {
     var dataErrorInfo = new DataErrorInfo("ErrorMessage", ErrorLevel.Error);
     Assert.AreEqual ( dataErrorInfo.DataErrorInfoType, DataErrorInfoType.ObjectLevel );
 }
 /// <summary>
 /// Reports when errors have changed.
 /// </summary>
 /// <param name="dataErrorInfo">Error Info.</param>
 partial void ReportErrorsChanged(DataErrorInfo dataErrorInfo)
 {
     if ( dataErrorInfo.DataErrorInfoType == DataErrorInfoType.ObjectLevel )
     {
         ReportErrorsChanged ( string.Empty );
     }
     else
     {
         foreach ( var propertyName in dataErrorInfo.Properties )
         {
             ReportErrorsChanged ( propertyName );
         }
     }
 }
예제 #13
0
        public void AddDataErrorInfo_AddingAnObjectLevelError_ErrorsChangedEventShouldFire()
        {
            var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "EntityLevelError", ErrorLevel.Error );
            string propertyName = "Dummy";
            personDto.ErrorsChanged += ( s, e ) => { propertyName = e.PropertyName; };

            personDto.AddDataErrorInfo ( dataErrorInfo );

            Assert.IsTrue ( string.IsNullOrEmpty ( propertyName ) );
        }
예제 #14
0
 public void DataErrorInfo_PropertyLevelWithEmptyPropertyNameError_ThrowsArgumentException()
 {
     var dataErrorInfo = new DataErrorInfo ( "ErrorMessage", ErrorLevel.Error, "" );
 }
예제 #15
0
        public void RemoveDataErrorInfo_RemovingAnObjectLevelError_GetErrorsShouldReturnGivenError()
        {
            var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "EntityLevelError", ErrorLevel.Error );
            IEnumerable<DataErrorInfo> errors = new List<DataErrorInfo> ();

            personDto.AddDataErrorInfo ( dataErrorInfo );

            personDto.ErrorsChanged +=
                ( s, e ) => { errors = personDto.GetErrors ( e.PropertyName ) as IEnumerable<DataErrorInfo>; };

            personDto.RemoveDataErrorInfo ( String.Empty );

            List<DataErrorInfo> returnedList = new List<DataErrorInfo> ( errors );

            Assert.IsTrue ( returnedList.Count == 0 );
        }
예제 #16
0
 public void DataErrorInfo_ObjectLevelError_Succeeds()
 {
     var dataErrorInfo = new DataErrorInfo ( "ErrorMessage", ErrorLevel.Error );
 }
예제 #17
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 );
        }
예제 #18
0
 /// <summary>
 /// Reports the errors changed.
 /// </summary>
 /// <param name="dataErrorInfo">The data error info.</param>
 partial void ReportErrorsChanged(DataErrorInfo dataErrorInfo);
예제 #19
0
 public void DataErrorInfo_PropertyLevelError_DataErrorInfoTypeIsPropertyLevel()
 {
     var dataErrorInfo = new DataErrorInfo("ErrorMessage", ErrorLevel.Error, "PropertyName");
     Assert.AreEqual(dataErrorInfo.DataErrorInfoType, DataErrorInfoType.PropertyLevel);
 }
예제 #20
0
 public void DataErrorInfo_PropertyLevelWithNullPropertyNameError_ThrowsArgumentException()
 {
     string[] s = new string[] { null };
     var dataErrorInfo = new DataErrorInfo ( "ErrorMessage", ErrorLevel.Error, s );
 }
예제 #21
0
 public void DataErrorInfo_CrossPropertyLevelWithNullPropertyNameError_ThrowsArgumentException()
 {
     var dataErrorInfo = new DataErrorInfo ( "ErrorMessage", ErrorLevel.Error, "FirstName", "LastName", null );
 }
예제 #22
0
        public void RemoveDataErrorInfo_RemovingAPropertyLevelError_GetErrorsShouldReturnGivenError()
        {
            var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "PropertyLevelError", ErrorLevel.Error, "FirstName" );

            personDto.AddDataErrorInfo ( dataErrorInfo );

            personDto.RemoveDataErrorInfo ( "FirstName" );

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

            Assert.IsTrue ( returnedList.Count == 0 );
        }
예제 #23
0
        public void RemoveDataErrorInfo_HasPropertyLevelAndObjectLevelErrors_RemovesObjectLevelErrors()
        {
            var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" };
            var propertyDataErrorInfo = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error, "FirstName" );
            var objectDataErrorInfo = new DataErrorInfo ( "SomeErrorMessage2", ErrorLevel.Error );
            personDto.AddDataErrorInfo ( propertyDataErrorInfo );
            personDto.AddDataErrorInfo ( objectDataErrorInfo );

            personDto.RemoveDataErrorInfo ( "" );
            IList referenceCollection = new ArrayList { propertyDataErrorInfo };

            CollectionAssert.AreEqual ( referenceCollection, personDto.DataErrorInfoCollection.ToList () );
        }
예제 #24
0
 public void DataErrorInfo_PropertyLevelError_Succeeds()
 {
     var dataErrorInfo = new DataErrorInfo ( "ErrorMessage", ErrorLevel.Error, "PropertyName" );
 }
예제 #25
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 );
        }
예제 #26
0
        public void RemoveDataErrorInfo_MoreThanOneObjectLevelError_RemovesObjectLevelErrors()
        {
            var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo1 = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error );
            var dataErrorInfo2 = new DataErrorInfo ( "SomeErrorMessage2", ErrorLevel.Error );
            personDto.AddDataErrorInfo ( dataErrorInfo1 );
            personDto.AddDataErrorInfo ( dataErrorInfo2 );

            personDto.RemoveDataErrorInfo ( "" );

            Assert.IsTrue ( personDto.DataErrorInfoCollection.Count() == 0 );
        }
예제 #27
0
        public void GetErrors_WithAPropertyNameButOnlyAnObjectLevelErrorExists_ReturnAnEmptyList()
        {
            var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" };
            DataErrorInfo dataErrorInfo = new DataErrorInfo ( "Error", ErrorLevel.Error );
            personDto.AddDataErrorInfo ( dataErrorInfo );

            IEnumerable<DataErrorInfo> errors = personDto.GetErrors ( "FirstName" ) as IEnumerable<DataErrorInfo>;
            IList<DataErrorInfo> errorList = new List<DataErrorInfo> ( errors );

            Assert.IsTrue ( errorList.Count() == 0 );
        }
예제 #28
0
        public void RemoveDataErrorInfo_OnePropertyLevelError_RemovesPropertyLevelError()
        {
            var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error, "FirstName" );
            personDto.AddDataErrorInfo ( dataErrorInfo );

            personDto.RemoveDataErrorInfo ( "FirstName" );

            Assert.IsTrue ( personDto.DataErrorInfoCollection.Count() == 0 );
        }
예제 #29
0
        public void RemoveDataErrorInfo_RemovingAPropertyLevelError_ErrorsChangedEventShouldFire()
        {
            var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "EntityLevelError", ErrorLevel.Error, "FirstName" );
            string propertyName = "Dummy";

            personDto.AddDataErrorInfo ( dataErrorInfo );
            personDto.ErrorsChanged += ( s, e ) => { propertyName = e.PropertyName; };
            personDto.RemoveDataErrorInfo ( "FirstName" );

            Assert.AreEqual ( propertyName, "FirstName" );
        }
예제 #30
0
        public void RemoveDataErrorInfo_PropertyLevelErrorAndCrossPropertyLevelError_RemovesAllErrorsWithSamePropertyName()
        {
            var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo1 = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error, "FirstName" );
            var dataErrorInfo2 = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error, "FirstName", "LastName" );
            var dataErrorInfo3 = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error, "LastName" );
            personDto.AddDataErrorInfo ( dataErrorInfo1 );
            personDto.AddDataErrorInfo ( dataErrorInfo2 );
            personDto.AddDataErrorInfo ( dataErrorInfo3 );

            personDto.RemoveDataErrorInfo ( "FirstName" );

            IList referenceCollection = new ArrayList { dataErrorInfo3 };

            CollectionAssert.AreEqual ( referenceCollection, personDto.DataErrorInfoCollection.ToList () );
        }
예제 #31
0
        public void RemoveDataErrorInfo_ProvidedAnEmptyProperty_RemovesObjectLevelErrors()
        {
            var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "SomeErrorMessage", ErrorLevel.Error );
            personDto.AddDataErrorInfo ( dataErrorInfo );

            personDto.RemoveDataErrorInfo ( "" );

            Assert.IsTrue ( personDto.DataErrorInfoCollection.Count() == 0 );
        }
예제 #32
0
        public void RemoveDataErrorInfo_ProvidedANonExistentProperty_ThrowAPropertyNotFoundException()
        {
            var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "SomeErrorMessage", ErrorLevel.Error );
            personDto.AddDataErrorInfo ( dataErrorInfo );

            personDto.RemoveDataErrorInfo ( "Foo" );

            Assert.IsTrue ( personDto.DataErrorInfoCollection.Count() == 0 );
        }
예제 #33
0
        public void AddDataErrorInfo_AddingAnObjectLevelError_GetErrorsShouldReturnGivenError()
        {
            var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" };
            var dataErrorInfo = new DataErrorInfo ( "EntityLevelError", ErrorLevel.Error );
            IEnumerable<DataErrorInfo> errors = new List<DataErrorInfo> ();

            personDto.ErrorsChanged +=
                ( s, e ) => { errors = personDto.GetErrors ( e.PropertyName ) as IEnumerable<DataErrorInfo>; };

            personDto.AddDataErrorInfo ( dataErrorInfo );

            List<DataErrorInfo> returnedList = new List<DataErrorInfo> ( errors );
            List<DataErrorInfo> referenceList = new List<DataErrorInfo> { dataErrorInfo };

            CollectionAssert.AreEqual ( returnedList, referenceList );
        }
 /// <summary>
 /// Tries the add data error info.
 /// </summary>
 /// <param name="dataErrorInfo">The data error info.</param>
 public void TryAddDataErrorInfo ( DataErrorInfo dataErrorInfo )
 {
     if ( !DataErrorInfoCollection.Contains ( dataErrorInfo ) )
     {
         AddDataErrorInfo ( dataErrorInfo );
     }
 }