Exemplo n.º 1
0
        public IEnumerable<Dictionary<string, object>> RawRead(string tableName, Dictionary<string, object> keyFields, IEnumerable<string> fields)
        {
            fields = fields ?? new string[] { };
            keyFields = keyFields ?? new Dictionary<string, object>();

            var table = getTable(tableName);
            var rows = table.Select(d => convertRow(d));
            if(keyFields.Any())
                rows = rows.Where(r => keyFields.IsSameAs(r));

            if (fields.Any())
                return rows.Select(r => r.Only(fields)).ToList();
            else
                return rows.ToList(); ;
        }
Exemplo n.º 2
0
        public void IsSameAsWithComparer()
        {
            var a = new Dictionary<string, object>();
            var b = new Dictionary<string, object>();
            var c = new Dictionary<string, object>();
            a.Add("A", null);
            b.Add("A", DBNull.Value);
            c.Add("A", "");
            Assert.False(a.IsSameAs(b));
            Assert.False(a.IsSameAs(b, a.Keys, ObjectExtensions.LazyEq));
            Assert.False(a.IsSameAs(c));
            Assert.False(a.IsSameAs(c, a.Keys, ObjectExtensions.LazyEq));

            // Conflate null and DBNull.
            Func<object, object, bool> Comparer = (x, y) =>
            {
                x = (x == DBNull.Value ? null : x);
                y = (y == DBNull.Value ? null : y);
                if (x == null && y != null)
                    return false;
                else if (x != null && y == null)
                    return false;
                else if (x.Neq(y))
                    return false;
                return true;
            };
            Assert.True(a.IsSameAs(b, a.Keys, Comparer));
            Assert.False(a.IsSameAs(c, a.Keys, Comparer));

            // Conflate null and DBNull and "".
            Comparer = (x, y) =>
            {
                x = (x == DBNull.Value || x == "" ? null : x);
                y = (y == DBNull.Value || y == "" ? null : y);
                if (x == null && y != null)
                    return false;
                else if (x != null && y == null)
                    return false;
                else if (x.Neq(y))
                    return false;
                return true;
            };
            Assert.True(a.IsSameAs(c, a.Keys, Comparer));
        }
Exemplo n.º 3
0
 public void IsSameAsParams()
 {
     var dict = new Dictionary<string, int>()
         { { "Key 1", 1 }, { "Key 2", 2 }, { "Key 3", 3 } };
     Dictionary<string, int> dictCopy = new Dictionary<string, int>()
         { { "Key 1", 1 }, { "Key 2", 5 }, { "Key 3", 3 } };
     string[] keysToCheck = { "Key 1", "Key 3" };
     Assert.AreEqual(false, dict.IsSameAs(dictCopy));
     Assert.AreEqual(true, dict.IsSameAs(dictCopy, keysToCheck));
 }
Exemplo n.º 4
0
        public void IsSameAsNullBug()
        {
            // If we have two objects that both have a null field, but the objects have differences
            // on other fields after that field, IsSameAs falsely returns true
            var a = new Dictionary<string, object>() { { "A", 1 }, { "B", null }, { "C", 3 } };
            var b = a.Assoc("C", 47);

            Assert.False(a.IsSameAs(b), "These are not the same!");
        }
Exemplo n.º 5
0
 public void IsSameAsDifferentTypes()
 {
     var a = new Dictionary<string, object>();
     var b = new Dictionary<string, object>();
     a.Add("A", 1);
     b.Add("A", "1");
     Assert.False(a.IsSameAs(b));
     Assert.True(a.IsSameAs(b, a.Keys, ObjectExtensions.LazyEq));
 }
Exemplo n.º 6
0
 public void IsSameAs()
 {
     Dictionary<int, int> dict = new Dictionary<int, int>();
     dict.Add(1, 1);
     dict.Add(2, 2);
     dict.Add(3, 3);
     Dictionary<int, int> dictCopy = new Dictionary<int, int>();
     dictCopy.Add(1, 1);
     dictCopy.Add(2, 2);
     dictCopy.Add(3, 3);
     Dictionary<int, int> dictOther = new Dictionary<int, int>();
     dictOther.Add(1, 3);
     dictOther.Add(7, 2);
     dictOther.Add(3, 9);
     Assert.AreEqual(true, dict.IsSameAs(dictCopy));
     Assert.AreEqual(false, dict.IsSameAs(dictOther));
 }