public void ConstructorThrowsExceptionWhenLengthGreaterThanMaximumForDoubleByteCharacterSet()
        {
            const int maxLength = 4000;

            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, maxLength, BindingFlags.DoubleByteCharacterSet);

            TestHelper.AssertThrows<ArgumentOutOfRangeException>(() =>
            {
                sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, maxLength + 1, BindingFlags.DoubleByteCharacterSet);
            });
        }
        public void ConstructorSetsByteLengthCorrectly()
        {
            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, AnyValidLengthWillDo, BindingFlags.None);

            Assert.AreEqual(AnyValidLengthWillDo, sut.ByteLength);
            Assert.AreEqual(AnyValidLengthWillDo, sut.Length);

            sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, AnyValidLengthWillDo, BindingFlags.DoubleByteCharacterSet);

            Assert.AreEqual(AnyValidLengthWillDo * 2, sut.ByteLength);
            Assert.AreEqual(AnyValidLengthWillDo, sut.Length);
        }
 public void ConstructorThrowsExceptionWhenIndexLessThanZero()
 {
     var sut = new StandardDataTypeImpl(-1, AnyBulkCopyDataTypeWillDo, 1, BindingFlags.None);
 }
        public void SetNullBehavesAsExpectedForVariableLengthColumn()
        {
            const int zeroLength = 0;

            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, AnyValidLengthWillDo, BindingFlags.VariableLengthOut);

            Assert.AreEqual(IndicatorLength, sut.IndicatorLength);

            sut.SetLength(AnyValidLengthWillDo);

            Assert.AreEqual(AnyValidLengthWillDo, GetIndicator(sut));

            sut.SetNull();

            Assert.AreEqual(zeroLength, GetIndicator(sut));
        }
        public void SetNullThrowsExceptionWhenIndicatorNotPresent()
        {
            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, AnyValidLengthWillDo, BindingFlags.None);

            sut.SetNull();
        }
        public void SetLengthThrowsExceptionWhenIndexOutOfRange()
        {
            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, AnyValidLengthWillDo, BindingFlags.Nullable);

            TestHelper.AssertThrows<ArgumentOutOfRangeException>(() => sut.SetLength(-1));
            TestHelper.AssertThrows<ArgumentOutOfRangeException>(() => sut.SetLength(AnyValidLengthWillDo + 1));
        }
        public void SetNullBehavesAsExpectedForNullableColumn()
        {
            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, AnyValidLengthWillDo, BindingFlags.Nullable);

            Assert.AreEqual(IndicatorLength, sut.IndicatorLength);

            sut.SetLength(AnyValidLengthWillDo);

            Assert.AreEqual(AnyValidLengthWillDo, GetIndicator(sut));

            sut.SetNull();

            Assert.AreEqual(Constants.SqlNullData, GetIndicator(sut));
        }
        public void ReturnsExpectedPropertyValues()
        {
            var sut = new StandardDataTypeImpl(0, BulkCopyDataType.TinyInt, AnyValidLengthWillDo, BindingFlags.None);

            const int tinyIntDataTypeLength = 1;

            Assert.AreEqual(tinyIntDataTypeLength, ((IBulkCopyBoundColumn)sut).ByteLength);
            Assert.AreEqual(BulkCopyDataType.TinyInt, sut.DataType);
            Assert.AreEqual("TinyInt NOT NULL", sut.DataTypeDescription);
            Assert.AreEqual(0, sut.Index);
            Assert.AreEqual(0, sut.IndicatorLength);
            Assert.AreEqual(true, sut.IsBound);
            Assert.AreEqual(false, sut.IsNullable);
            Assert.AreEqual(false, sut.IsVariableLength);
            Assert.AreEqual(tinyIntDataTypeLength, ((IBulkCopyBoundColumn)sut).Length);
            Assert.AreEqual(BindingFlags.None, sut.Options);

            sut = new StandardDataTypeImpl(1, BulkCopyDataType.NullableVarBinary, AnyValidLengthWillDo, BindingFlags.Nullable | BindingFlags.VariableLengthIn | BindingFlags.VariableLengthOut);

            Assert.AreEqual(AnyValidLengthWillDo, ((IBulkCopyBoundColumn)sut).ByteLength);
            Assert.AreEqual(BulkCopyDataType.NullableVarBinary, sut.DataType);
            Assert.AreEqual("VarBinary NULL", sut.DataTypeDescription);
            Assert.AreEqual(1, sut.Index);
            Assert.AreEqual(IndicatorLength, sut.IndicatorLength);
            Assert.AreEqual(true, sut.IsBound);
            Assert.AreEqual(true, sut.IsNullable);
            Assert.AreEqual(true, sut.IsVariableLength);
            Assert.AreEqual(AnyValidLengthWillDo, ((IBulkCopyBoundColumn)sut).Length);
            Assert.AreEqual(BindingFlags.Nullable | BindingFlags.VariableLengthIn | BindingFlags.VariableLengthOut, sut.Options);
        }
        public void SetLengthBehavesAsExpected()
        {
            const int maxLength = 8000;
            const int minValue = 1;
            const int maxValue = maxLength;

            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, maxLength, BindingFlags.Nullable);

            Assert.AreEqual(IndicatorLength, sut.IndicatorLength);

            sut.SetLength(minValue);

            Assert.AreEqual(minValue, GetIndicator(sut));

            sut.SetLength(maxValue);

            Assert.AreEqual(maxValue, GetIndicator(sut));
        }
        public void CopyInt64BehavesAsExpected()
        {
            const int dataTypeLengthInBytes = 8;
            const long minValue = long.MinValue;
            const long maxValue = long.MaxValue;

            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, dataTypeLengthInBytes, BindingFlags.None);

            Assert.AreEqual(0, sut.IndicatorLength);

            sut.CopyInt64(0, minValue);

            Assert.AreEqual(minValue, BitConverter.ToInt64(sut.Data, sut.IndicatorLength));

            sut.CopyInt64(0, maxValue);

            Assert.AreEqual(maxValue, BitConverter.ToInt64(sut.Data, sut.IndicatorLength));

            sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, dataTypeLengthInBytes, BindingFlags.Nullable);

            Assert.AreEqual(IndicatorLength, sut.IndicatorLength);

            sut.CopyInt64(0, minValue);

            Assert.AreEqual(minValue, BitConverter.ToInt64(sut.Data, sut.IndicatorLength));

            sut.CopyInt64(0, maxValue);

            Assert.AreEqual(maxValue, BitConverter.ToInt64(sut.Data, sut.IndicatorLength));
        }
        public void CopyInt64ThrowsExceptionWhenIndexOutOfRange()
        {
            const int dataTypeLengthInBytes = 8;
            const long anyValueWillDo = 1;

            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, dataTypeLengthInBytes, BindingFlags.None);

            TestHelper.AssertThrows<ArgumentOutOfRangeException>(() => sut.CopyInt64(-1, anyValueWillDo));
            TestHelper.AssertThrows<ArgumentOutOfRangeException>(() => sut.CopyInt64(dataTypeLengthInBytes, anyValueWillDo));
        }
        public void CopyFromThrowsExceptionWhenIndexLessThanZero()
        {
            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, AnyValidLengthWillDo, BindingFlags.None);

            sut.CopyFrom(new byte[AnyValidLengthWillDo], -1);
        }
        public void CopyFromThrowsExceptionWhenBytesIsNull()
        {
            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, AnyValidLengthWillDo, BindingFlags.None);

            sut.CopyFrom(null, AnyValidLengthWillDo);
        }
        public void CopyFromBehavesAsExpected()
        {
            const int dataTypeLengthInBytes = 4;
            var bytes = new byte[] {0, 128, 255};

            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, dataTypeLengthInBytes, BindingFlags.None);

            Assert.AreEqual(0, sut.IndicatorLength);

            sut.CopyFrom(bytes, 0);

            VerifyCopiedBytes(bytes, sut);

            sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, dataTypeLengthInBytes, BindingFlags.Nullable);

            Assert.AreEqual(IndicatorLength, sut.IndicatorLength);

            sut.CopyFrom(bytes, 0);

            Assert.AreEqual(bytes.Length, GetIndicator(sut));
            VerifyCopiedBytes(bytes, sut);
        }
        public void CopyByteBehavesAsExpected()
        {
            const int dataTypeLengthInBytes = 1;
            const byte minValue = byte.MinValue;
            const byte maxValue = byte.MaxValue;

            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, dataTypeLengthInBytes, BindingFlags.None);

            Assert.AreEqual(0, sut.IndicatorLength);

            sut.CopyByte(0, minValue);

            Assert.AreEqual(minValue, sut.Data[sut.IndicatorLength]);

            sut.CopyByte(0, maxValue);

            Assert.AreEqual(maxValue, sut.Data[sut.IndicatorLength]);

            sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, dataTypeLengthInBytes, BindingFlags.Nullable);

            Assert.AreEqual(IndicatorLength, sut.IndicatorLength);

            sut.CopyByte(0, minValue);

            Assert.AreEqual(minValue, sut.Data[sut.IndicatorLength]);

            sut.CopyByte(0, maxValue);

            Assert.AreEqual(maxValue, sut.Data[sut.IndicatorLength]);
        }
        public void ConstructorThrowsExceptionWhenLengthLessThanOne()
        {
            const int minLength = 1;

            var sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, minLength, BindingFlags.None);

            TestHelper.AssertThrows<ArgumentOutOfRangeException>(() =>
            {
                sut = new StandardDataTypeImpl(AnyValidIndexWillDo, AnyBulkCopyDataTypeWillDo, minLength - 1, BindingFlags.None);
            });
        }