예제 #1
0
        public async Task Open_UnsupportedColumnType_CreatesRawColumnInstance(bool useAsync)
        {
            using (var table = await this.Exec(() => Table.Open(EmbeddedSamples.GetStream(EmbeddedSamples.UNSUPPORTED_TYPES)), useAsync))
            {
                var actualUnsupportedColumns = table.Columns.OfType <RawColumn>().Select(c => new { c.Name, c.NativeType });

                var expectedColumns = new[] { new { Name = "UNITPRICE", NativeType = 89 }, new { Name = "_NullFlags", NativeType = 48 } };
                actualUnsupportedColumns.ShouldAllBeEquivalentTo(expectedColumns, opt => opt.WithStrictOrdering());
            }
        }
예제 #2
0
        public async Task Open_FoxProDateTimeColumn_CreatesFoxProDateTimeColumnInstance(bool useAsync)
        {
            var tableStream = EmbeddedSamples.GetStream(EmbeddedSamples.FOXPRO_DATETIME);

            using (var table = await this.Exec(() => Table.Open(tableStream), useAsync))
            {
                var foxProDateTimeColumn = table.Columns[Samples.FoxProDateTime.FirstRow().columnName];

                foxProDateTimeColumn.Should().BeOfType <FoxProDateTimeColumn>();
            }
        }
예제 #3
0
        public async Task GetDecimal_ValueWithWhitespace_ReturnsValue(bool useAsync)
        {
            using (var table = await this.Exec(() => Table.Open(EmbeddedSamples.GetStream(EmbeddedSamples.WHITE_SPACES)), useAsync))
            {
                var reader = table.OpenReader(Encoding.GetEncoding(1250));
                await reader.Exec(r => r.Read(), useAsync);

                decimal?actualValue = reader.GetDecimal("OBJ_SEQ");
                actualValue.ShouldBeEquivalentTo(11085340);
            }
        }
        public async Task TableWithTenBytesDates_ReadsTheTableProperly(bool useAsync)
        {
            using (var tableStream = EmbeddedSamples.GetStream(EmbeddedSamples.TEN_BYTES_DATES))
                using (var table = await this.Exec(() => Table.Open(tableStream), useAsync))
                {
                    var reader = table.OpenReader();
                    await reader.Exec(r => r.Read(), useAsync);

                    var firstRowContent = table.Columns.Select(reader.GetValue).ToList();

                    firstRowContent.ShouldAllBeEquivalentTo(Samples.TenBytesDates.FirstRowContent);
                }
        }
예제 #5
0
        public async Task GetValue_UnsupportedColumn_ReturnsBytes(bool useAsync)
        {
            using (var table = await this.Exec(() => Table.Open(EmbeddedSamples.GetStream(EmbeddedSamples.UNSUPPORTED_TYPES)), useAsync))
            {
                Reader reader = table.OpenReader();
                for (int i = 0; i < 3; i++)
                {
                    await reader.Exec(r => r.Read(), useAsync);
                }

                var actualBytes   = reader.GetValue("UNITPRICE") as byte[];
                var expectedBytes = new byte[] { 160, 134, 1, 0, 0, 0, 0, 0 };
                actualBytes.ShouldAllBeEquivalentTo(expectedBytes, opt => opt.WithStrictOrdering());
            }
        }
예제 #6
0
        private async Task GetMethod_ZeroSizeColumn_ReturnsNull(Func <Reader, object> getter, bool useAsync)
        {
            // Arrange
            Stream stream = EmbeddedSamples.GetStream(EmbeddedSamples.ZERO_SIZE_COLUMN);

            using (var table = await this.Exec(() => Table.Open(stream), useAsync))
            {
                var reader = table.OpenReader(Encoding.GetEncoding(1250));
                await reader.Exec((r) => r.Read(), useAsync);

                var expectedValues = new[] { null, "ABCD" };

                // Act
                var actualValues = new[] { getter(reader), reader.GetString("CSU_KRAJ") };

                // Assert
                actualValues.ShouldAllBeEquivalentTo(expectedValues, opt => opt.WithStrictOrdering());
            }
        }
