Example #1
0
        public void TestCount()
        {
            var cfg = new ProcessBuilder("process")
                      .Connection("input").Provider(ProviderType.Internal)
                      .Connection("output").Provider(ProviderType.Internal)
                      .Entity("entity")
                      .Group() //group means you need to aggregate all output fields
                      .Field("order").Aggregate("group").Int32().PrimaryKey()
                      .Field("count").Input(false).Aggregate("count").Int32()
                      .Process();

            cfg.Entities.First().InputOperation = _testInput;

            var output = ProcessFactory.CreateSingle(cfg, new TestLogger()).Execute().ToArray();

            Assert.AreEqual(2, output.Length);

            var r1 = output[0];

            Assert.AreEqual(1, r1["order"]);
            Assert.AreEqual(5, r1["count"]);

            var r2 = output[1];

            Assert.AreEqual(2, r2["order"]);
            Assert.AreEqual(2, r2["count"]);
        }
Example #2
0
        public TestWithProcess()
        {
            var cfg = new TflRoot(File.ReadAllText(@"TestFiles\Test.xml"), null);

            foreach (var problem in cfg.Errors())
            {
                Console.WriteLine(problem);
            }

            _process = ProcessFactory.CreateSingle(cfg.Processes[0], new TestLogger());

            _entityKeysExtract = new Mock <IOperation>();
            _entityKeysExtract.Setup(foo => foo.Execute(It.IsAny <IEnumerable <Row> >())).Returns(new List <Row> {
                new Row {
                    { "OrderDetailKey", 1 }
                },
                new Row {
                    { "OrderDetailKey", 2 }
                },
                new Row {
                    { "OrderDetailKey", 3 }
                },
                new Row {
                    { "OrderDetailKey", 4 }
                }
            });
        }
Example #3
0
        public FileImportResult Import(FileInspectionRequest request, TflConnection output)
        {
            var fileInformation = FileInformationFactory.Create(request, _logger);

            var cfg = BuildProcess(fileInformation, request, output, _logger);

            if (cfg.Connections.First(c => c.Name == "output").Provider == "internal")
            {
                // nothing to init, so just run in default mode
                return(new FileImportResult {
                    Information = fileInformation,
                    Rows = ProcessFactory.CreateSingle(cfg, _logger).Execute()
                });
            }

            // first run in init mode
            cfg.Mode = "init";
            var process = ProcessFactory.CreateSingle(cfg, _logger, new Options {
                Mode = "init"
            });

            process.ExecuteScaler();

            // now run in default mode
            cfg.Mode = "default";
            process  = ProcessFactory.CreateSingle(cfg, _logger, new Options()
            {
                Mode = "default"
            });
            return(new FileImportResult {
                Information = fileInformation,
                Rows = process.Execute(),
                RowCount = process.Entities[0].Inserts
            });
        }
Example #4
0
        public void RunCfgBenchmark()
        {
            var xml = File.ReadAllText(@"NorthWind.xml");

            var xDocWatch = new Stopwatch();
            var procWatch = new Stopwatch();
            var cfgWatch  = new Stopwatch();

            xDocWatch.Start();
            var xDocProcess = XDocument.Parse(xml).Root.Element("processes").Element("add");

            xDocWatch.Stop();

            cfgWatch.Start();
            var cfgProcess = new ConfigurationFactory(xml, new TestLogger()).CreateSingle();

            cfgWatch.Stop();

            procWatch.Start();
            var bigBloatedProcess = ProcessFactory.CreateSingle(xml, new TestLogger());

            procWatch.Stop();

            Console.WriteLine("Process: " + procWatch.ElapsedMilliseconds);   // ~ 1928 to 1586
            Console.WriteLine("Config: " + cfgWatch.ElapsedMilliseconds);     // ~ 341 to 222
            Console.WriteLine("XDocument: " + xDocWatch.ElapsedMilliseconds); // ~ 45ms to 44

            Assert.AreEqual("NorthWind", xDocProcess.Attribute("name").Value);
            Assert.AreEqual("NorthWind", cfgProcess.Name);
            Assert.AreEqual("NorthWind", bigBloatedProcess.Name);
        }
