Exemple #1
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
        }
        public void Write_DataTypes()
        {
            // Arrange
            TestHelper testHelper = new TestHelper();

            DataConnection     connection  = testHelper.TestConnection();                                         // Get a test connection
            DataItemDefinition definition  = testHelper.TestDefinition(TestHelper.TestFile_GenericFixedWidth);    // Get the test definition of what to write
            DataTable          dataToWrite = testHelper.PopulateDataTable(TestHelper.TestFile_GenericFixedWidth); // Get the data
            DataTable          dataToRead  = null;                                                                // Table to read the data back in to (to verify it was created)
            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(dataToWrite, "");                      // Write the data to the empty stream
            dataToRead = provider.Read("");                       // Get the data back

            // Assert
            Assert.True(dataToRead.Rows.Count != 0);
        }
        public DataTable PopulateDataTable(String testDefinition, DataConnection connection)
        {
            // Get the test data from the resource in the manifest
            Stream resourceStream = GetResourceStream(testDefinition);

            // Get the test definition (The columns, data types etc. for this file)
            DataItemDefinition definition = TestDefinition(testDefinition);

            // Create a new flat file provider
            IDataProvider provider = new FixedWidthFileProvider()
            {
                TestMode = true // The provider should be marked as being in test mode
            };

            provider.Connect(definition, connection, resourceStream); // Connect to the location of the data

            // Read the data from the provider
            DataTable data = provider.Read(""); // Get the data

            // Return the data table
            return(data);
        }
Exemple #4
0
        public void Filter_Records_With_Command()
        {
            // Arrange
            TestHelper testHelper = new TestHelper();

            DataConnection     connection     = testHelper.TestConnection();                                         // Get a test connection
            DataItemDefinition definition     = testHelper.TestDefinition(TestHelper.TestFile_GenericFixedWidth);    // Get the test definition of what to data to filter
            DataTable          unfilteredData = testHelper.PopulateDataTable(TestHelper.TestFile_GenericFixedWidth); // 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

            String command = "[GL Account] = '3930621977'";                                                          // The command to do the filter

            // Act
            provider.Connect(definition, connection, testStream); // Connect to the blank stream
            provider.Write(unfilteredData, "");                   // Write the unfiltered data to the empty stream
            DataTable filteredData = provider.Read(command);      // Get the new data set back that has been filtered

            // Assert
            Assert.True(filteredData.Rows.Count == 1); // Expect 1 row in the filtered set
        }