예제 #1
0
        public void AsEnumerable()
        {
            var reflectedObject = new ReflectedObject ("string");
              var output = new StringBuilder (6);

              foreach (var character in reflectedObject.AsEnumerable<char>())
            output.Append (character);

              Assert.That (output.ToString(), Is.EqualTo ("string"));
        }
예제 #2
0
        public void AsEnumerable()
        {
            var reflectedObject = new ReflectedObject("string");
            var output          = new StringBuilder(6);

            foreach (var character in reflectedObject.AsEnumerable <char>())
            {
                output.Append(character);
            }

            Assert.That(output.ToString(), Is.EqualTo("string"));
        }
예제 #3
0
        public void AsEnumerable_NonEnumerable()
        {
            var reflectedObject = new ReflectedObject(42);

            try
            {
                reflectedObject.AsEnumerable <object>().GetEnumerator().MoveNext();
                Assert.Fail("expected exception not thrown");
            }
            catch (NotSupportedException notSupportedException)
            {
                Assert.That(notSupportedException.Message, Is.EqualTo("The reflected object 'System.Int32' is not enumerable."));
            }
        }
예제 #4
0
        public void AsEnumerable_NonEnumerable()
        {
            var reflectedObject = new ReflectedObject (42);

              try
              {
            reflectedObject.AsEnumerable<object>().GetEnumerator().MoveNext();
            Assert.Fail ("expected exception not thrown");
              }
              catch (NotSupportedException notSupportedException)
              {
            Assert.That (notSupportedException.Message, Is.EqualTo ("The reflected object 'System.Int32' is not enumerable."));
              }
        }
예제 #5
0
        public void AsEnumerable_EnumerableButWrongType()
        {
            var reflectedObject = new ReflectedObject("string");

            try
            {
                // 'char' is convertible to 'int'!
                reflectedObject.AsEnumerable <float>().GetEnumerator().MoveNext();
                Assert.Fail("expected exception not thrown");
            }
            catch (InvalidCastException notSupportedException)
            {
                Assert.That(notSupportedException.Message, Is.EqualTo("Specified cast is not valid."));
            }
        }
예제 #6
0
        public void AsEnumerable_EnumerableButWrongType()
        {
            var reflectedObject = new ReflectedObject ("string");

              try
              {
            // 'char' is convertible to 'int'!
            reflectedObject.AsEnumerable<float>().GetEnumerator().MoveNext();
            Assert.Fail ("expected exception not thrown");
              }
              catch (InvalidCastException notSupportedException)
              {
            Assert.That (notSupportedException.Message, Is.EqualTo ("Specified cast is not valid."));
              }
        }