public void AddRange_Null_ThrowsArgumentNullException() { var collection = new CodeNamespaceImportCollection(); AssertExtensions.Throws <ArgumentNullException>("value", () => collection.AddRange(null)); AssertExtensions.Throws <ArgumentNullException>("value", () => collection.AddRange(null)); }
// CodeNamespaceImportCollection public void CodeNamespaceImportCollectionExample() { //<Snippet3> //<Snippet4> // Creates an empty CodeNamespaceImportCollection. CodeNamespaceImportCollection collection = new CodeNamespaceImportCollection(); //</Snippet4> //<Snippet5> // Adds a CodeNamespaceImport to the collection. collection.Add(new CodeNamespaceImport("System")); //</Snippet5> //<Snippet6> // Adds an array of CodeNamespaceImport objects to the collection. CodeNamespaceImport[] Imports = { new CodeNamespaceImport("System"), new CodeNamespaceImport("System.Drawing") }; collection.AddRange(Imports); //</Snippet6> //<Snippet7> // Retrieves the count of the items in the collection. int collectionCount = collection.Count; //</Snippet7> //</Snippet3> }
/// <summary> /// Visits a <see cref="CodeNamespaceImportCollection"/>. /// </summary> /// <param name="codeNamespaceImportCollection">The <see cref="CodeNamespaceImportCollection"/> to visit.</param> protected override void VisitCodeNamespaceImportCollection(CodeNamespaceImportCollection codeNamespaceImportCollection) { CodeNamespaceImport[] sortedImports = codeNamespaceImportCollection.Cast <CodeNamespaceImport>().OrderBy(i => i.Namespace, new NamespaceImportComparer()).Distinct().ToArray(); codeNamespaceImportCollection.Clear(); codeNamespaceImportCollection.AddRange(sortedImports); base.VisitCodeNamespaceImportCollection(codeNamespaceImportCollection); }
public void AddRange_CodeNamespaceArray_Works(CodeNamespaceImport[] value) { var collection = new CodeNamespaceImportCollection(); collection.AddRange(value); Assert.Equal(value.Length, collection.Count); for (int i = 0; i < value.Length; i++) { Assert.Same(value[i], collection[i]); } }
public void Constructor0_Deny_Unrestricted() { CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection(); coll.Add(cni); Assert.AreSame(cni, coll[0], "this[int]"); coll[0] = cni; coll.Clear(); coll.AddRange(array); Assert.IsNotNull(coll.GetEnumerator(), "GetEnumerator"); }
public void AddRange_CodeNamespaceArray_Works(CodeNamespaceImport[] value) { var collection = new CodeNamespaceImportCollection(); collection.AddRange(value); Assert.Equal(value.Length, collection.Count); for (int i = 0; i < value.Length; i++) { Assert.Same(value[i], collection[i]); } }
public void AddRange() { CodeNamespaceImport ni1 = new CodeNamespaceImport("A"); CodeNamespaceImport ni2 = new CodeNamespaceImport("B"); CodeNamespaceImport ni3 = new CodeNamespaceImport("b"); CodeNamespaceImport ni4 = new CodeNamespaceImport("B"); CodeNamespaceImport ni5 = new CodeNamespaceImport("C"); CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection(); coll.AddRange(new CodeNamespaceImport[] { ni1, ni2 }); Assert.AreEqual(2, coll.Count, "#1"); Assert.AreEqual(0, ((IList)coll).IndexOf(ni1), "#2"); Assert.AreEqual(1, ((IList)coll).IndexOf(ni2), "#3"); coll.AddRange(new CodeNamespaceImport[] { ni3, ni4, ni5 }); Assert.AreEqual(3, coll.Count, "#4"); Assert.AreEqual(0, ((IList)coll).IndexOf(ni1), "#5"); Assert.AreEqual(1, ((IList)coll).IndexOf(ni2), "#6"); Assert.AreEqual(-1, ((IList)coll).IndexOf(ni3), "#7"); Assert.AreEqual(-1, ((IList)coll).IndexOf(ni4), "#8"); Assert.AreEqual(2, ((IList)coll).IndexOf(ni5), "#9"); }
public void AddRange_NullObjectInValue_ThrowsNullReferenceException() { var collection = new CodeNamespaceImportCollection(); Assert.Throws<NullReferenceException>(() => collection.AddRange(new CodeNamespaceImport[] { null })); }
public void AddRange_Null_ThrowsArgumentNullException() { var collection = new CodeNamespaceImportCollection(); Assert.Throws<ArgumentNullException>("value", () => collection.AddRange(null)); Assert.Throws<ArgumentNullException>("value", () => collection.AddRange(null)); }
public void AddRange_NullObjectInValue_ThrowsNullReferenceException() { var collection = new CodeNamespaceImportCollection(); Assert.Throws <NullReferenceException>(() => collection.AddRange(new CodeNamespaceImport[] { null })); }
public void AddRange_Null_Item() { CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection(); coll.AddRange(new CodeNamespaceImport[] { null }); }
public void AddRange_Null_Array() { CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection(); coll.AddRange((CodeNamespaceImport[])null); }