Example #1
0
 def test_it_cannot_set_causation_id_twice(self):
     domain_event = EventA("0A919B3E-5BCB-41DC-B157-8A9E2A7198BE", "foo")
     domain_event.set_causation_id("6C28E7B7-61A1-432D-8778-DA94BE334969")
     with self.assertRaises(DomainEventException) as ex:
         domain_event.set_causation_id("4AFA7DC7-5268-4BE9-B065-27D19CE4DD5F")
     self.assertEqual(str(ex.exception), "Causation id can only be set once!")
Example #2
0
    def test_it_can_set_correct_causation_ids(self):
        """ test if SQLStore can deal properly with causation ids """
        store = SQLStore(self.__session)

        aggr_root = '897878D0-1230-408B-A980-7A9C24EBDEFA'
        event1 = EventA(aggr_root, 'my_prop')
        event1.set_aggregate_root_version(1)
        event2 = EventA(aggr_root, 'my_prop1')
        event2.set_aggregate_root_version(2)
        event3 = EventA(aggr_root, 'my_prop2')
        event3.set_aggregate_root_version(3)

        eventstream = [
            event1,
            event2,
            event3
        ]

        store.save(eventstream, aggr_root)

        # stored_eventstream: List[DomainEvent]
        stored_eventstream = store.load(aggr_root)

        event4 = EventA(aggr_root, 'my_prop')
        event4.set_aggregate_root_version(4)
        event4.set_causation_id(stored_eventstream[1].get_event_id())
        event5 = EventA(aggr_root, 'my_prop1')
        event5.set_aggregate_root_version(5)
        event5.set_causation_id(stored_eventstream[1].get_event_id())

        eventstream = [
            event4,
            event5
        ]

        store.save(eventstream, aggr_root)

        stored_eventstream = store.load(aggr_root)

        self.assertEqual(5, len(stored_eventstream))

        self.assertEqual(
            stored_eventstream[1].get_event_id(),
            stored_eventstream[2].get_causation_id()
        )

        self.assertEqual(
            aggr_root,
            stored_eventstream[2].get_correlation_id()
        )

        self.assertEqual(
            stored_eventstream[1].get_event_id(),
            stored_eventstream[3].get_causation_id()
        )

        self.assertEqual(
            aggr_root,
            stored_eventstream[3].get_correlation_id()
        )

        self.assertEqual(
            stored_eventstream[1].get_event_id(),
            stored_eventstream[4].get_causation_id()
        )

        self.assertEqual(
            aggr_root,
            stored_eventstream[4].get_correlation_id()
        )