public void Save()
        {
            using (var ds = new DAL())
            {
                ds.Insert(new CuttingUnitDO()
                {
                    Code = "u1", CuttingUnit_CN = 1
                });
                ds.Insert(new StratumDO()
                {
                    Code = "st1", Stratum_CN = 1, Method = "something"
                });
                ds.Insert(new SampleGroupDO()
                {
                    Code = "sg1", SampleGroup_CN = 1, Stratum_CN = 1, CutLeave = "Something", UOM = "bla", PrimaryProduct = "wha"
                });

                var tree_guid_1 = Guid.NewGuid();

                var tree = new TreeDO(ds)
                {
                    CuttingUnit_CN = 1,
                    Stratum_CN     = 1,
                    SampleGroup_CN = 1,
                    TreeNumber     = 1,
                    Tree_GUID      = tree_guid_1
                };
                tree.Save();

                var trees = ds.From <TreeDO>().Query().ToArray();
                trees.Should().HaveCount(1);
                var treeAgain = trees.Single();
                treeAgain.Should().BeEquivalentTo(tree, config => config
                                                  .Excluding(x => x.CreatedBy)
                                                  .Excluding(x => x.CreatedDate)
                                                  .Excluding(x => x.ModifiedBy)
                                                  .Excluding(x => x.ModifiedDate)
                                                  .Excluding(x => x.Self));

                tree.DBH = 101;
                tree.Save();

                trees = ds.From <TreeDO>().Query().ToArray();
                trees.Should().HaveCount(1);
                treeAgain = trees.Single();
                treeAgain.Should().BeEquivalentTo(tree, config => config
                                                  .Excluding(x => x.CreatedBy)
                                                  .Excluding(x => x.CreatedDate)
                                                  .Excluding(x => x.ModifiedBy)
                                                  .Excluding(x => x.ModifiedDate)
                                                  .Excluding(x => x.Self));
            }
        }
        public void ReadUnitLevelCruisersTest()
        {
            using (var ds = CreateDataStore())
            {
                var unitLevelInitialsEmpty = IDataEntryDataService.ReadUnitLevelCruisers(ds);

                unitLevelInitialsEmpty.Should().NotBeNull();
                unitLevelInitialsEmpty.Should().BeEmpty();

                var initialsRaw      = new string[] { " ", "", "A", "AB", " C " };
                var initialsExpected = new string[] { "A", "AB", "C" };

                var cuttingUnit = ds.From <CuttingUnitDO>().Query().First();
                var stratum     = ds.From <StratumDO>().Query().First();

                long j = 0;
                foreach (var initial in initialsRaw)
                {
                    var tree = new TreeDO()
                    {
                        DAL         = ds,
                        CuttingUnit = cuttingUnit,
                        Stratum     = stratum,
                        TreeNumber  = ++j,
                        Initials    = initial
                    };

                    tree.Save();
                }

                var unitLevelInitials = IDataEntryDataService.ReadUnitLevelCruisers(ds);

                unitLevelInitials.Should().Contain(initialsExpected);
            }
        }
        DAL CreateDataStore(string salePurpose = null, string saleRegion = "01", IEnumerable <string> methods = null)
        {
            methods = methods ?? new string[] { CruiseMethods.STR, CruiseMethods.FIX };

            var ds = new DAL();

            var sale = new SaleDO()
            {
                DAL        = ds,
                SaleNumber = "12345",
                Region     = saleRegion,
                Forest     = "11",
                District   = "something",
                Purpose    = salePurpose
            };

            sale.Save();

            var cuttingUnit = new CuttingUnitDO()
            {
                DAL  = ds,
                Code = "01"
            };

            cuttingUnit.Save();

            var tdv = new TreeDefaultValueDO()
            {
                DAL            = ds,
                Species        = "something",
                PrimaryProduct = "something",
                LiveDead       = "L"
            };

            tdv.Save();

            int counter = 0;

            foreach (var method in methods)
            {
                var stratum = new StratumDO()
                {
                    DAL    = ds,
                    Code   = counter++.ToString("d2"),
                    Method = method
                };
                stratum.Save();
                stratum.CuttingUnits.Add(cuttingUnit);
                stratum.CuttingUnits.Save();

                var sg = new SampleGroupDO()
                {
                    DAL            = ds,
                    Code           = 1.ToString("d2"),
                    Stratum        = stratum,
                    CutLeave       = "C",
                    UOM            = "something",
                    PrimaryProduct = "something"
                };
                sg.Save();
                sg.TreeDefaultValues.Add(tdv);
                sg.TreeDefaultValues.Save();

                if (CruiseMethods.PLOT_METHODS.Contains(method))
                {
                    var plot = new PlotDO()
                    {
                        DAL = ds, Stratum = stratum, CuttingUnit = cuttingUnit, PlotNumber = 1
                    };
                    plot.Save();

                    var tree = new TreeDO()
                    {
                        DAL              = ds,
                        CuttingUnit      = cuttingUnit,
                        Stratum          = stratum,
                        Plot             = plot,
                        SampleGroup      = sg,
                        TreeDefaultValue = tdv,
                        TreeNumber       = 1
                    };
                    tree.Save();
                }
                else
                {
                    var tree = new TreeDO()
                    {
                        DAL              = ds,
                        CuttingUnit      = cuttingUnit,
                        Stratum          = stratum,
                        SampleGroup      = sg,
                        TreeDefaultValue = tdv,
                        TreeNumber       = 1
                    };
                    tree.Save();
                }

                var countTree = new CountTree()
                {
                    CuttingUnit_CN      = cuttingUnit.CuttingUnit_CN,
                    SampleGroup_CN      = sg.SampleGroup_CN,
                    TreeDefaultValue_CN = tdv.TreeDefaultValue_CN,
                };

                ds.Save(countTree);
            }

            return(ds);
        }
