public void RemoveOne() { FieldFormatterCollection fieldFormatters = new FieldFormatterCollection(); fieldFormatters.Removed += new FieldFormatterRemovedEventHandler( OnFieldFormattersRemoved); // Add field formatters. for (int i = _fieldFormatters.Length - 1; i >= 0; i--) { fieldFormatters.Add(( FieldFormatter)(_fieldFormatters[i])); } // Remove. for (int i = 0; i < _exists.Length; i++) { Assert.IsNotNull(fieldFormatters[_exists[i]]); Assert.IsTrue(fieldFormatters.Contains(_exists[i])); Assert.IsNull(fieldFormatters[_notExists[i]]); Assert.IsFalse(fieldFormatters.Contains(_notExists[i])); _removedEventArgs = null; FieldFormatter fieldFormatter = fieldFormatters[_exists[i]]; fieldFormatters.Remove(_exists[i]); Assert.IsNotNull(_removedEventArgs); Assert.IsTrue(_removedEventArgs.FieldFormatter == fieldFormatter); _removedEventArgs = null; fieldFormatters.Remove(_notExists[i]); Assert.IsNull(_removedEventArgs); Assert.IsNull(fieldFormatters[_exists[i]]); Assert.IsFalse(fieldFormatters.Contains(_exists[i])); Assert.IsNull(fieldFormatters[_notExists[i]]); Assert.IsFalse(fieldFormatters.Contains(_notExists[i])); if (i < _maximum.Length) { Assert.IsTrue(fieldFormatters.MaximumFieldFormatterNumber == _maximum[i]); } else { try { int max = fieldFormatters.MaximumFieldFormatterNumber; Assert.Fail(); } catch (ApplicationException) { } } } }
public void RemoveMany() { FieldFormatterCollection fieldFormatters = new FieldFormatterCollection(); // Add field formatters. for (int i = _fieldFormatters.Length - 1; i >= 0; i--) { fieldFormatters.Add(( FieldFormatter)(_fieldFormatters[i])); } // Remove all. Assert.IsTrue(fieldFormatters.Count == _fieldFormatters.Length); fieldFormatters.Remove(_notExists); Assert.IsTrue(fieldFormatters.Count == _fieldFormatters.Length); fieldFormatters.Remove(_exists); Assert.IsTrue(fieldFormatters.Count == 0); // Add field formatters again. for (int i = _fieldFormatters.Length - 1; i >= 0; i--) { fieldFormatters.Add(( FieldFormatter)(_fieldFormatters[i])); } // Remove. int[] fieldsToRemove = new int[4]; for (int i = 0; i < _exists.Length; i += 2) { if ((i + 1) >= _exists.Length) { break; } fieldsToRemove[0] = _exists[i]; fieldsToRemove[1] = _notExists[i]; fieldsToRemove[2] = _exists[i + 1]; fieldsToRemove[3] = _notExists[i + 1]; Assert.IsNotNull(fieldFormatters[_exists[i]]); Assert.IsTrue(fieldFormatters.Contains(_exists[i])); Assert.IsNull(fieldFormatters[_notExists[i]]); Assert.IsFalse(fieldFormatters.Contains(_notExists[i])); Assert.IsNotNull(fieldFormatters[_exists[i + 1]]); Assert.IsTrue(fieldFormatters.Contains(_exists[i + 1])); Assert.IsNull(fieldFormatters[_notExists[i + 1]]); Assert.IsFalse(fieldFormatters.Contains(_notExists[i + 1])); fieldFormatters.Remove(fieldsToRemove); Assert.IsNull(fieldFormatters[_exists[i]]); Assert.IsFalse(fieldFormatters.Contains(_exists[i])); Assert.IsNull(fieldFormatters[_notExists[i]]); Assert.IsFalse(fieldFormatters.Contains(_notExists[i])); Assert.IsNull(fieldFormatters[_exists[i + 1]]); Assert.IsFalse(fieldFormatters.Contains(_exists[i + 1])); Assert.IsNull(fieldFormatters[_notExists[i + 1]]); Assert.IsFalse(fieldFormatters.Contains(_notExists[i + 1])); Assert.IsTrue(fieldFormatters.MaximumFieldFormatterNumber == _maximum[i + 1]); } Assert.IsTrue(fieldFormatters.Count == 1); Assert.IsTrue(fieldFormatters.MaximumFieldFormatterNumber == _maximum[_maximum.Length - 1]); }