public void Assoc_ExistingKey()
 {
     var dict = new Dictionary<string, int>();
     dict.Add("a", 1);
     var res = dict.Assoc("a", 2);
     Assert.AreEqual("([a,2])", res.Print());
 }
 public void Assoc_IsImmutable()
 {
     var dict = new Dictionary<string, int>();
     dict.Add("a", 1);
     var other = dict.Assoc("b", 2);
     Assert.AreEqual("([a,1])", dict.Print(),
         "Calling Assoc should not change the original dictionary");
 }
        public void Diff()
        {
            var a = new Dictionary<string, int>() { { "A", 1 }, { "B", 2 }, {"C", 3}};
            var b = a.Assoc("B", -2);

            var diff = a.Diff(b);
            Assert.AreEqual("([B,(2, -2)])", diff.Print());

            diff = a.Diff(b, "A".And("B"));
            Assert.AreEqual("([B,(2, -2)])", diff.Print());

            diff = a.Diff(b, "A".And("C"));
            Assert.AreEqual("()", diff.Print());

            var copyA = a.Copy();
            diff = a.Diff(copyA);
            Assert.AreEqual("()", diff.Print());
        }
Example #4
0
        public virtual Dictionary<string, object> Insert(string tableName, Dictionary<string, object> row)
        {
            if (StrictTables && !Analyzer.TableExists(tableName))
                throw new NotATableException(tableName);

            // Make sure all the required keys are supplied
            this.AssertInsertKeys(tableName, row);

            var sql = MakeInsertSql(tableName, row);
            var autoKey = sqlInsert(sql, row);

            // If there's an autonumber, make sure we add it to the result
            var autoNumberKeyName = Analyzer.GetAutoNumberKey(tableName);
            //if (autoNumberKeyName != null && autoKey == null)
            //    throw new ThisSadlyHappenedException("The SQL ran beautifully, but you were expecting an autogenerated number and you did not get it");
            if(autoNumberKeyName != null && autoKey.HasValue)
                row = row.Assoc(autoNumberKeyName, autoKey.Value);

            // Return the set of primary keys from the insert operation
            var primaryKeys = Analyzer.GetPrimaryKeys(tableName);
            return row.Only(primaryKeys);
        }
        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!");
        }