コード例 #1
0
        /// <summary>
        /// Get a test connection for use with the readers
        /// </summary>
        /// <returns>A test connection</returns>
        public DataConnection TestConnection()
        {
            DataConnection connection = new DataConnection()
            {
                ProviderType = DataProviderType.FixedWidthFileProvider,
                LastUpdated  = DateTime.Now,
                Id           = Guid.NewGuid(),
                PropertyBag  =
                    (new FixedWidthFileProvider()).PropertyBagTypes()
                    .Select(type =>
                            new PropertyBagItem()
                {
                    Value    = type.DefaultValue,
                    ItemType = type
                })
                    .ToList()
            };

            // Create a property bag helper to set some defaults
            PropertyBagHelper propertyBagHelper = new PropertyBagHelper(connection);

            propertyBagHelper.Set <Boolean>(PropertyBagItemTypeEnum.HasHeaderRecord, true);
            propertyBagHelper.Set <Int32>(PropertyBagItemTypeEnum.RowsToSkip, 1);

            return(connection);
        }
コード例 #2
0
        public void Merge_Files_2_Part_Primary_Key()
        {
            // Arrange
            TestHelper testHelper = new TestHelper();

            DataConnection    connection        = testHelper.TestConnection(); // Get a test connection
            PropertyBagHelper propertyBagHelper = new PropertyBagHelper(connection);

            propertyBagHelper.Set <Int32>(PropertyBagItemTypeEnum.RowsToSkip, 1);
            propertyBagHelper.Set <Boolean>(PropertyBagItemTypeEnum.HasHeaderRecord, true);

            DataItemDefinition definition = testHelper.TestDefinition(TestHelper.TestFile_GenericFixedWidth);      // Get the test definition of what to merge from (but also to)

            DataTable baseData  = testHelper.PopulateDataTable(TestHelper.TestFile_GenericFixedWidth, connection); // Get the data
            DataTable mergeData = testHelper.PopulateDataTable(TestHelper.TestFile_MergeData, connection);         // Get the data

            Stream        testStream = new MemoryStream();                                                         // A blank stream to write data to
            IDataProvider provider   = new FixedWidthFileProvider();                                               // A flat file provider to use to write the data

            // Act
            provider.Connect(definition, connection, testStream); // Connect to the blank stream
            provider.Write(baseData, "");                         // Write the data to the empty stream
            provider.Write(mergeData, "");                        // Write some more records with some updates and some adds
            DataTable mergedData = provider.Read("");             // Get the new data set back

            // Assert
            Assert.True(mergedData.Rows.Count == (baseData.Rows.Count + mergeData.Rows.Count) - 1); // Expect of the total of 8 rows, 2 should merge
        }
コード例 #3
0
        public void Custom_Dates_Can_Be_Read()
        {
            // Arrange
            TestHelper        testHelper        = new TestHelper();
            DataConnection    connection        = testHelper.TestConnection();
            PropertyBagHelper propertyBagHelper = new PropertyBagHelper(connection);

            propertyBagHelper.Set <Int32>(PropertyBagItemTypeEnum.RowsToSkip, 1);
            propertyBagHelper.Set <Boolean>(PropertyBagItemTypeEnum.HasHeaderRecord, true);

            // Act
            DataTable data = testHelper.PopulateDataTable(TestHelper.TestFile_GenericFixedWidth, connection); // Get the data

            // Assert
            Assert.True(data.Rows.Count != 0); // It actually got some data rows
            Object row0Date = data.Rows[0]["PostDate"];
            Object row1Date = data.Rows[1]["PostDate"];
            Object row2Date = data.Rows[2]["PostDate"];
            Object row3Date = data.Rows[3]["PostDate"];

            // "10/17/2012"
            Assert.True(
                (row0Date != DBNull.Value) &&
                ((DateTime)row0Date).Day == 17 &&
                ((DateTime)row0Date).Month == 10 &&
                ((DateTime)row0Date).Year == 2012);

            // "01/14/2013"
            Assert.True(
                (row1Date != DBNull.Value) &&
                ((DateTime)row1Date).Day == 14 &&
                ((DateTime)row1Date).Month == 1 &&
                ((DateTime)row1Date).Year == 2013);

            // "XX/YY/2012"
            Assert.True((row2Date == DBNull.Value));

            // "11/21/2012"
            Assert.True(
                (row3Date != DBNull.Value) &&
                ((DateTime)row3Date).Day == 21 &&
                ((DateTime)row3Date).Month == 11 &&
                ((DateTime)row3Date).Year == 2012);
        }
