Ejemplo n.º 1
0
        public void PostgreSql_Integration()
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new ShorthandTransformModule());
            builder.RegisterModule(new RootModule());
            var container = builder.Build();

            // CORRECT DATA AND INITIAL LOAD
            using (var cn = new SqlServerConnectionFactory(InputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(2, cn.Execute(@"
                    UPDATE [Order Details] SET UnitPrice = 14.40, Quantity = 42 WHERE OrderId = 10253 AND ProductId = 39;
                    UPDATE Orders SET CustomerID = 'CHOPS', Freight = 22.98 WHERE OrderId = 10254;
                "));
            }

            var root     = ResolveRoot(container, Cfg, InitMode());
            var response = Execute(root);

            Assert.AreEqual(200, response.Code);
            Assert.AreEqual(string.Empty, response.Message);

            using (var cn = new PostgreSqlConnectionFactory(OutputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(2155, cn.ExecuteScalar <int>("SELECT COUNT(*) FROM NorthWindStar;"));
                Assert.AreEqual(2155, cn.ExecuteScalar <int>("SELECT Inserts FROM NorthWindControl WHERE Entity = 'Order Details' AND BatchId = 1 LIMIT 1;"));
            }

            // FIRST DELTA, NO CHANGES
            root     = ResolveRoot(container, Cfg);
            response = Execute(root);

            Assert.AreEqual(200, response.Code);
            Assert.AreEqual(string.Empty, response.Message);

            using (var cn = new PostgreSqlConnectionFactory(OutputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(2155, cn.ExecuteScalar <int>("SELECT COUNT(*) FROM NorthWindStar;"));
                Assert.AreEqual(0, cn.ExecuteScalar <int>("SELECT Inserts+Updates+Deletes FROM NorthWindControl WHERE Entity = 'Order Details' AND BatchId = 9 LIMIT 1;"));
            }


            // CHANGE 2 FIELDS IN 1 RECORD IN MASTER TABLE THAT WILL CAUSE CALCULATED FIELD TO BE UPDATED TOO
            using (var cn = new SqlServerConnectionFactory(InputConnection).GetConnection()) {
                cn.Open();
                const string sql = @"UPDATE [Order Details] SET UnitPrice = 15, Quantity = 40 WHERE OrderId = 10253 AND ProductId = 39;";
                Assert.AreEqual(1, cn.Execute(sql));
            }

            root     = ResolveRoot(container, Cfg);
            response = Execute(root);

            Assert.AreEqual(200, response.Code);
            Assert.AreEqual(string.Empty, response.Message);

            using (var cn = new PostgreSqlConnectionFactory(OutputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(1, cn.ExecuteScalar <int>("SELECT Updates FROM NorthWindControl WHERE Entity = 'Order Details' AND BatchId = 17 LIMIT 1;"));
                Assert.AreEqual(15.0M, cn.ExecuteScalar <decimal>("SELECT OrderDetailsUnitPrice FROM NorthWindStar WHERE OrderDetailsOrderID = 10253 AND OrderDetailsProductID = 39;"));
                Assert.AreEqual(40, cn.ExecuteScalar <int>("SELECT OrderDetailsQuantity FROM NorthWindStar WHERE OrderDetailsOrderID= 10253 AND OrderDetailsProductID = 39;"));
                Assert.AreEqual(15.0M * 40, cn.ExecuteScalar <int>("SELECT OrderDetailsExtendedPrice FROM NorthWindStar WHERE OrderDetailsOrderID= 10253 AND OrderDetailsProductID = 39;"));
            }

            // CHANGE 1 RECORD'S CUSTOMERID AND FREIGHT ON ORDERS TABLE
            using (var cn = new SqlServerConnectionFactory(InputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(1, cn.Execute("UPDATE Orders SET CustomerID = 'VICTE', Freight = 20.11 WHERE OrderId = 10254;"));
            }

            root     = ResolveRoot(container, Cfg);
            response = Execute(root);

            Assert.AreEqual(200, response.Code);
            Assert.AreEqual(string.Empty, response.Message);

            using (var cn = new PostgreSqlConnectionFactory(OutputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(1, cn.ExecuteScalar <int>("SELECT Updates FROM NorthWindControl WHERE Entity = 'Orders' AND BatchId = 26;"));
                Assert.AreEqual("VICTE", cn.ExecuteScalar <string>("SELECT OrdersCustomerID FROM NorthWindStar WHERE OrderDetailsOrderID= 10254 LIMIT 1;"));
                Assert.AreEqual(20.11M, cn.ExecuteScalar <decimal>("SELECT OrdersFreight FROM NorthWindStar WHERE OrderDetailsOrderID= 10254;"));
            }
        }
Ejemplo n.º 2
0
        public void Integration()
        {
            var logger = new ConsoleLogger(LogLevel.Debug);


            // CORRECT DATA AND INITIAL LOAD
            using (var cn = new SqlServerConnectionFactory(InputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(2, cn.Execute(@"
               UPDATE [Order Details] SET UnitPrice = 14.40, Quantity = 42 WHERE OrderId = 10253 AND ProductId = 39;
               UPDATE Orders SET CustomerID = 'CHOPS', Freight = 22.98 WHERE OrderId = 10254;
            "));
            }

            using (var outer = new ConfigurationContainer().CreateScope(Cfg + $"?Mode=init&Password={Password}", logger)) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container(new PostgreSqlModule(), new SqlServerModule(), new JintTransformModule()).CreateScope(process, logger)) {
                    var controller = inner.Resolve <IProcessController>();
                    controller.Execute();
                }
            }

            using (var cn = new PostgreSqlConnectionFactory(OutputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(2155, cn.ExecuteScalar <int>("SELECT COUNT(*) FROM NorthWindStar;"));
                Assert.AreEqual(2155, cn.ExecuteScalar <int>("SELECT Inserts FROM NorthWindControl WHERE Entity = 'Order Details' AND BatchId = 1 LIMIT 1;"));
            }

            // FIRST DELTA, NO CHANGES
            using (var outer = new ConfigurationContainer().CreateScope(Cfg + $"?Password={Password}", logger)) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container(new PostgreSqlModule(), new SqlServerModule(), new JintTransformModule()).CreateScope(process, logger)) {
                    var controller = inner.Resolve <IProcessController>();
                    controller.Execute();
                }
            }

            using (var cn = new PostgreSqlConnectionFactory(OutputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(2155, cn.ExecuteScalar <int>("SELECT COUNT(*) FROM NorthWindStar;"));
                Assert.AreEqual(0, cn.ExecuteScalar <int>("SELECT Inserts+Updates+Deletes FROM NorthWindControl WHERE Entity = 'Order Details' AND BatchId = 9 LIMIT 1;"));
            }

            // CHANGE 2 FIELDS IN 1 RECORD IN MASTER TABLE THAT WILL CAUSE CALCULATED FIELD TO BE UPDATED TOO
            using (var cn = new SqlServerConnectionFactory(InputConnection).GetConnection()) {
                cn.Open();
                const string sql = @"UPDATE [Order Details] SET UnitPrice = 15, Quantity = 40 WHERE OrderId = 10253 AND ProductId = 39;";
                Assert.AreEqual(1, cn.Execute(sql));
            }

            using (var outer = new ConfigurationContainer().CreateScope(Cfg + $"?Password={Password}", logger)) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container(new PostgreSqlModule(), new SqlServerModule(), new JintTransformModule()).CreateScope(process, logger)) {
                    var controller = inner.Resolve <IProcessController>();
                    controller.Execute();
                }
            }

            using (var cn = new PostgreSqlConnectionFactory(OutputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(1, cn.ExecuteScalar <int>("SELECT Updates FROM NorthWindControl WHERE Entity = 'Order Details' AND BatchId = 17 LIMIT 1;"));
                Assert.AreEqual(15.0M, cn.ExecuteScalar <decimal>("SELECT OrderDetailsUnitPrice FROM NorthWindStar WHERE OrderDetailsOrderID = 10253 AND OrderDetailsProductID = 39;"));
                Assert.AreEqual(40, cn.ExecuteScalar <int>("SELECT OrderDetailsQuantity FROM NorthWindStar WHERE OrderDetailsOrderID= 10253 AND OrderDetailsProductID = 39;"));
                Assert.AreEqual(15.0 * 40, cn.ExecuteScalar <int>("SELECT OrderDetailsExtendedPrice FROM NorthWindStar WHERE OrderDetailsOrderID= 10253 AND OrderDetailsProductID = 39;"));
            }

            // CHANGE 1 RECORD'S CUSTOMERID AND FREIGHT ON ORDERS TABLE
            using (var cn = new SqlServerConnectionFactory(InputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(1, cn.Execute("UPDATE Orders SET CustomerID = 'VICTE', Freight = 20.11 WHERE OrderId = 10254;"));
            }

            using (var outer = new ConfigurationContainer().CreateScope(Cfg + $"?Password={Password}", logger)) {
                var process = outer.Resolve <Process>();
                using (var inner = new Container(new PostgreSqlModule(), new SqlServerModule(), new JintTransformModule()).CreateScope(process, logger)) {
                    var controller = inner.Resolve <IProcessController>();
                    controller.Execute();
                }
            }

            using (var cn = new PostgreSqlConnectionFactory(OutputConnection).GetConnection()) {
                cn.Open();
                Assert.AreEqual(1, cn.ExecuteScalar <int>("SELECT Updates FROM NorthWindControl WHERE Entity = 'Orders' AND BatchId = 26;"));
                Assert.AreEqual("VICTE", cn.ExecuteScalar <string>("SELECT OrdersCustomerID FROM NorthWindStar WHERE OrderDetailsOrderID= 10254 LIMIT 1;"));
                Assert.AreEqual(20.11M, cn.ExecuteScalar <decimal>("SELECT OrdersFreight FROM NorthWindStar WHERE OrderDetailsOrderID= 10254;"));
            }
        }