Ejemplo n.º 1
0
        public static T Column <T>(this FakeDataReader reader, int i)
        {
            if (reader is null)
            {
                throw new ArgumentException(nameof(reader));
            }

            return(_extractor.Extract <T>(reader.GetValue(i)));
        }
Ejemplo n.º 2
0
        public void Extract_Int32_Throws_On_DBNull()
        {
            // Arrange

            // Act
            TestDelegate test = () => _extractor.Extract <int>(DBNull.Value);

            // Assert
            Assert.That(test, Throws.TypeOf <InvalidCastException>());
        }
Ejemplo n.º 3
0
        public void Extract_Int32_Unboxes(object input)
        {
            // Arrange

            // Act
            int result = _extractor.Extract <int>(input);

            // Assert
            Assert.That(result, Is.EqualTo(input));
        }
        public void Extract_Int32_Unwraps(int input)
        {
            // Arrange
            WrappedInt32 value = new WrappedInt32(input);

            // Act
            int result = _extractor.Extract <int>(value);

            // Assert
            Assert.That(result, Is.EqualTo(input));
        }
Ejemplo n.º 5
0
        public void Unbox_DataReader_Columns_with_Custom_Handlers(object input)
        {
            // Arrange
            ValueExtractor extractor = ValueExtractor.Create(config =>
            {
                config.UseHandler <bool>(
                    (obj, ctx) =>
                {
                    if (obj is bool b)
                    {
                        ctx.Result = b;
                        return;
                    }

                    if (obj is string s)
                    {
                        ctx.Result = s == "Y";
                        return;
                    }
                });
            });

            // Act
            bool result = extractor.Extract <bool>(input);

            // Assert
        }
Ejemplo n.º 6
0
        public void ContextualHandler_Throws_InvalidCastException_If_No_Result_Assigned()
        {
            // Arrange
            ValueExtractor extractor = ValueExtractor.Create(config =>
            {
                config.UseHandler <string>(
                    (obj, ctx) =>
                {
                });
            });

            // Act
            TestDelegate test = () => extractor.Extract <string>("");

            // Assert
            Assert.That(test, Throws.TypeOf <InvalidCastException>());
        }
Ejemplo n.º 7
0
 internal virtual object Extract(object o)
 {
     return(ValueExtractor.Extract(o));
 }