Exemplo n.º 1
0
        public void TestGetPrimaryMetadataForEveryone()
        {
            // Blow away excessive nychanis data.
            FastDAO <NycDatum> dataDao = new FastDAO <NycDatum>("PDP.Data", "NYCHANIS");
            DaoCriteria        crit    = new DaoCriteria();

            crit.Expressions.Add(new EqualExpression("IndicatorId", 201, false));
            crit.Expressions.Add(new GreaterExpression("IndicatorId", 10));
            dataDao.Delete(crit);

            // And also excessive PDB data.
            PdbTwoTableHelper helper = new PdbTwoTableHelper(Config.GetConfig("PDP.Data"), "Properties",
                                                             PdbEntityType.Properties);
            DictionaryDao primaryPdbDao = new DictionaryDao(
                dataDao.ConnDesc, helper.GetClassMapForPrimaryTable(new SecurityRole[] { SecurityRole.@public }));
            FastDAO <PdbSecondaryTableProperty> secondaryPdbDao = new FastDAO <PdbSecondaryTableProperty>(
                dataDao.ConnDesc, helper.GetClassMapForSecondaryTable());

            crit.Expressions.Clear();
            crit.Expressions.Add(new GreaterExpression("UID", 100630));
            primaryPdbDao.Delete(crit);
            crit.Expressions.Clear();
            crit.Expressions.Add(new GreaterExpression("ForeignKey", 100630));
            secondaryPdbDao.Delete(crit);
        }
        public static IList <T> GetRows <T>(string nlihcId, IList <SecurityRole> roles)
            where T : class, IDisplaySortable, new()
        {
            var dao       = new FastDAO <T>(Config.GetConfig("PDP.Data"), "PDB");
            var crit      = new DaoCriteria(new EqualExpression("NlihcId", nlihcId));
            var sortField = Activator.CreateInstance <T>().GetSortField();

            crit.Orders.Add(new SortOrder(sortField, SortType.Desc));
            return(DisplayForRole(ResourceMap[typeof(T)], roles) ? dao.Get(crit) : null);
        }
Exemplo n.º 3
0
 public void SetUp()
 {
     try
     {
         _ncdao = new FastDAO<NullableClass>(new Config("..\\..\\Tests\\PostgreSqlDao.config", "PostgreSqlDaoConfig"), "DAO");
         AbstractFastDAOTests.ResetTable(_ncdao.DataAccessLayer, _ncdao.ClassMap);
     }
     catch (Exception e)
     {
         string message = "ERROR: Exception while setting up PostGIS Nullable tests: " + e;
         Console.WriteLine(message);
         Assert.Fail(message);
     }
 }
Exemplo n.º 4
0
 public void SetUp()
 {
     try
     {
         _polyDao = new FastDAO<PolyClass>(new Config("..\\..\\Tests\\PostgreSqlDao.config", "PostgreSqlDaoConfig"), "DAO");
         _lineDao = new FastDAO<LineClass>(new Config("..\\..\\Tests\\PostgreSqlDao.config", "PostgreSqlDaoConfig"), "DAO");
         _pointDao = new FastDAO<PointClass>(new Config("..\\..\\Tests\\PostgreSqlDao.config", "PostgreSqlDaoConfig"), "DAO");
         SetupPoints();
         SetupLines();
         SetupPolys();
     }
     catch (Exception e)
     {
         string message = "ERROR: Exception while setting up PostGIS DAO tests: " + e;
         Console.WriteLine(message);
         Assert.Fail(message);
     }
 }
Exemplo n.º 5
0
 private static void AssertMissingColumns(ClassMapping mapping, string fieldName, object uninitVal)
 {
     FastDAO<CsvTestObj> dao = new FastDAO<CsvTestObj>(
         new CsvDescriptor(CsvConnectionType.Directory, "..\\..\\Tests\\"), mapping);
     DictionaryDao dictDao = new DictionaryDao(
         new CsvDescriptor(CsvConnectionType.Directory, "..\\..\\Tests\\"), mapping);
     IList<CsvTestObj> objs = dao.Get();
     IList<CheckedDictionary<string, object>> dicts = dictDao.Get();
     Assert.AreEqual(12, objs.Count, "Wrong number of real objects.");
     Assert.AreEqual(12, dicts.Count, "Wrong number of dictionaries.");
     for (int x = 0; x < objs.Count; x++)
     {
         object val;
         switch (fieldName)
         {
             case "One":
                 val = objs[x].One;
                 break;
             case "Two":
                 val = objs[x].Two;
                 break;
             case "Three":
                 val = objs[x].Three;
                 break;
             case "Four":
                 val = objs[x].Four;
                 break;
             case "Five":
                 val = objs[x].Five;
                 break;
             default:
                 throw new ArgumentException("Field " + fieldName + " isn't handled yet.", "fieldName");
         }
         Assert.AreEqual(uninitVal, val, "Field '" + fieldName + "' should be uninitialized because it is unmapped, but isn't.");
         Assert.IsFalse(dicts[x].ContainsKey(fieldName), "Field '" + fieldName + "' should not be in the dictionary because it is unmapped.");
     }
 }
