public void Index() { FieldFormatterCollection fieldFormatters = new FieldFormatterCollection(); // Add field Formatters. for (int i = 0; i < _fieldFormatters.Length; i++) { fieldFormatters.Add(_fieldFormatters[i]); } // Check valid field formatters. for (int i = 0; i < _exists.Length; i++) { Assert.IsNotNull(fieldFormatters[_exists[i]]); Assert.IsTrue(fieldFormatters.Contains(_exists[i])); } // Check invalid field formatters. for (int i = 0; i < _notExists.Length; i++) { Assert.IsNull(fieldFormatters[_notExists[i]]); Assert.IsFalse(fieldFormatters.Contains(_notExists[i])); } Assert.IsTrue(fieldFormatters.MaximumFieldFormatterNumber == 64); Assert.IsTrue(fieldFormatters.Count == _fieldFormatters.Length); }
public void AddField() { FieldFormatterCollection fieldFormatters = new FieldFormatterCollection(); fieldFormatters.Added += new FieldFormatterAddedEventHandler( OnFieldFormattersAdded); _removedEventArgs = null; fieldFormatters.Removed += new FieldFormatterRemovedEventHandler( OnFieldFormattersRemoved); // Add field formatters. for (int i = _fieldFormatters.Length - 1; i >= 0; i--) { _addedEventArgs = null; fieldFormatters.Add(( FieldFormatter)(_fieldFormatters[i])); Assert.IsNull(_removedEventArgs); Assert.IsNotNull(_addedEventArgs); Assert.IsTrue(_addedEventArgs.FieldFormatter == ( FieldFormatter)(_fieldFormatters[i])); } // Check valid field formatters. for (int i = 0; i < _exists.Length; i++) { Assert.IsNotNull(fieldFormatters[_exists[i]]); Assert.IsTrue(fieldFormatters.Contains(_exists[i])); } // Check invalid field formatters. for (int i = 0; i < _notExists.Length; i++) { Assert.IsNull(fieldFormatters[_notExists[i]]); Assert.IsFalse(fieldFormatters.Contains(_notExists[i])); } Assert.IsTrue(fieldFormatters.MaximumFieldFormatterNumber == 64); Assert.IsTrue(fieldFormatters.Count == _fieldFormatters.Length); // Substitute one field formatter. FieldFormatter toReplace = fieldFormatters[_exists[0]]; FieldFormatter toAdd = new StringFieldFormatter(_exists[0], new FixedLengthManager(20), StringEncoder.GetInstance()); _addedEventArgs = null; fieldFormatters.Add(toAdd); Assert.IsNotNull(_removedEventArgs); Assert.IsNotNull(_addedEventArgs); Assert.IsTrue(_addedEventArgs.FieldFormatter == toAdd); Assert.IsTrue(_removedEventArgs.FieldFormatter == toReplace); }
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 ContainsOne() { FieldFormatterCollection fieldFormatters = new FieldFormatterCollection(); // Add field formatters. for (int i = _fieldFormatters.Length - 1; i >= 0; i--) { fieldFormatters.Add(( FieldFormatter)(_fieldFormatters[i])); } // Check valid field formatters. for (int i = 0; i < _exists.Length; i++) { Assert.IsTrue(fieldFormatters.Contains(_exists[i])); } // Check invalid field formatters. for (int i = 0; i < _notExists.Length; i++) { Assert.IsFalse(fieldFormatters.Contains(_notExists[i])); } }
public void ContainsMany() { FieldFormatterCollection fieldFormatters = new FieldFormatterCollection(); // Add field formatters. for (int i = _fieldFormatters.Length - 1; i >= 0; i--) { fieldFormatters.Add(( FieldFormatter)(_fieldFormatters[i])); } Assert.IsTrue(fieldFormatters.Contains(_exists)); Assert.IsFalse(fieldFormatters.Contains(_notExists)); int[] more = new int[4]; more[0] = _exists[0]; more[1] = _notExists[0]; more[2] = _exists[1]; more[3] = _notExists[1]; Assert.IsFalse(fieldFormatters.Contains(more)); more[0] = _exists[0]; more[1] = _exists[1]; more[2] = _exists[2]; more[3] = _exists[3]; Assert.IsTrue(fieldFormatters.Contains(more)); }
public void Enumeration() { FieldFormatterCollection fieldFormatters = new FieldFormatterCollection(); FieldFormatterCollection copy = new FieldFormatterCollection(); // Add field formatters. for (int i = _fieldFormatters.Length - 1; i >= 0; i--) { fieldFormatters.Add(( FieldFormatter)(_fieldFormatters[i])); } // Copy collection. foreach (FieldFormatter fieldFormatter in fieldFormatters) { copy.Add(fieldFormatter); } // Check valid field formatters. for (int i = 0; i < _exists.Length; i++) { Assert.IsNotNull(copy[_exists[i]]); Assert.IsTrue(copy.Contains(_exists[i])); } }
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]); }