Exemplo n.º 1
0
        /// <summary>
        ///   Constructs a new <see cref="PrimitiveExtractionStep"/>.
        /// </summary>
        /// <param name="extractor">
        ///   The <see cref="IFieldExtractor"/> defining how the primitive value is to be obtained.
        /// </param>
        /// <param name="converter">
        ///   A <see cref="DataConverter"/> defining how to transform the primitive value extracted according to
        ///   <paramref name="extractor"/>. If no transformation is desired, an
        ///   <see cref="DataConverter.Identity{T}">identity conversion</see> should be provided.
        /// </param>
        /// <pre>
        ///   The <see cref="DataConverter.SourceType">SourceType</see> of <paramref name="converter"/> is the same as
        ///   the <see cref="IFieldExtractor.FieldType">FieldType</see> of <paramref name="extractor"/>, or is a base
        ///   class or interface thereof
        ///     --and--
        ///   The <see cref="IFieldExtractor.FieldType">FieldType</see> of <paramref name="extractor"/> is a data type
        ///   supported by the Framework.
        /// </pre>
        public PrimitiveExtractionStep(IFieldExtractor extractor, DataConverter converter)
        {
            Guard.Against.Null(extractor, nameof(extractor));
            Guard.Against.Null(converter, nameof(converter));
            Debug.Assert(extractor.FieldType.IsInstanceOf(converter.SourceType));
            Debug.Assert(DBType.IsSupported(converter.SourceType));

            extractor_     = extractor;
            converter_     = converter;
            ExpectedSource = extractor_.ExpectedSource;
        }
        /// <summary>
        ///   Constructs a new <see cref="DecomposingExtractionStep"/>.
        /// </summary>
        /// <param name="extractor">
        ///   The <see cref="IFieldExtractor"/> defining how the primitive value is to be obtained.
        /// </param>
        /// <param name="decomposition">
        ///   The steps defining how to decompose the value produced by <paramref name="extractor"/>.
        /// </param>
        /// <pre>
        ///  <paramref name="decomposition"/> is not empty
        ///    --and--
        ///   The <see cref="IExtractionStep.ExpectedSource">ExpectedSource</see> of each element of
        ///   <paramref name="decomposition"/> is the same as the <see cref="IFieldExtractor.FieldType">FieldType</see>
        ///   of <paramref name="extractor"/>, or is a base class or interface thereof
        ///     --and--
        ///   The <see cref="IFieldExtractor.FieldType">FieldType</see> of <paramref name="extractor"/> is a data type
        ///   not supported by the Framework.
        /// </pre>
        public DecomposingExtractionStep(IFieldExtractor extractor, IEnumerable <IExtractionStep> decomposition)
        {
            Guard.Against.Null(extractor, nameof(extractor));
            Guard.Against.Null(decomposition, nameof(decomposition));
            Debug.Assert(!decomposition.IsEmpty());
            Debug.Assert(decomposition.All(d => extractor.FieldType.IsInstanceOf(d.ExpectedSource)));
            Debug.Assert(!DBType.IsSupported(extractor.FieldType));         // otherwise decomposition is unnecessary

            extractor_     = extractor;
            decomposition_ = decomposition;
            ExpectedSource = extractor_.ExpectedSource;
        }
Exemplo n.º 3
0
        [TestMethod] public void LookupNullableDecimal()
        {
            // Arrange
            var type = typeof(decimal?);

            // Act
            var supported = DBType.IsSupported(type);
            var dbType    = DBType.Lookup(type);

            // Assert
            supported.Should().BeTrue();
            dbType.Should().Be(DBType.Decimal);
        }
Exemplo n.º 4
0
        [TestMethod] public void LookupUShort()
        {
            // Arrange
            var type = typeof(ushort);

            // Act
            var supported = DBType.IsSupported(type);
            var dbType    = DBType.Lookup(type);

            // Assert
            supported.Should().BeTrue();
            dbType.Should().Be(DBType.UInt16);
        }
Exemplo n.º 5
0
        [TestMethod] public void LookupNullableEnum()
        {
            // Arrange
            var type = typeof(DataAccessMethod?);

            // Act
            var supported = DBType.IsSupported(type);
            var dbType    = DBType.Lookup(type);

            // Assert
            supported.Should().BeTrue();
            dbType.Should().Be(DBType.Enumeration);
        }
Exemplo n.º 6
0
        [TestMethod] public void LookupNullableSbyte()
        {
            // Arrange
            var type = typeof(sbyte?);

            // Act
            var supported = DBType.IsSupported(type);
            var dbType    = DBType.Lookup(type);

            // Assert
            supported.Should().BeTrue();
            dbType.Should().Be(DBType.Int8);
        }
Exemplo n.º 7
0
        [TestMethod] public void LookupNullableFloat()
        {
            // Arrange
            var type = typeof(float?);

            // Act
            var supported = DBType.IsSupported(type);
            var dbType    = DBType.Lookup(type);

            // Assert
            supported.Should().BeTrue();
            dbType.Should().Be(DBType.Single);
        }
Exemplo n.º 8
0
        [TestMethod] public void LookupNullableULong()
        {
            // Arrange
            var type = typeof(ulong?);

            // Act
            var supported = DBType.IsSupported(type);
            var dbType    = DBType.Lookup(type);

            // Assert
            supported.Should().BeTrue();
            dbType.Should().Be(DBType.UInt64);
        }
Exemplo n.º 9
0
        [TestMethod] public void LookupChar()
        {
            // Arrange
            var type = typeof(char);

            // Act
            var supported = DBType.IsSupported(type);
            var dbType    = DBType.Lookup(type);

            // Assert
            supported.Should().BeTrue();
            dbType.Should().Be(DBType.Character);
        }
Exemplo n.º 10
0
        [TestMethod] public void LookupBool()
        {
            // Arrange
            var type = typeof(bool);

            // Act
            var supported = DBType.IsSupported(type);
            var dbType    = DBType.Lookup(type);

            // Assert
            supported.Should().BeTrue();
            dbType.Should().Be(DBType.Boolean);
        }
Exemplo n.º 11
0
        [TestMethod] public void LookupString()
        {
            // Arrange
            var type = typeof(string);

            // Act
            var supported = DBType.IsSupported(type);
            var dbType    = DBType.Lookup(type);

            // Assert
            supported.Should().BeTrue();
            dbType.Should().Be(DBType.Text);
        }
Exemplo n.º 12
0
        [TestMethod] public void LookupDateTime()
        {
            // Arrange
            var type = typeof(DateTime);

            // Act
            var supported = DBType.IsSupported(type);
            var dbType    = DBType.Lookup(type);

            // Assert
            supported.Should().BeTrue();
            dbType.Should().Be(DBType.DateTime);
        }
Exemplo n.º 13
0
        [TestMethod] public void LookupCollection()
        {
            // Arrange
            var type = typeof(List <string>);

            // Act
            var           supported = DBType.IsSupported(type);
            Func <DBType> action    = () => DBType.Lookup(type);

            // Assert
            supported.Should().BeFalse();
            action.Should().ThrowExactly <ArgumentException>()
            .WithAnyMessage()
            .And
            .ParamName.Should().NotBeNullOrEmpty();
        }