 (deftest test-find-and-*
   (let [foo (create Simple {:value "Foo"})
         expected (merge foo {:age 21})]
-    (is (= expected
-           (find-and-modify Simple (where (eq :value "Foo"))
-                            (modify (set-fields {:age 21}))
-                            :return-new true)))
-    (is (= expected
-           (find-and-remove Simple (where (eq :value "Foo")))))))
+    (expect (find-and-modify Simple (where (eq :value "Foo"))
+                             (modify (set-fields {:age 21}))
+                             :return-new true)
+            => expected)
+    (expect (find-and-remove Simple (where (eq :value "Foo")))
+            => expected)))
 
 (deftest test-map-reduce
   (dotimes [n 5]
     (create Simple {:value n}))
-  (is (= [{:_id "sum" :value (apply + (range 5))}] 
-           (map-reduce-fetch-all Simple
-                                 "function() {emit('sum', this.value)}"
-                                 "function(k,vals) {
-                                                 var sum=0;
-                                                 for(var i in vals) sum += vals[i];
-                                                 return sum;
-                                              }"))))
+  (expect (map-reduce-fetch-all Simple
+                                "function() {emit('sum', this.value)}"
+                                "function(k,vals) {
+                                    var sum=0;
+                                    for(var i in vals) sum += vals[i];
+                                    return sum;
+                                 }")
+                  => [{:_id "sum" :value (apply + (range 5))}]))

  (let [jpmorgan (create Company {:name "JPMorgan Chase & Co." :date-founded "1799"})
        dell (create Company {:name "Dell" :date-founded (date 1984 11 4)})
        exxon (create Company {:name "Exxon" :date-founded "1911"})]
    (is (= [jpmorgan] (older-companies "1800")))
    (is (=  #{jpmorgan exxon} (set (older-companies "1913"))))
    (is (=  [exxon jpmorgan] (older-companies "1913" :sort [(asc :name)])))
    (is (=  [jpmorgan exxon dell]
              (older-companies "1999" :sort [(asc :date-founded)
                                             (asc :name)])))
    (is (=  [dell] (modern-companies)))))

(deftest test-deffetch-one
  (is (= {:company-by-name company-by-name}

                      :address {:city "Nashville"
                                :street {:number "123"
                                         :name "Main St."}}})]
    (expect (class (-> person :address)) => Address)
    (expect (class (-> person :address :street)) => Street)
    (expect (class (-> person :phones first))=> Phone))
  (let [person (make Person {:last-name "Smith"})
        phone (make Phone {})]
    (expect (keys person) => (in-any-order [:last-name :blood-alcohol-level]))
    (expect (:blood-alcohol-level person) =>  0.0)
    (expect (keys phone) => [:country-code])
    (expect (:country-code phone) => 1))
  (testing "preserves the metadata of original hash")
   (let [person (make Person #^{:meta "data"} {:first-name "Jimmy"})]
     (expect (meta person) => {:meta "data"})))

(defn remove-called [e] (dissoc e :called))

(deftest test-crud
  (let [person (remove-called (create Person
                                      {:first-name "John"
                                       :last-name "Smith"
                                       :birthday (date 1976 7 4)
                                       :phones [{:number "123" :country-code 2}]
                                       :address {:city "Nashville"
                                                 :street {:number "123"
                                                          :name "Main St."}}}))]
    (expect (class person) => Person)
    (expect (:birthday person) => "1976-07-04")
    (expect (:_id person) => not-nil?)
    (expect (collection-for Person) => (collection :people))
    (expect (collection-for Person) => (collection-for person))
    (expect (remove-called (fetch-one Person (where (eq :_id (:_id person)))))
            => person)
    (expect (remove-called (first (fetch-all Person)))
            => person)
    (expect (remove-called (first (fetch Person (where (eq :last-name "Smith")))))
            => person)
    (expect (count-instances Person) => 1)
    (dotimes [x 5]
      (create Person {:first-name "John" :last-name (str "Smith" (inc x))}))
    (expect (first (distinct-values Person :first-name)) => "John")
    (expect (count-instances Person) => 6)
    (delete person)
    (expect (count-instances Person) => 5)
    (delete-all Person (where (eq :last-name "Smith1")))
    (expect (count-instances Person) => 4)
    (delete-all Person)
    (expect (count-instances Person) => 0)))

(deftest test-callback-protocol
  (are [callback e] (= e (callback e))
