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
        }
Exemple #2
0
        public void FileWriterTest()
        {
            var invoice = new Invoice()
            {
                CompanyName    = "SoftysTech LCC",
                Date           = new DateTime(2018, 10, 30),
                BuyerName      = "SysCompanik",
                InvoiceNumber  = "0169/18",
                AmountTotal    = 1299.00m,
                DateCreated    = new DateTime(2018, 10, 31),
                SignatureName  = "John Doe",
                SignatoryTitle = "Financial Manager",
            };

            var fileProvider = new FixedWidthFileProvider <Invoice>()
            {
                Content = GetDataFormTemplate()
            };

            fileProvider.UpdateContent(invoice);

            List <string> fileLines     = GetDataFile();
            int           numberOfLines = fileLines.Count;

            for (int i = 0; i < numberOfLines; i++)
            {
                Assert.Equal(fileLines[i], fileProvider.Content[i]);
            }
        }
Exemple #3
0
        public void FileParserTest()
        {
            List <string> fileLines = GetDataFile();

            Invoice invoice = new FixedWidthFileProvider <Invoice>().Parse(fileLines);

            Assert.Equal("SoftysTech LCC", invoice.CompanyName);
            Assert.Equal(new DateTime(2018, 10, 30), invoice.Date);
            Assert.Equal("SysCompanik", invoice.BuyerName);
            Assert.Equal("0169/18", invoice.InvoiceNumber);
            Assert.Equal(1299.00m, invoice.AmountTotal);
            Assert.Equal(new DateTime(2018, 10, 31), invoice.DateCreated);
            Assert.Equal("Financial Manager", invoice.SignatoryTitle);
            Assert.Equal("John Doe", invoice.SignatureName);
        }
        /// <summary>
        /// Get the property bag from a given instance
        /// </summary>
        /// <returns>The property bag item types</returns>
        public List <PropertyBagItemType> Get(ObjectTypes objectType, Int32 value)
        {
            // The result
            List <PropertyBagItemType> result = new List <PropertyBagItemType>();

            // Check the enum type
            switch (objectType)
            {
            // We are checking data provider types
            case ObjectTypes.Connections:

                IDataProvider provider = null;

                DataProviderType dataProviderType = (DataProviderType)value;
                switch (dataProviderType)
                {
                case DataProviderType.DelimitedFileProvider:
                    provider = new DelimitedFileProvider();
                    break;

                case DataProviderType.FixedWidthFileProvider:
                    provider = new FixedWidthFileProvider();
                    break;

                case DataProviderType.SQLProvider:
                    provider = new SQLProvider();
                    break;
                }

                // Did we get a provider?
                if (provider != null)
                {
                    result   = provider.PropertyBagTypes(); // Get the property bag types
                    provider = null;                        // Destroy (effectively)
                }

                break;
            }

            // Return the result
            return(result);
        }
        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 #7
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
        }