using System; using System.Collections.Generic; using Developpez.Dotnet.Collections; using NUnit.Framework; namespace Developpez.Dotnet.Tests.Collections { [TestFixture] public class ImmutableListTests { [Test] public void Test_ImmutableList() { var expected = ImmutableList.Create("zoo", "bar", "foo"); var input = ImmutableList.Create("foo", "bar", "baz"); var inputSave = input.AsImmutable(); var actual = input .Add("foo") .RemoveAt(0) .Replace(0, "zoo") .Insert(1, "bar") .Remove("baz"); Assert.AreEqual(inputSave, input, "Input collection was modified"); Assert.AreEqual(expected, actual); } public void Test_CantModifyList() { IList list = ImmutableList.Create("foo", "bar", "baz"); var actions = new TestDelegate[] { () => list.Add("foo"), () => list.Clear(), () => list.Insert(1, "foo"), () => list.Remove("foo"), () => list.RemoveAt(0), () => list[0] = "foo" }; foreach (var action in actions) { Assert.Throws(action); } } } }