예제 #7
0
        public async Task Open_TableWithExtraHeaderFields_ReturnsCorrectValues(bool useAsync, bool seekableStream)
        {
            Stream tableStream = EmbeddedSamples.GetStream(EmbeddedSamples.UNSUPPORTED_TYPES);

            if (seekableStream)
            {
                tableStream = tableStream.ToNonSeekable();
            }

            using (var table = await this.Exec(() => Table.Open(tableStream), useAsync))
            {
                var reader = table.OpenReader();
                await reader.Exec(r => r.Read(), useAsync);

                var expectedValues = new object[] { 1, "Chai", 1, 1, "10 boxes x 20 bags" };
                var actualValues   = new object[] { reader.GetValue("PRODUCTID"), reader.GetValue("PRODUCTNAM"), reader.GetValue("SUPPLIERID"), reader.GetValue("CATEGORYID"), reader.GetValue("QUANTITYPE") };

                actualValues.ShouldAllBeEquivalentTo(expectedValues, opt => opt.WithStrictOrdering());
            }
        }
예제 #8
0
        private async Task GetMethod_FoxProDateTimeColumn_ReturnsCorrectDateTime(bool useAsync, Func <Reader, DateTime?> getMethod, DateTime?expectedValue)
        {
            // Arrange
            Stream stream = EmbeddedSamples.GetStream(EmbeddedSamples.FOXPRO_DATETIME);

            using (var table = await this.Exec(() => Table.Open(stream), useAsync))
            {
                var reader = table.OpenReader();

                DateTime?actualValue = null;

                if (await reader.Exec(r => r.Read(), useAsync))
                {
                    // Act
                    actualValue = getMethod(reader);
                }

                // Assert
                actualValue.TrimMilliseconds().ShouldBeEquivalentTo(expectedValue);
            }
        }
예제 #9
0
        public async Task Read_TableBasedOnNonSeekableStream_ReadsAllRowsAsUsual(bool useAsync)
        {
            // Arrange
            var stream = EmbeddedSamples.GetStream(EmbeddedSamples.BASIC).ToNonSeekable();

            // Act
            int rowsCount = 0;

            using (var table = await this.Exec(() => Table.Open(stream), useAsync))
            {
                var reader = table.OpenReader();

                while (await reader.Exec(r => r.Read(), useAsync))
                {
                    rowsCount += 1;
                }
            }

            // Assert
            Assert.Equal(3, rowsCount);
        }
예제 #10
0
        public async Task ReadsBigCzechSampleTableWithoutErrors(bool useAsync)
        {
            // Arrange & Act
            using (var table = await this.Exec(() => Table.Open(EmbeddedSamples.GetStream(EmbeddedSamples.BIG_CZECH_DATA)), useAsync))
            {
                var readRows = 0;
                var reader   = table.OpenReader(Encoding.GetEncoding(1250));

                object value = null;
                while (await reader.Exec(r => r.Read(), useAsync))
                {
                    foreach (var column in table.Columns)
                    {
                        value = reader.GetValue(column);
                    }

                    readRows++;
                }

                // Assert
                Assert.Equal(1071, readRows);
            }
        }
예제 #11
0
        private async Task Read_TableWithDeletedRows_SkipsDeletedRows(bool useAsync, Func <Stream, Stream> streamModifier)
        {
            // Arrange
            var stream = streamModifier(EmbeddedSamples.GetStream(EmbeddedSamples.DELETED_ROWS));

            using (var table = await this.Exec(() => Table.Open(stream), useAsync))
            {
                var reader        = table.OpenReader();
                var expectedItems = new List <string> {
                    "text3"
                };
                var actualItems = new List <string>();

                // Act
                while (await reader.Exec(r => r.Read(), useAsync))
                {
                    actualItems.Add(reader.GetString("NAME"));
                }

                // Assert
                actualItems.ShouldAllBeEquivalentTo(expectedItems, opt => opt.WithStrictOrdering());
            }
        }
예제 #12
0
        public async Task GetString_ReaderOfTableWithCzechTextsOpenedWithCzechEncoding_ReturnsCorrectlyEncodedString(bool useAsync)
        {
            // Arrange
            Stream stream = EmbeddedSamples.GetStream(EmbeddedSamples.CZECH_ENCODING);

            using (var table = await this.Exec(() => Table.Open(stream), useAsync))
            {
                var reader = table.OpenReader(Encoding.GetEncoding(1250));

                var expectedItems = new List <string> {
                    "Mateřská škola Deštná", "Tělocvična Deštná", "Městský úřad Deštná"
                };
                var actualItems = new List <string>();

                // Act
                while (await reader.Exec(r => r.Read(), useAsync))
                {
                    actualItems.Add(reader.GetString("DS"));
                }

                // Assert
                actualItems.ShouldAllBeEquivalentTo(expectedItems, opt => opt.WithStrictOrdering());
            }
        }
예제 #13
0
 public static Stream GetBasicTableStream()
 {
     return(EmbeddedSamples.GetStream(EmbeddedSamples.BASIC));
 }