public void TryLast_WherePredicateMatchesNoItems_ReturnsNoValue() { IEnumerable<string> source = new[] { "Foo", "Baz", "Boo", "Quix" }; var result = source.TryLast(x => false); Assert.IsFalse(result.HasValue); }
public void TryLast_WherePredicateMatchesItem_ReturnsLastMatchingItem() { IEnumerable<string> source = new[] { "Foo", "Baz", "Boo", "Quix" }; var result = source.TryLast(x => x.StartsWith("B")); Assert.IsTrue(result.HasValue); Assert.AreEqual("Boo", result.Value); }
public void TryLast_WithManyItems_ReturnsLastItem() { IEnumerable<int> source = new[] { 42, 84, 168 }; var result = source.TryLast(); Assert.IsTrue(result.HasValue); Assert.AreEqual(168, result.Value); result = source.TryLast(x => true); Assert.IsTrue(result.HasValue); Assert.AreEqual(168, result.Value); }
public void TryLast_WithLastItemNull_ReturnsNoValue() { IEnumerable<string> source = new[] { "Foo", "Baz", null }; var result = source.TryLast(); Assert.IsFalse(result.HasValue); result = source.TryLast(x => true); Assert.IsFalse(result.HasValue); }
public void TryLast_WithOneItem_ReturnsItem() { IEnumerable<int> source = new[] { 42 }; var result = source.TryLast(); Assert.IsTrue(result.HasValue); Assert.AreEqual(42, result.Value); result = source.TryLast(x => true); Assert.IsTrue(result.HasValue); Assert.AreEqual(42, result.Value); }