Beispiel #1
0
        public void SqlRecordExtractorTest()
        {
            D2S.LibraryTests.SqlExtractorTestHelper helper = new SqlExtractorTestHelper();
            PipelineContext context = new PipelineContext();

            // ToDo: use connection string from app.config (local version)
            //context.SqlServerName = @"(localdb)\MSSQLLocalDB";
            //context.DatabaseName = "master";

            context.SourceTableName = "doesnt matter im hacking";
            try
            {
                context.SourceTableName = helper.Initialize(ConfigVariables.Instance.ConfiguredConnection);
                //above will build con string and then set the tablename to w/e its supposed to be
                //also initializes a test table with some data

                context.SqlSourceColumnsSelected = new List <string> {
                    "col1", "col2"
                };                                                                      //trust me on this one

                SqlRecordExtractor extractor = new SqlRecordExtractor();

                Action <PipelineContext, IProducerConsumerCollection <object>, ManualResetEvent> action = extractor.GetPausableWorkItem();

                List <object>            ResultList = new List <object>();
                ConcurrentQueue <object> results    = new ConcurrentQueue <object>();

                action(context, results, null); //call function
                ResultList = results.ToList();
                foreach (object o in ResultList)
                {
                    foreach (object p in (object[])o)
                    {
                        Console.WriteLine(p.ToString());
                    }
                }

                Assert.AreEqual(expected: "Knijn", actual: ((object[])ResultList[0])[0]);
                Assert.AreEqual(expected: 1, actual: ((object[])ResultList[0])[1]);
                Assert.AreEqual(expected: "Knijntje", actual: ((object[])ResultList[1])[0]);
                Assert.AreEqual(expected: 2, actual: ((object[])ResultList[1])[1]);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                helper.Cleanup(ConfigVariables.Instance.ConfiguredConnection);
            }
        }
Beispiel #2
0
        public void PausingReportingSQLLoaderTest()
        {
            D2S.LibraryTests.SqlExtractorTestHelper helper = new D2S.LibraryTests.SqlExtractorTestHelper();
            PipelineContext context = new PipelineContext();

            // ToDo: use connection string from app.config (local version)
            //context.SqlServerName = @"(localdb)\MSSQLLocalDB";
            //context.DatabaseName = "master";

            context.DestinationTableName = "loaderstest";
            try
            {
                context.DestinationTableName = helper.Initialize(ConfigVariables.Instance.ConfiguredConnection);
                context.ColumnNames          = new string[] { "col1", "col2" };
                ConcurrentQueue <Row> input = new ConcurrentQueue <Row>();
                Row newRow = new Row();
                newRow["col1"] = new Tuple <object, Type>("TestValue", typeof(string));
                newRow["col2"] = new Tuple <object, Type>(482, typeof(int));

                input.Enqueue(newRow);

                newRow         = new Row();
                newRow["col1"] = new Tuple <object, Type>("Hi", typeof(string));
                newRow["col2"] = new Tuple <object, Type>(483, typeof(int));

                input.Enqueue(newRow);

                SQLTableLoader loader = new SQLTableLoader();

                var action = loader.GetPausableReportingWorkItem();
                ManualResetEvent pauseButton = new ManualResetEvent(true);
                Progress <int>   progress    = new Progress <int>();

                Task work = Task.Factory.StartNew(() => action(context, input, pauseButton, progress));
                //wait for work to finish
                while (!input.IsEmpty)
                {
                    Task.Delay(200).Wait();
                }
                loader.SignalCompletion();

                work.Wait();

                //confirm that it worked
                SqlRecordExtractor reader = new SqlRecordExtractor();

                List <object>            Results = new List <object>();
                ConcurrentQueue <object> result  = new ConcurrentQueue <object>();
                Action <PipelineContext, IProducerConsumerCollection <object>, ManualResetEvent> readaction = reader.GetPausableWorkItem();
                context.SourceTableName          = context.DestinationTableName;
                context.SqlSourceColumnsSelected = new List <string>()
                {
                    "col1", "col2"
                };
                readaction(context, result, null);

                Results = result.ToList();
                Assert.AreEqual(expected: "TestValue", actual: ((object[])Results[2])[0]);
                Assert.AreEqual(expected: 482, actual: ((object[])Results[2])[1]);
                Assert.AreEqual(expected: "Hi", actual: ((object[])Results[3])[0]);
                Assert.AreEqual(expected: 483, actual: ((object[])Results[3])[1]);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                helper.Cleanup(ConfigVariables.Instance.ConfiguredConnection);
            }
        }
Beispiel #3
0
        public void SQLLoaderTest()
        {
            D2S.LibraryTests.SqlExtractorTestHelper helper = new D2S.LibraryTests.SqlExtractorTestHelper();
            PipelineContext context = new PipelineContext();

            // ToDo: use connection string from app.config (local version)
            //context.SqlServerName = @"(localdb)\MSSQLLocalDB";
            //context.DatabaseName = "master";

            context.DestinationTableName = "loaderstest";

            try
            {
                context.DestinationTableName = helper.Initialize(ConfigVariables.Instance.ConfiguredConnection);
                context.ColumnNames          = new string[] { "col1", "col2" };

                ConcurrentQueue <Row> row = new ConcurrentQueue <Row>();

                Row newRow = new Row();
                newRow["col1"] = new Tuple <object, Type>("TestValue", typeof(string));
                newRow["col2"] = new Tuple <object, Type>(482, typeof(int));

                row.Enqueue(newRow);

                newRow         = new Row();
                newRow["col1"] = new Tuple <object, Type>("Hi", typeof(string));
                newRow["col2"] = new Tuple <object, Type>(483, typeof(int));

                row.Enqueue(newRow);

                SQLTableLoader loader = new SQLTableLoader();

                Action <PipelineContext, IProducerConsumerCollection <Row> > action = loader.GetWorkItem();

                action(context, row);

                SqlRecordExtractor reader = new SqlRecordExtractor();

                List <object>            Results = new List <object>();
                ConcurrentQueue <object> result  = new ConcurrentQueue <object>();
                Action <PipelineContext, IProducerConsumerCollection <object>, ManualResetEvent> readaction = reader.GetPausableWorkItem();
                context.SourceTableName          = context.DestinationTableName;
                context.SqlSourceColumnsSelected = new List <string>()
                {
                    "col1", "col2"
                };
                readaction(context, result, null);

                Results = result.ToList();
                Assert.AreEqual(expected: "TestValue", actual: ((object[])Results[2])[0]);
                Assert.AreEqual(expected: 482, actual: ((object[])Results[2])[1]);
                Assert.AreEqual(expected: "Hi", actual: ((object[])Results[3])[0]);
                Assert.AreEqual(expected: 483, actual: ((object[])Results[3])[1]);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                helper.Cleanup(ConfigVariables.Instance.ConfiguredConnection);
            }
        }