1 /* System.Collections.Specialized.StringCollection.cs
\r
3 * John Barnette (jbarn@httcb.net)
\r
5 * Copyright (C) 2001 John Barnette
\r
8 using NUnit.Framework;
\r
10 namespace System.Collections.Specialized {
\r
11 public class StringCollectionTest : TestCase {
\r
12 private StringCollection sc;
\r
13 string[] strings = {
\r
23 public StringCollectionTest(string name) : base(name) {}
\r
25 protected override void SetUp() {
\r
26 sc = new StringCollection();
\r
27 sc.AddRange(strings);
\r
32 public void TestSimpleCount() {
\r
33 Assert(sc.Count == 7);
\r
36 public void TestSimpleIsFixedSize() {
\r
37 Assert(!sc.IsFixedSize);
\r
40 public void TestSimpleIsReadOnly() {
\r
41 Assert(!sc.IsReadOnly);
\r
44 public void TestSimpleIsSynchronized() {
\r
45 Assert(!sc.IsSynchronized);
\r
48 public void TestSimpleItemGet() {
\r
49 for(int i = 0; i < strings.Length; i++) {
\r
50 Assert(strings[i].Equals(sc[i]));
\r
54 public void TestSimpleItemSet() {
\r
56 Assert(sc[0].Equals("bob"));
\r
59 public void TestSimpleSyncRoot() {
\r
60 Assert(sc.Equals(sc.SyncRoot));
\r
63 public void TestSimpleAdd() {
\r
64 int index = sc.Add("chuck");
\r
65 Assert(index == strings.Length);
\r
66 Assert(sc[strings.Length].Equals("chuck"));
\r
70 public void TestSimpleAddRange() {
\r
71 string[] newStrings = {
\r
77 int index = sc.Count;
\r
78 sc.AddRange(newStrings);
\r
80 Assert(sc.Count == index + newStrings.Length);
\r
82 for (int i = 0; i+index <= sc.Count-1; i++) {
\r
83 Assert(newStrings[i].Equals(sc[i+index]));
\r
87 public void TestSimpleClear() {
\r
89 Assert(sc.Count == 0);
\r
92 public void TestSimpleContains() {
\r
93 Assert(sc.Contains(strings[0]));
\r
94 Assert(!sc.Contains("NOT CONTAINED"));
\r
97 public void TestSimpleCopyTo() {
\r
98 string[] copyArray = new string[sc.Count];
\r
99 sc.CopyTo(copyArray, 0);
\r
100 for (int i = 0; i < copyArray.Length; i++) {
\r
101 Assert(copyArray[i] == sc[i]);
\r
105 public void TestSimpleGetEnumerator() {
\r
107 foreach(string s in sc) {
\r
108 Assert(s.Equals(strings[index]));
\r
113 public void TestSimpleIndexOf() {
\r
114 Assert(sc.IndexOf(strings[0]) == 0);
\r
117 public void TestSimpleInsert() {
\r
119 int oldCount = sc.Count;
\r
120 string before = sc[index - 1];
\r
121 string current = sc[index];
\r
122 string after = sc[index + 1];
\r
123 string newStr = "paco";
\r
125 sc.Insert(index, newStr);
\r
127 Assert(sc.Count == oldCount + 1);
\r
128 Assert(sc[index].Equals(newStr));
\r
129 Assert(sc[index-1].Equals(before));
\r
130 Assert(sc[index+1].Equals(current));
\r
131 Assert(sc[index+2].Equals(after));
\r
134 public void TestSimpleRemove() {
\r
135 int oldCount = sc.Count;
\r
136 sc.Remove(strings[0]);
\r
137 Assert(oldCount == sc.Count + 1);
\r
138 Assert(!sc.Contains(strings[0]));
\r
141 public void TestSimpleRemoveAt() {
\r
143 int oldCount = sc.Count;
\r
144 string after = sc[index+1];
\r
146 sc.RemoveAt(index);
\r
147 Assert(oldCount == sc.Count + 1);
\r
148 Assert(sc[index].Equals(after));
\r