コード例 #4
0
        public void Data_Read_From_Headers()
        {
            // Arrange
            TestHelper        testHelper        = new TestHelper();
            DataConnection    connection        = testHelper.TestConnection(); // Get a test connection
            PropertyBagHelper propertyBagHelper = new PropertyBagHelper(connection);

            propertyBagHelper.Set <Int32>(PropertyBagItemTypeEnum.RowsToSkip, 1);
            propertyBagHelper.Set <Boolean>(PropertyBagItemTypeEnum.HasHeaderRecord, true);

            // Act
            DataTable data    = testHelper.PopulateDataTable(TestHelper.TestFile_GenericFixedWidth, connection); // Get the data
            DataRow   dataRow = (data.Rows.Count >= 1) ? data.Rows[0] : null;                                    // Get row 3 to check the data against later

            // Assert
            Assert.True(data.Rows.Count == 530);                                                  // Should be 530 rows (532 including the header and spacer)
            Assert.True(data.Columns.Contains("Description"));                                    // Should be a column that was found even though it had no quotes
            Assert.True(dataRow != null && ((String)dataRow["Description"]).Trim() == "TXNPUES"); // The third row should have some data for the unquoted header
            Assert.True(dataRow != null && ((String)dataRow["Ref"]).Trim() == "RHMXWPCP");        // The third row should have some data for the unquoted header
            Assert.True(dataRow != null && (Boolean)dataRow["Post"]);                             // The third row should have some data for the unquoted header
        }
コード例 #5
0
        public void Boolean_Values_Of_Different_Types()
        {
            // Arrange
            TestHelper        testHelper        = new TestHelper();
            DataConnection    connection        = testHelper.TestConnection();
            PropertyBagHelper propertyBagHelper = new PropertyBagHelper(connection);

            propertyBagHelper.Set <Boolean>(PropertyBagItemTypeEnum.HasHeaderRecord, false);

            // Act
            DataTable data = testHelper.PopulateDataTable(TestHelper.TestFile_DataTypes, connection); // Get the data

            // Assert
            Assert.True(data.Rows.Count != 0);                                               // It actually got some data rows
            Assert.True((data.Rows.Count == 5) && (Boolean)data.Rows[0]["Active"] == true);  // Check row 0's expected result
            Assert.True((data.Rows.Count == 5) && (Boolean)data.Rows[1]["Active"] == true);  // Check row 1's expected result
            Assert.True((data.Rows.Count == 5) && (Boolean)data.Rows[2]["Active"] == true);  // Check row 2's expected result
            Assert.True((data.Rows.Count == 5) && (Boolean)data.Rows[3]["Active"] == false); // Check row 3's expected result
            Assert.True((data.Rows.Count == 5) && (Boolean)data.Rows[4]["Active"] == false); // Check row 4's expected result
        }
コード例 #6
0
        public void Boolean_Values_Of_Different_Types()
        {
            // Arrange
            TestHelper        testHelper        = new TestHelper();
            DataConnection    connection        = testHelper.TestConnection();
            PropertyBagHelper propertyBagHelper = new PropertyBagHelper(connection);

            propertyBagHelper.Set <Int32>(PropertyBagItemTypeEnum.RowsToSkip, 0); // Override the default setting to 0 rows to skip

            // Act
            DataTable data = testHelper.PopulateDataTable(TestHelper.TestFile_DataTypes, connection); // Get the data

            // Assert
            Assert.True(data.Rows.Count != 0);                                                    // It actually got some data rows
            Assert.True((data.Rows.Count == 6) && (Boolean)data.Rows[0]["BooleanType"] == true);  // Check row 0's expected result
            Assert.True((data.Rows.Count == 6) && (Boolean)data.Rows[1]["BooleanType"] == false); // Check row 1's expected result
            Assert.True((data.Rows.Count == 6) && (Boolean)data.Rows[2]["BooleanType"] == true);  // Check row 2's expected result
            Assert.True((data.Rows.Count == 6) && (Boolean)data.Rows[3]["BooleanType"] == false); // Check row 3's expected result
            Assert.True((data.Rows.Count == 6) && (Boolean)data.Rows[4]["BooleanType"] == true);  // Check row 4's expected result
            Assert.True((data.Rows.Count == 6) && (Boolean)data.Rows[5]["BooleanType"] == false); // Check row 5's expected result
        }