Example #4
0
        public DAL CreateDataStore(int treesToCreate, int numLogToCreate)
        {
            var ds = new DAL();

            try
            {
                var stratum = new StratumDO()
                {
                    DAL    = ds,
                    Code   = "01",
                    Method = "something"
                };

                stratum.Save();


                //set up the log fields
                int counter        = 1;
                var logFieldSetups = CruiseDAL.Schema.LOG._ALL
                                     .Select(x => new LogFieldSetupDO()
                {
                    DAL = ds, Field = x, FieldOrder = counter++, Heading = x, Stratum = stratum
                })
                                     .ToList();

                foreach (var lfs in logFieldSetups)
                {
                    lfs.Save();
                }

                var cuttingUnit = new CuttingUnitDO()
                {
                    DAL  = ds,
                    Code = "01"
                };

                cuttingUnit.Save();

                for (int j = 0; j < treesToCreate; j++)
                {
                    var tree = new TreeDO()
                    {
                        DAL         = ds,
                        CuttingUnit = cuttingUnit,
                        Stratum     = stratum,
                        TreeNumber  = j + 1
                    };

                    tree.Save();

                    for (int i = 0; i < numLogToCreate; i++)
                    {
                        var log = new LogDO()
                        {
                            DAL       = ds,
                            LogNumber = (i + 1).ToString(),
                            Tree      = tree,
                        };

                        log.Save();
                    }
                }

                return(ds);
            }
            catch
            {
                ds.Dispose();
                throw;
            }
        }
Example #5
0
        public void FailWhenNoConnection()
        {
            string path = "doesNotExist.cruise";

            Exception ex = null;
            try
            {
                DAL target = new DAL(path);
                TreeDO t = new TreeDO(target);
                t.Save();
            }
            catch (FileNotFoundException e)
            {
                ex = e;
            }
            Assert.True(ex != null, "Save should fail when dal trys to access a file that hasn't been created");
        }