예제 #1
0
        public void ElementAtOrDefault_With_OutOfRange_Must_ReturnDefault(int[] source, int index)
        {
            // Arrange
            var wrapped = Wrap.AsValueReadOnlyList(source);

            // Act
            var result = ReadOnlyList.ElementAtOrDefault <Wrap.ValueReadOnlyList <int>, int>(wrapped, index);

            // Assert
            _ = result.Must()
                .BeEqualTo(default);
예제 #2
0
        public void List_ElementAtOrDefault()
        {
            var list = new int[0];

            Assert.AreEqual(0, ReadOnlyList.ElementAtOrDefault(list, 3));
            list = new int[] { 3 };
            Assert.AreEqual(3, ReadOnlyList.ElementAtOrDefault(list, 0));
            Assert.AreEqual(0, ReadOnlyList.ElementAtOrDefault(list, 1));
            list = new int[] { 9, 3, 1 };
            Assert.AreEqual(1, ReadOnlyList.ElementAtOrDefault(list, 2));
            var list2 = new string[] { };

            Assert.AreEqual((string)null, ReadOnlyList.ElementAtOrDefault(list2, 0));
            list2 = new string[] { "one" };
            Assert.AreEqual("one", ReadOnlyList.ElementAtOrDefault(list2, 0));
            list2 = new string[] { "three", "two", "one" };
            Assert.AreEqual("two", ReadOnlyList.ElementAtOrDefault(list2, 1));
            Assert.AreEqual((string)null, ReadOnlyList.ElementAtOrDefault(list2, 3));
        }