Exemplo n.º 6
0
        public void TestWriteCsv()
        {
            CsvTestObj testObj1 = new CsvTestObj();
            CheckedDictionary<string, object> testDict1 = new CheckedDictionary<string, object>();
            testObj1.One = 50;
            testObj1.Two = -1.0;
            testObj1.Three = "Yo";
            testObj1.Four = new DateTime(2001, 1, 1, 1, 1, 1);
            testObj1.Five = null;
            testDict1["One"] = testObj1.One;
            testDict1["Two"] = testObj1.Two;
            testDict1["Three"] = testObj1.Three;
            testDict1["Four"] = testObj1.Four;
            testDict1["Five"] = testObj1.Five;

            CsvTestObj testObj2 = new CsvTestObj();
            CheckedDictionary<string, object> testDict2 = new CheckedDictionary<string, object>();
            testObj2.One = int.MaxValue;
            testObj2.Two = double.MinValue;
            testObj2.Three = null;
            testObj2.Four = DateTime.MinValue;
            testObj2.Five = "";
            testDict2["One"] = testObj2.One;
            testDict2["Two"] = testObj2.Two;
            testDict2["Three"] = testObj2.Three;
            testDict2["Four"] = testObj2.Four;
            testDict2["Five"] = testObj2.Five;

            ClassMapping mapping1 = MakeMapping("n/a", "WriteOne", true);
            CsvDescriptor desc1 = new CsvDescriptor("..\\..\\Tests");
            DictionaryDao dao1 = new DictionaryDao(desc1, mapping1);
            dao1.Truncate();
            dao1.Insert(testDict1);
            dao1.Insert(testDict2);

            ClassMapping mapping2 = MakeMapping("Azavea.Open.DAO.CSV.Tests.CsvTestObj,Azavea.Open.DAO.CSV", "Doesn'tMatter", true);
            CsvDescriptor desc2 = new CsvDescriptor(CsvConnectionType.FileName,
                                                    "..\\..\\Tests\\WriteTwo.csv");
            FastDAO<CsvTestObj> dao2 = new FastDAO<CsvTestObj>(desc2, mapping2);
            dao2.Truncate();
            dao2.Insert(testObj1);
            dao2.Insert(testObj2);

            ClassMapping mapping3 = MakeMapping("n/a", "AlsoDoesn'tMatter", true);
            using (StreamWriter sw = new StreamWriter("..\\..\\Tests\\WriteThree.csv", false))
            {
                CsvDescriptor desc3 = new CsvDescriptor(sw);
                DictionaryDao dao3 = new DictionaryDao(desc3, mapping3);
                // Can't truncate this one.
                dao3.Insert(testDict1);
                dao3.Insert(testDict2);
            }

            ClassMapping mapping4 = MakeMapping("n/a", "WriteFour", false);
            CsvDescriptor desc4 = new CsvDescriptor("..\\..\\Tests");
            DictionaryDao dao4 = new DictionaryDao(desc4, mapping4);
            dao4.Truncate();
            dao4.Insert(testDict1);
            dao4.Insert(testDict2);

            ClassMapping mapping5 = MakeMapping("Azavea.Open.DAO.CSV.Tests.CsvTestObj,Azavea.Open.DAO.CSV", "Doesn'tMatter", false);
            CsvDescriptor desc5 = new CsvDescriptor(CsvConnectionType.FileName,
                                                    "..\\..\\Tests\\WriteFive.csv");
            FastDAO<CsvTestObj> dao5 = new FastDAO<CsvTestObj>(desc5, mapping5);
            dao5.Truncate();
            dao5.Insert(testObj1);
            dao5.Insert(testObj2);

            ClassMapping mapping6 = MakeMapping("n/a", "AlsoDoesn'tMatter", false);
            using (StreamWriter sw = new StreamWriter("..\\..\\Tests\\WriteSix.csv", false))
            {
                CsvDescriptor desc6 = new CsvDescriptor(sw);
                DictionaryDao dao6 = new DictionaryDao(desc6, mapping6);
                // Can't truncate this one.
                dao6.Insert(testDict1);
                dao6.Insert(testDict2);
            }

            // Now, assert they are all correct.  1, 2, and 3 should be the same (they have headers)
            // and 4, 5, and 6 should be the same (without headers).
            AssertFileContentsSame("..\\..\\Tests\\WriteOne.csv", "..\\..\\Tests\\WriteTwo.csv");
            AssertFileContentsSame("..\\..\\Tests\\WriteOne.csv", "..\\..\\Tests\\WriteThree.csv");
            AssertFileGreater("..\\..\\Tests\\WriteOne.csv", "..\\..\\Tests\\WriteFour.csv");
            AssertFileContentsSame("..\\..\\Tests\\WriteFour.csv", "..\\..\\Tests\\WriteFive.csv");
            AssertFileContentsSame("..\\..\\Tests\\WriteFour.csv", "..\\..\\Tests\\WriteFive.csv");
        }
Exemplo n.º 7
0
 public void SetUp()
 {
     var config = new Config("..\\..\\Tests\\dao.config", "DaoConfig");
     _pointDao = new FastDAO<PointClass>(config, "SpatialDao");
     _lineDao = new FastDAO<LineClass>(config, "SpatialDao");
     _polyDao = new FastDAO<PolyClass>(config, "SpatialDao");
     SetupPoints();
     SetupLines();
     SetupPolys();
 }