Example #5
0
        public void TestSingleInput()
        {
            var file1 = Path.GetTempFileName();

            File.WriteAllText(file1, "id,name\n1,one\n2,two\n3,three");

            var cfg = new ProcessBuilder("process")

                      .Connection("input1").Provider("file").File(file1).Delimiter(",").Start(2)
                      .Connection("output").Provider("internal")

                      .Entity("entity")
                      .Connection("input1")
                      .Field("id").Int32().PrimaryKey()
                      .Field("name")
                      .Process();

            var process = ProcessFactory.CreateSingle(cfg, new TestLogger());

            var output = process.Execute().ToArray();

            Assert.IsInstanceOf <IEnumerable <Row> >(output);
            Assert.AreEqual(3, output.Count());
            Assert.AreEqual(true, output.Any(r => r["id"].Equals(1)));
            Assert.AreEqual(true, output.Any(r => r["id"].Equals(2)));
            Assert.AreEqual(true, output.Any(r => r["id"].Equals(3)));
            Assert.AreEqual(true, output.Any(r => r["name"].Equals("one")));
            Assert.AreEqual(true, output.Any(r => r["name"].Equals("two")));
            Assert.AreEqual(true, output.Any(r => r["name"].Equals("three")));
        }
Example #6
0
        public void TestCopyFileToConnection()
        {
            var file1 = Path.GetTempFileName();

            File.WriteAllText(file1, "f1,f2,f3\nv1,v2,v3");

            var element = new ProcessBuilder("CopyFile")
                          .Connection("output")
                          .Provider("SqlServer")
                          .Database("TestOutput")
                          .Action("Copy")
                          .From(file1)
                          .To("output")
                          .Process();

            var process = ProcessFactory.CreateSingle(element, new TestLogger());

            process.ExecuteScaler();
            var expected  = Common.CleanIdentifier(Path.GetFileNameWithoutExtension(file1));
            var sqlServer = element.GetDefaultOf <TflConnection>(c => {
                c.Name     = "test";
                c.Provider = "sqlserver";
                c.Database = "TestOutput";
            }).Connection;

            var rows = sqlServer.GetConnection().Query(string.Format("SELECT f1, f2, f3 FROM {0}", expected)).ToArray();

            Assert.AreEqual(1, rows.Length);
            Assert.AreEqual("v1", rows[0].f1);
            Assert.AreEqual("v2", rows[0].f2);
            Assert.AreEqual("v3", rows[0].f3);
        }
Example #7
0
        public void OneOff()
        {
            const string file = @"https://fleet.scope-services.com/Transformalize/Api/Configuration/55";

            ProcessFactory.CreateSingle(file, new TestLogger(), new Options()
            {
                Mode = "init"
            }).ExecuteScaler();
            Assert.AreEqual(2, 2);
        }
Example #8
0
        public void TestError()
        {
            var cfg = new TflRoot(File.ReadAllText(@"C:\Temp\test.xml"), null);

            Assert.AreEqual(0, cfg.Errors().Length);

            var process = ProcessFactory.CreateSingle(@"C:\Temp\test.xml", new TestLogger());

            Assert.IsNotNull(process);

            process.ExecuteScaler();
        }
Example #9
0
        public void Test2()
        {
            var xml  = @"
<cfg>
    <processes>
        <add name='test'>
            <data-sets>
                <add name='one'>
                    <rows>
                        <add f1='1' f2='1' f3='2001-01-01' />
                        <add f1='2' f2='2' f3='2002-02-02' />
                        <add f1='3' f2='3' f3='2003-03-03' />
                    </rows>
                </add>
            </data-sets>

            <connections>
                <add name='input' provider='internal' />
                <add name='output' provider='internal' />
            </connections>

            <entities>
                <add name='one'>
                    <fields>
                        <add name='f1' primary-key='true' />
                        <add name='f2' type='int' />
                        <add name='f3' type='datetime' />
                    </fields>
                </add>
            </entities>
        </add>
    </processes>
</cfg>
".Replace("'", "\"");
            var root = new TflRoot(xml);

            var problems = root.Errors();

            foreach (var problem in problems)
            {
                Console.WriteLine(problem);
            }

            Assert.AreEqual(0, problems.Length);

            Assert.AreEqual(3, root.Processes.First().DataSets.First().Rows.Count);

            var rows = ProcessFactory.CreateSingle(root.Processes[0], new TestLogger()).Execute().ToList();

            Assert.AreEqual(3, rows.Count());
        }
