packages feed

cqrs-test (empty) → 0.9.0

raw patch · 4 files changed

+125/−0 lines, 4 filesdep +HUnitdep +basedep +bytestringsetup-changed

Dependencies added: HUnit, base, bytestring, conduit, cqrs-types, hspec, pool-conduit, stm, transformers

Files

+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2011 Bardur Arantsson++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.lhs view
@@ -0,0 +1,4 @@+#! /usr/bin/env runhaskell++> import Distribution.Simple+> main = defaultMain
+ cqrs-test.cabal view
@@ -0,0 +1,28 @@+Name:                cqrs-test+Version:             0.9.0+Synopsis:            Command-Query Responsibility Segregation Test Support+Description:         Test Support for CQRS integration components.+License:             MIT+License-file:        LICENSE+Category:            Data+Cabal-version:       >=1.10+Build-type:          Simple+Author:              Bardur Arantsson+Maintainer:          Bardur Arantsson <bardur@scientician.net>++Library+  Build-Depends:       base == 4.*+                     , bytestring >= 0.9.0.1+                     , conduit >= 1.0 && < 2+                     , cqrs-types >= 0.9.0 && < 0.10.0+                     , pool-conduit >= 0.1 && < 0.2+                     , stm >= 2.4 && < 3+                     , transformers >= 0.2.2 && < 0.4+                     -- Test framework+                     , hspec >= 1.3 && < 2.0+                     , HUnit >= 1.2 && < 2.0+  Default-language:    Haskell2010+  Default-Extensions:  OverloadedStrings+  ghc-options:         -Wall+  hs-source-dirs:      src+  Exposed-modules:     Data.CQRS.Test.EventStore.BackendTest
+ src/Data/CQRS/Test/EventStore/BackendTest.hs view
@@ -0,0 +1,74 @@+module Data.CQRS.Test.EventStore.BackendTest+    ( testBackend+    ) where++import           Data.Conduit (runResourceT, ($$))+import qualified Data.Conduit.List as CL+import           Data.Conduit.Pool (Pool, withResource)+import           Data.CQRS.GUID+import           Data.CQRS.EventStore.Backend+import           Data.CQRS.PersistedEvent+import           Test.Hspec++-- Run tests with a clean slate.+withBackend :: (EventStoreBackend b) => IO (Pool b) -> (b -> IO a) -> IO a+withBackend mkPool a = do+  mkPool >>= (flip withResource) a++-- Test suite for memory backend.+testBackend :: (EventStoreBackend b) => IO (Pool b) -> IO () -> Spec+testBackend mkPool setup = do+  -- Bracket a test with a new event store backend pool.+  let bracket run = do+        setup+        withBackend mkPool run+  -- Examples+  describe "Event store backend" $ do++    it "should be able to retrieve stored events" $ bracket $ \b -> do+      g <- newGUID+      -- Write two events.+      let expectedEvents = [ PersistedEvent g "test event 1" 0+                           , PersistedEvent g "test event 2" 1+                           ]+      (esbStoreEvents b) g 0 expectedEvents+      -- Retrieve the stored events.+      actualEvents <- runResourceT (esbRetrieveEvents b g 0 $$ CL.consume)+      -- Assert that we've retrieved the expected events in order.+      actualEvents `shouldBe` expectedEvents++    it "should be able to enumerate all stored events" $ bracket $ \b -> do+      g1 <- newGUID+      g2 <- newGUID+      let pe1 = PersistedEvent g1 "test event 1" 0+      let pe2 = PersistedEvent g2 "test event 2" 0+      (esbStoreEvents b) g1 0 [ pe1 ]+      (esbStoreEvents b) g2 0 [ pe2 ]+      -- Retrieve the stored events.+      evs <- runResourceT (esbEnumerateAllEvents b $$ CL.consume)+      -- Assert that we've retrieved both events.+      length evs `shouldBe` 2+      (pe1 `elem` evs) `shouldBe` True+      (pe2 `elem` evs) `shouldBe` True++    it "writing first snapshot works" $ bracket $ \b -> do+      g <- newGUID+      -- Write the snapshot.+      let rs = (RawSnapshot 3 "Hello, world")+      esbWriteSnapshot b g rs+      -- Read the snapshot.+      rs' <- esbGetLatestSnapshot b g+      -- Assert that we've retrieved the right snapshot.+      rs' `shouldBe` Just rs++    it "updating snapshot overwrites existing one" $ bracket $ \b -> do+      g <- newGUID+      -- Write snapshot "twice"+      let rs1 = (RawSnapshot 3 "Hello")+      let rs2 = (RawSnapshot 4 "Goodbye")+      esbWriteSnapshot b g rs1+      esbWriteSnapshot b g rs2+      -- Read latest snapshot+      rs' <- esbGetLatestSnapshot b g+      -- Assert that the latter snapshot was retrieved+      rs' `shouldBe` Just rs2