public void ShouldAppendLinks() { // Given var chain = new Chain <string>("base"); // When chain.Append("1"); chain.Append("2"); chain.Append("3"); // Then chain.Current.ShouldBe("3"); }
public void ShouldRemoveLinks() { // Given var chain = new Chain <string>("base"); var token1 = chain.Append("1"); var token2 = chain.Append("2"); var token3 = chain.Append("3"); // When token3.Dispose(); chain.Current.ShouldBe("2"); token2.Dispose(); chain.Current.ShouldBe("1"); token1.Dispose(); chain.Current.ShouldBe("base"); token1.Dispose(); // Then }
public void ShouldRemoveLink() { // Given var chain = new Chain <string>("base"); var token = chain.Append("1"); // When token.Dispose(); // Then chain.Current.ShouldBe("base"); }
public void AppendEmptyTest() { const int v1 = 42; const int v2 = 43; var o = new Chain<int>(v1, v2); Assert.AreEqual(2, o.Count()); var o2 = o.Append(Chain<int>.Empty); Assert.AreSame(o, o2); var o3 = o.Append(new Chain<int>()); Assert.AreSame(o, o3); var o4 = Chain<int>.Empty.Append(o); Assert.AreSame(o, o4); var o5 = new Chain<int>().Append(o); Assert.AreSame(o, o5); }
public void AppendTest() { const int v1 = 42; const int v2 = 43; const int v3 = 44; var v = new[] { v1, v2, v3 }; var o = new Chain<int>(v1); Assert.AreEqual(1, o.Count()); o = o.Append(v2); Assert.AreEqual(2, o.Count()); o = o.Append(v3); Assert.AreEqual(3, o.Count()); Assert.AreEqual(o.Head, v1); Assert.AreEqual(o.Tail.Head, v2); Assert.AreEqual(o.Tail.Tail.Head, v3); Assert.IsTrue(v.Zip(o, (a, b) => a == b).All(p => p)); }