예제 #1
0
        public void ForEach_throws_ArgumentNullException()
        {
            IEnumerable enumeration = new[] { "a", "b", "c" };

            void action(object _)
            {
            }

            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.ForEach((IEnumerable)null, action));
            Assert.Throws <ArgumentNullException>(() => IEnumerableExtensions.ForEach(enumeration, (Action <object>)null));
        }
예제 #2
0
 public void Foreach_source_null_NullReferenceException()
 {
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <short>(null, _ => { }));
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <int>(null, _ => { }));
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <long>(null, _ => { }));
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <bool>(null, _ => { }));
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <byte>(null, _ => { }));
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <DateTime>(null, _ => { }));
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <TimeSpan>(null, _ => { }));
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <float>(null, _ => { }));
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <double>(null, _ => { }));
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <string>(null, _ => { }));
     Assert.Throws <NullReferenceException>(() => IEnumerableExtensions.ForEach <List <int> >(null, _ => { }));
 }
        public void FluentForEach()
        {
            IEnumerable <dataClass> theOriginalData = new List <dataClass> {
                new dataClass()
                {
                    Name = "a"
                }, new dataClass()
                {
                    Name = "b"
                }, new dataClass()
                {
                    Name = "c"
                }
            };
            IEnumerable <dataClass> thechangedData = IEnumerableExtensions.ForEach <dataClass>(theOriginalData, delegate(dataClass obj) { obj.Name = "New Name"; });

            foreach (dataClass dc in thechangedData)
            {
                Assert.AreEqual("New Name", dc.Name);
            }
        }