public void ShouldBeAbleToRemoveAnElementFromImmutableCollection() { var elements = new List <string> { "Element1", "Element2" }; IImmutableCollection <String> immutableCollection = new ImmutableCollection <String>(elements); IImmutableCollection <String> newImmutableCollection = immutableCollection.Remove("Element1"); Assert.Equals(2, immutableCollection.Size()); Assert.Equals(1, newImmutableCollection.Size()); }
public void ShouldAddNewElementToImmutableCollection() { var elements = new List <string> { "Element1", "Element2" }; IImmutableCollection <String> immutableCollection = new ImmutableCollection <String>(elements); IImmutableCollection <String> newImmutableCollection = immutableCollection.Add("newElement"); Assert.Equals(2, immutableCollection.Size()); Assert.Equals(3, newImmutableCollection.Size()); }
public TCollection CreateCollection <TCollection, TValue>(IEnumerable <TValue> values) where TCollection : IImmutableCollection <TValue> { IImmutableCollection <TValue> colleciton = Activator.CreateInstance <TCollection>(); return((TCollection)values.Aggregate(colleciton, (current, value) => current.Add(value))); }