Example #10
0
        public void TestCopyFile()
        {
            var file1 = Path.GetTempFileName();
            var file2 = Path.GetTempFileName();

            File.WriteAllText(file1, "f1,f2,f3\nv1,v2,v3");

            var process = new ProcessBuilder("CopyFile")
                          .Action("Copy")
                          .From(file1)
                          .To(file2)
                          .Process();

            ProcessFactory.CreateSingle(process, new TestLogger()).ExecuteScaler();

            Assert.AreEqual("f1,f2,f3\nv1,v2,v3", File.ReadAllText(file2));
        }
Example #11
0
        public void TestIntegratedEntityFilters()
        {
            const string xml     = @"<transformalize>
    <processes>
        <add name=""process"">
            <connections>
                <add name=""input"" database=""master"" />
            </connections>
            <entities>
                <add name=""entity"" version=""version"">
                    <filter>
                        <add left=""field1"" right=""literal1"" operator=""NotEqual"" continuation=""AND"" />
                        <add left=""field2"" right=""6"" operator=""GreaterThan"" continuation=""OR"" />
                        <add expression=""field3 != 'literal3'"" />
                    </filter>
                    <fields>
                        <add name=""field1"" primary-key=""true"" />
                        <add name=""field2"" type=""int"" />
                        <add name=""field3"" />
                        <add name=""version"" type=""byte[]"" length=""8"" />
                    </fields>
                </add>
            </entities>
        </add>
    </processes>
</transformalize>";
            var          process = ProcessFactory.CreateSingle(xml, new TestLogger());

            Assert.AreEqual("process", process.Name);
            Assert.AreEqual("entity", process.Entities.First().Name);

            var filters = process.Entities.First().Filters;

            Assert.AreEqual(3, filters.Count);
            Assert.AreEqual("field1 != 'literal1'", filters[0].ResolveExpression("'"));
            Assert.AreEqual("field2 > 6", filters[1].ResolveExpression("'"));
            Assert.AreEqual("field3 != 'literal3'", filters[2].ResolveExpression("'"));

            Assert.AreEqual("(field1 != 'literal1' AND field2 > 6 OR field3 != 'literal3')", filters.ResolveExpression("'"));

            var sql = process.Entities[0].Input[0].Connection.KeyAllQuery(process.Entities[0]);

            Assert.AreEqual(@"
                SELECT [field1] FROM [dbo].[entity] WHERE [field1] IS NOT NULL AND (field1 != 'literal1' AND field2 > 6 OR field3 != 'literal3')", sql);
        }
Example #12
0
        public ActionResult MetaData(int id)
        {
            Response.AddHeader("Access-Control-Allow-Origin", "*");
            ConfigurationPart part;
            ApiRequest        request;

            var query = _transformalize.GetQuery();

            foreach (var rejection in _apiService.Rejections(id, out request, out part))
            {
                return(rejection.ContentResult(
                           query["format"],
                           query["flavor"]
                           ));
            }

            request.RequestType = ApiRequestType.MetaData;
            var transformalizeRequest = new TransformalizeRequest(part, query, null, Logger);
            var logger = new TransformalizeLogger(transformalizeRequest.Part.Title(), part.LogLevel, Logger, OrchardVersion, _moduleVersion);

            var errors = transformalizeRequest.Root.Errors();

            if (errors.Any())
            {
                var bad = new TransformalizeResponse();
                request.Status  = 501;
                request.Message = "Configuration Problem" + errors.Length.Plural();
                bad.Log.AddRange(errors.Select(p => new[] { DateTime.Now.ToString(CultureInfo.InvariantCulture), "error", ".", ".", p }));
                return(new ApiResponse(request, "<tfl></tfl>", bad).ContentResult(
                           query["format"],
                           query["flavor"]
                           ));
            }

            var metaData = new MetaDataWriter(ProcessFactory.CreateSingle(transformalizeRequest.Root.Processes[0], logger, new Options {
                Mode = "metadata"
            })).Write();

            return(new ApiResponse(request, metaData).ContentResult(
                       query["format"],
                       query["flavor"]
                       ));
        }
Example #13
0
        public void TestCopyTemplateOutputToFile()
        {
            var template = Path.GetTempFileName();
            var file     = Path.GetTempFileName();

            File.WriteAllText(template, "Setting1: @Model.Parameters.Setting1, Setting2: @Model.Parameters.Setting2;");

            var process = new ProcessBuilder("TestCopyTemplateOutputToFile")
                          .Template("template")
                          .File(template)
                          .Parameter("Setting1", 1)
                          .Parameter("Setting2", 2)
                          .Action("Copy")
                          .To(file)
                          .Process();

            ProcessFactory.CreateSingle(process, new TestLogger()).ExecuteScaler();

            Assert.AreEqual("Setting1: 1, Setting2: 2;", File.ReadAllText(file));
        }
Example #14
0
        public void TestTwoInputs()
        {
            var file1 = Path.GetTempFileName();

            File.WriteAllText(file1, "id,name\n1,One\n2,Two\n3,Three");

            var file2 = Path.GetTempFileName();

            File.WriteAllText(file2, "id,name\n4,Four\n5,Five\n6,Six");

            var cfg = new ProcessBuilder("process")

                      .Connection("input1").Provider("file").File(file1).Delimiter(",").Start(2)
                      .Connection("input2").Provider("file").File(file2).Delimiter(",").Start(2)
                      .Connection("output").Provider("internal")
                      .Entity("entity")
                      .Input("i1", "input1")
                      .Input("i2", "input2")
                      .Field("id").Int32().PrimaryKey()
                      .Field("name")

                      .Process();

            var process = ProcessFactory.CreateSingle(cfg, new TestLogger());

            Assert.AreEqual(2, process.Entities.First().Input.Count);

            var output = process.Execute().ToArray();

            Assert.IsInstanceOf <IEnumerable <Row> >(output);

            foreach (var row in output)
            {
                Console.WriteLine(row);
            }

            Assert.AreEqual(6, output.Length);
            Assert.AreEqual(1 + 2 + 3 + 4 + 5 + 6, output.Sum(r => (int)r["id"]));
            Assert.AreEqual("OneTwoThreeFourFiveSix", string.Concat(output.OrderBy(r => (int)r["id"]).Select(r => r["name"])));
        }
Example #15
0
        public void TestMin()
        {
            var cfg = new ProcessBuilder("process")
                      .Connection("input").Provider(ProviderType.Internal)
                      .Connection("output").Provider(ProviderType.Internal)
                      .Entity("entity")
                      .Group() //group means you need to aggregate all output fields
                      .Field("order").Aggregate("group").Int32().PrimaryKey()
                      .Field("year").Aggregate("min")
                      .Field("int32").Aggregate("min").Int32()
                      .Field("int64").Aggregate("min").Int64()
                      .Field("guid").Aggregate("min").Type("guid")
                      .Field("bytes").Aggregate("min").Type("byte[]")
                      .Process();

            cfg.Entities.First().InputOperation = _testInput;

            var output = ProcessFactory.CreateSingle(cfg, new TestLogger()).Execute().ToArray();

            Assert.AreEqual(2, output.Length);

            var r1 = output[0];

            Assert.AreEqual(1, r1["order"]);
            Assert.AreEqual("2000", r1["year"]);
            Assert.AreEqual(2000, r1["int32"]);
            Assert.AreEqual(0, r1["int64"]);                                                 //because of null
            Assert.AreEqual(Guid.Parse("00000000-0000-0000-0000-000000000000"), r1["guid"]); // because of null
            Assert.AreEqual(new Byte[] { 0, 0, 0 }, r1["bytes"]);

            var r2 = output[1];

            Assert.AreEqual(2, r2["order"]);
            Assert.AreEqual("2000", r2["year"]);
            Assert.AreEqual(2000, r2["int32"]);
            Assert.AreEqual(2000, r2["int64"]);
            Assert.AreEqual(Guid.Parse("cd5cb6c8-4cbe-40c5-b17d-c17aee4196a2"), r2["guid"]);
            Assert.AreEqual(new Byte[] { 0, 0, 0 }, r2["bytes"]);
        }
Example #16
0
        public void TestMax()
        {
            var cfg = new ProcessBuilder("process")
                      .Connection("input").Provider(ProviderType.Internal)
                      .Connection("output").Provider(ProviderType.Internal)
                      .Entity("entity")
                      .Group() //group means you need to aggregate all output fields
                      .Field("order").Aggregate("group").Int32().PrimaryKey()
                      .Field("year").Aggregate("max")
                      .Field("int32").Aggregate("max").Int32()
                      .Field("int64").Aggregate("max").Int64()
                      .Field("guid").Aggregate("max").Type("guid")
                      .Field("bytes").Aggregate("max").Type("byte[]")
                      .Process();

            cfg.Entities.First().InputOperation = _testInput;

            var output = ProcessFactory.CreateSingle(cfg, new TestLogger()).Execute().ToArray();

            Assert.AreEqual(2, output.Length);

            var r1 = output[0];

            Assert.AreEqual(1, r1["order"]);
            Assert.AreEqual("2002", r1["year"]);
            Assert.AreEqual(2002, r1["int32"]);
            Assert.AreEqual(2002, r1["int64"]);
            Assert.AreEqual(Guid.Parse("e2cf0d95-1d29-4bed-9b31-ce5b5628466b"), r1["guid"]);
            Assert.AreEqual(new Byte[] { 0, 0, 2 }, r1["bytes"]);

            var r2 = output[1];

            Assert.AreEqual(2, r2["order"]);
            Assert.AreEqual("2000", r2["year"]);
            Assert.AreEqual(2000, r2["int32"]);
            Assert.AreEqual(2000, r2["int64"]);
            Assert.AreEqual(Guid.Parse("e2cf0d95-1d29-4bed-9b31-ce5b5628466b"), r2["guid"]);
            Assert.AreEqual(new Byte[] { 0, 0, 0 }, r2["bytes"]);
        }
Example #17
0
        public void DomainWithBranches()
        {
            var cfg = new ProcessBuilder("process")
                      .Connection("input").Provider(ProviderType.Internal)
                      .Connection("output").Provider(ProviderType.Internal)
                      .Entity("entity")
                      .Field("name")
                      .CalculatedField("is-dale")
                      .Type("bool")
                      .Transform("domain")
                      .Domain("Dale")
                      .Parameter("name")
                      .CalculatedField("new-name")
                      .Transform("copy")
                      .Parameter("name")
                      .Branch("DaleBranch")
                      .RunIf("is-dale", true)
                      .Transform("toUpper")
                      .Parameter("name")
                      .Branch("VladBranch")
                      .RunIf("is-dale", false)
                      .Transform("toLower")
                      .Parameter("name")

                      .Process();

            cfg.Entities[0].InputOperation = new RowsBuilder()
                                             .Row("name", "Dale")
                                             .Row("name", "Vlad")
                                             .Row("name", "Tara").ToOperation();

            var process = ProcessFactory.CreateSingle(cfg, new TestLogger());
            var output  = process.Execute().ToArray();

            Assert.AreEqual("DALE", output[0]["new-name"]);
            Assert.AreEqual("vlad", output[1]["new-name"]);
            Assert.AreEqual("tara", output[2]["new-name"]);
        }
Example #18
0
        public void Test1()
        {
            var data = new List <Dictionary <string, string> > {
                new Dictionary <string, string> {
                    { "f1", "1" }, { "f2", "1" }, { "f3", new DateTime(2001, 1, 1).ToString() }
                },
                new Dictionary <string, string> {
                    { "f1", "2" }, { "f2", "2" }, { "f3", new DateTime(2002, 2, 2).ToString() }
                },
                new Dictionary <string, string> {
                    { "f1", "3" }, { "f2", "3" }, { "f3", new DateTime(2003, 3, 3).ToString() }
                }
            };

            var process = new ProcessBuilder("test")
                          .DataSet("one", data)
                          .Entity("one")
                          .Field("f1").PrimaryKey()
                          .Field("f2").Type("int")
                          .Field("f3").Type("datetime")
                          .Process();

            var problems = process.Errors();

            foreach (var problem in problems)
            {
                Console.WriteLine(problem);
            }

            Assert.AreEqual(0, problems.Length);
            Assert.AreEqual(3, process.DataSets.First().Rows.Count);

            var rows = ProcessFactory.CreateSingle(process, new TestLogger()).Execute().ToList();

            Assert.AreEqual(3, rows.Count());
        }
Example #19
0
        public Fields Inspect(FileInformation fileInformation, FileInspectionRequest request)
        {
            var process = new TflRoot().GetDefaultOf <TflProcess>(p => {
                p.Name              = request.ProcessName;
                p.StarEnabled       = false;
                p.ViewEnabled       = false;
                p.PipelineThreading = "MultiThreaded";
            });

            process.Connections = new List <TflConnection> {
                process.GetDefaultOf <TflConnection>(c => {
                    c.Name      = "input";
                    c.Provider  = "file";
                    c.File      = fileInformation.FileInfo.FullName;
                    c.Delimiter = fileInformation.Delimiter == default(char)
                        ? "|"
                        : fileInformation.Delimiter.ToString(CultureInfo.InvariantCulture);
                    c.Start = fileInformation.FirstRowIsHeader ? 2 : 1;
                }),
                process.GetDefaultOf <TflConnection>(c => {
                    c.Name     = "output";
                    c.Provider = "internal";
                })
            };

            process.Entities.Add(process.GetDefaultOf <TflEntity>(e => {
                e.Name = request.EntityName;
                e.PrependProcessNameToOutputName = false;
                e.DetectChanges = false;
                e.Sample        = System.Convert.ToInt32(request.Sample);
            }));

            foreach (var fd in fileInformation.Fields)
            {
                var field = fd;
                process.Entities[0].Fields.Add(process.GetDefaultOf <TflField>(f => {
                    f.Name       = field.Name;
                    f.Length     = field.Length;
                    f.Type       = field.Type;
                    f.QuotedWith = field.QuotedWith;
                }));
            }

            for (var i = 0; i < request.DataTypes.Count; i++)
            {
                var dataType = request.DataTypes[i];
                foreach (var field in fileInformation.Fields)
                {
                    var result = IsDataTypeField(field.Name, dataType);
                    process.Entities[0].CalculatedFields.Add(
                        process.GetDefaultOf <TflField>(f => {
                        f.Name       = result;
                        f.Type       = "bool";
                        f.Input      = false;
                        f.Transforms = new List <TflTransform> {
                            f.GetDefaultOf <TflTransform>(t => {
                                t.Method      = "typeconversion";
                                t.Type        = dataType;
                                t.Parameter   = field.Name;
                                t.IgnoreEmpty = request.IgnoreEmpty;
                            })
                        };
                    })
                        );
                }
            }

            foreach (var field in fileInformation.Fields)
            {
                var result = LengthField(field.Name);
                process.Entities[0].CalculatedFields.Add(
                    process.GetDefaultOf <TflField>(f => {
                    f.Name       = result;
                    f.Type       = "int32";
                    f.Transforms = new List <TflTransform> {
                        f.GetDefaultOf <TflTransform>(t => {
                            t.Method    = "length";
                            t.Parameter = field.Name;
                        })
                    };
                })
                    );
            }

            var runner  = ProcessFactory.CreateSingle(new TflRoot(process).Processes[0], _logger);
            var results = runner.Execute().ToList();

            if (results.Count <= 0)
            {
                _logger.Warn("Nothing imported from in {0}!", fileInformation.FileInfo.Name);
                return(fileInformation.Fields);
            }

            foreach (var field in fileInformation.Fields)
            {
                if (!results.All(row => row[field.Name].Equals(string.Empty)))
                {
                    foreach (var dataType in request.DataTypes)
                    {
                        var result = IsDataTypeField(field.Name, dataType);
                        if (!results.All(row => row[result].Equals(true)))
                        {
                            continue;
                        }
                        field.Type   = dataType;
                        field.Length = request.MinLength.ToString(CultureInfo.InvariantCulture);
                        break;
                    }
                }
                if (!field.Type.Equals("string"))
                {
                    continue;
                }

                var length = results.Max(row => (int)row[LengthField(field.Name)]) + 1;
                if (request.MaxLength > 0 && length > request.MaxLength)
                {
                    length = request.MaxLength;
                }
                if (request.MinLength > 0 && length < request.MinLength)
                {
                    length = request.MinLength;
                }
                field.Length = length.ToString(CultureInfo.InvariantCulture);
            }
            return(fileInformation.Fields);
        }
Example #20
0
        private static Process GetTestProcess(string outputProvider)
        {
            var process = new ProcessBuilder("Test")
                          .StarEnabled(false)
                          .Connection("input").Provider("internal")
                          .Connection("output").Provider(outputProvider)
                          .Entity("OrderDetail")
                          .Schema("dbo")
                          .Field("OrderDetailId").PrimaryKey()
                          .Field("OrderId")
                          .Field("ProductId")
                          .Field("Price")
                          .Field("Quantity")
                          .Entity("Order")
                          .Schema("dbo")
                          .Field("OrderId").PrimaryKey()
                          .Field("CustomerId")
                          .Entity("Customer")
                          .Schema("dbo")
                          .Field("CustomerId").PrimaryKey()
                          .Field("FirstName")
                          .Field("LastName")
                          .Entity("Product")
                          .Schema("dbo")
                          .Field("ProductId").PrimaryKey()
                          .Field("Name").Alias("Product")
                          .Field("Description")
                          .Entity("ProductCategory")
                          .Schema("dbo")
                          .Field("ProductId").PrimaryKey()
                          .Field("CategoryId").PrimaryKey()
                          .Entity("Category")
                          .Schema("dbo")
                          .Field("CategoryId").PrimaryKey()
                          .Field("Name").Alias("Category")
                          .Relationship()
                          .LeftEntity("OrderDetail").LeftField("OrderId")
                          .RightEntity("Order").RightField("OrderId")
                          .Relationship()
                          .LeftEntity("Order").LeftField("CustomerId")
                          .RightEntity("Customer").RightField("CustomerId")
                          .Relationship()
                          .LeftEntity("OrderDetail").LeftField("ProductId")
                          .RightEntity("Product").RightField("ProductId")
                          .Relationship()
                          .LeftEntity("Product").LeftField("ProductId")
                          .RightEntity("ProductCategory").RightField("ProductId")
                          .Relationship()
                          .LeftEntity("ProductCategory").LeftField("CategoryId")
                          .RightEntity("Category").RightField("CategoryId")
                          .Process();

            process = new TflRoot(process).Processes[0];

            process.Entities[0].InputOperation = new RowsBuilder()
                                                 .Row("OrderDetailId", 1).Field("OrderId", 1).Field("ProductId", 1).Field("Quantity", 2).Field("Price", 2.0)
                                                 .Row("OrderDetailId", 2).Field("OrderId", 1).Field("ProductId", 2).Field("Quantity", 2).Field("Price", 3.0)
                                                 .Row("OrderDetailId", 3).Field("OrderId", 2).Field("ProductId", 2).Field("Quantity", 4).Field("Price", 3.0)
                                                 .ToOperation();

            process.Entities[1].InputOperation = new RowsBuilder()
                                                 .Row("OrderId", 1).Field("CustomerId", 1)
                                                 .Row("OrderId", 2).Field("CustomerId", 2)
                                                 .ToOperation();

            process.Entities[2].InputOperation = new RowsBuilder()
                                                 .Row("CustomerId", 1).Field("FirstName", "Dale").Field("LastName", "Newman")
                                                 .Row("CustomerId", 2).Field("FirstName", "Tara").Field("LastName", "Newman")
                                                 .ToOperation();

            process.Entities[3].InputOperation = new RowsBuilder()
                                                 .Row("ProductId", 1).Field("Name", "Beans").Field("Description", "Really nice beans.")
                                                 .Row("ProductId", 2).Field("Name", "Cheese").Field("Description", "Very sharp cheese.")
                                                 .ToOperation();

            process.Entities[4].InputOperation = new RowsBuilder()
                                                 .Row("ProductId", 1).Field("CategoryId", 1)
                                                 .Row("ProductId", 1).Field("CategoryId", 2)
                                                 .Row("ProductId", 2).Field("CategoryId", 3)
                                                 .ToOperation();

            process.Entities[5].InputOperation = new RowsBuilder()
                                                 .Row("CategoryId", 1).Field("Name", "Proteins")
                                                 .Row("CategoryId", 2).Field("Name", "Miracle Fruits")
                                                 .Row("CategoryId", 3).Field("Name", "Dairy")
                                                 .ToOperation();

            return(ProcessFactory.CreateSingle(process, new TestLogger()));
        }
Example #21
0
        public void TestBug()
        {
            var inventory        = GetInitialInventory();
            var storageLocations = GetInitialStorageLocations();
            var warehouses       = GetInitialWarehouses();
            var process          = GetInitialProcess(inventory, storageLocations, warehouses);

            //init and run
            var init = ProcessFactory.CreateSingle(process, new TestLogger(), new Options());

            init.Mode = "init";
            init.PipelineThreading = PipelineThreading.SingleThreaded;
            init.ExecuteScaler();

            var first = ProcessFactory.CreateSingle(process, new TestLogger(), new Options());

            first.PipelineThreading = PipelineThreading.SingleThreaded;
            first.ExecuteScaler();

            Assert.AreEqual(3, first["Inventory"].Inserts);
            Assert.AreEqual(2, first["StorageLocation"].Inserts);
            Assert.AreEqual(2, first["Warehouse"].Inserts);

            Assert.AreEqual(0, first["Inventory"].Updates);
            Assert.AreEqual(0, first["StorageLocation"].Updates);
            Assert.AreEqual(0, first["Warehouse"].Updates);

            inventory        = GetInitialInventory();
            storageLocations = GetInitialStorageLocations();
            warehouses       = GetInitialWarehouses();
            process          = GetInitialProcess(inventory, storageLocations, warehouses);

            //run again, no changes
            var second = ProcessFactory.CreateSingle(process, new TestLogger());

            second.PipelineThreading = PipelineThreading.SingleThreaded;
            second.ExecuteScaler();
            //LogManager.Flush();

            Assert.AreEqual(0, second["Inventory"].Inserts);
            Assert.AreEqual(0, second["StorageLocation"].Inserts);
            Assert.AreEqual(0, second["Warehouse"].Inserts);

            Assert.AreEqual(0, second["Inventory"].Updates);
            Assert.AreEqual(0, second["StorageLocation"].Updates);
            Assert.AreEqual(0, second["Warehouse"].Updates);

            //move Inventory 2 from Storage Location 1 to Storage Location 2
            process.Entities[0].InputOperation = new RowsBuilder()
                                                 .Row("InventoryKey", 1)
                                                 .Field("Name", "Inventory 1")
                                                 .Field("StorageLocationKey", 1)
                                                 .Row("InventoryKey", 2)
                                                 .Field("Name", "Inventory 2")
                                                 .Field("StorageLocationKey", 2) //here
                                                 .Row("InventoryKey", 3)
                                                 .Field("Name", "Inventory 3")
                                                 .Field("StorageLocationKey", 2)
                                                 .ToOperation();
            process.Entities[1].InputOperation = GetInitialStorageLocations();
            process.Entities[2].InputOperation = GetInitialWarehouses();

            //run again
            var third = ProcessFactory.CreateSingle(process, new TestLogger());

            third.PipelineThreading = PipelineThreading.SingleThreaded;
            third.ExecuteScaler();
            //LogManager.Flush();

            Assert.AreEqual(0, third["Inventory"].Inserts);
            Assert.AreEqual(0, third["StorageLocation"].Inserts);
            Assert.AreEqual(0, third["Warehouse"].Inserts);

            Assert.AreEqual(1, third["Inventory"].Updates);
            Assert.AreEqual(0, third["StorageLocation"].Updates);
            Assert.AreEqual(0, third["Warehouse"].Updates);
        }