コード例 #1
0
        public void WhenListWithRepeatedIntegerValuesThenDistinctShouldReturnListWithSameCount()
        {
            List <Foo> sourceList = new List <Foo>();

            sourceList.Add(new Foo()
            {
                IntProp = 42, StringProp = "First String"
            });
            sourceList.Add(new Foo()
            {
                IntProp = 42, StringProp = "Second String"
            });
            sourceList.Add(new Foo()
            {
                IntProp = 42, StringProp = "Second String"
            });

            sourceList.Add(new Foo()
            {
                IntProp = 41, StringProp = "Third String"
            });
            sourceList.Add(new Foo()
            {
                IntProp = 40, StringProp = "Fourth String"
            });


            var distinctEnumerable = IEnumerableUtil.DistinctBy(sourceList, f => f.IntProp);

            Assert.AreEqual(3, distinctEnumerable.Count());
        }
コード例 #2
0
        public void WhenNullListThenDistinctShouldThrowArgumentNullException()
        {
            List <Foo> sourceList = null;

            Assert.ThrowsException <ArgumentNullException>(() => { IEnumerableUtil.DistinctBy(sourceList, f => f.IntProp).ToList(); });
        }