Пример #1
0
 def test_dispatch_sync_without_behavior(self):
     Mediator.register_handler(get_array_handler_sync)
     Mediator.register_handler(GetArrayQueryHandler)
     mediator = Mediator()
     query1 = GetArrayQuery(5)
     result1 = mediator.send(query1)
     self.assertEqual(len(result1), 5)
Пример #2
0
 def test_get_array_query_handler(self):
     ioloop = asyncio.get_event_loop()
     Mediator.register_handler(get_array_handler)
     mediator = Mediator()
     query = GetArrayQuery(5)
     result = ioloop.run_until_complete(mediator.send_async(query))
     array_count = len(result)
     self.assertEqual(5, array_count)
Пример #3
0
 def test_get_array_query_handler_with_behavior(self):
     ioloop = asyncio.get_event_loop()
     Mediator.register_handler(get_array_handler)
     Mediator.register_behavior(get_array_query_behavior)
     Mediator.register_behavior(get_array_query_behavior_3)
     mediator = Mediator()
     query = GetArrayQuery(5)
     self.assertEqual(query.items_count, 5)
     result = ioloop.run_until_complete(mediator.send_async(query))
     self.assertEqual(query.items_count, 3)
     array_count = len(result)
     self.assertEqual(3, array_count)
Пример #4
0
 async def test_dispatch_sync(self):
     Mediator.register_handler(get_array_handler_sync)
     Mediator.register_handler(GetArrayQueryHandler)
     Mediator.register_behavior(common_log_behavior)
     mediator = Mediator()
     query1 = GetArrayQuery(5)
     result1 = mediator.send(query1)
     self.assertEqual(len(result1), 5)
     self.assertIsNotNone(query1.updated_at)
     query2 = GetArrayQuery1(4)
     result2 = mediator.send(query2)
     self.assertEqual(len(result2), 4)
     self.assertIsNotNone(query2.updated_at)
Пример #5
0
 def test_1(self):
     Mediator.register_handler(get_array_handler)
     Mediator.register_handler(GetArrayQueryHandler)
     Mediator.register_behavior(common_log_behavior)
     mediator = Mediator()
     query1 = GetArrayQuery(5)
     result1 = self.ioloop.run_until_complete(mediator.send_async(query1))
     self.assertEqual(len(result1), 5)
     self.assertIsNotNone(query1.updated_at)
     query2 = GetArrayQuery1(4)
     result2 = self.ioloop.run_until_complete(mediator.send_async(query2))
     self.assertEqual(len(result2), 4)
     self.assertIsNotNone(query2.updated_at)
Пример #6
0
    def test_first(self):

        Mediator.register_handler(get_array_handler_sync)
        Mediator.register_handler(GetArrayQueryHandler)
        Mediator.register_handler(QueryWithTypedResponseHandler)
        Mediator.register_behavior(common_log_behavior)
        Mediator.register_behavior(print_before)

        query1 = GetArrayQuery(5)
        result1 = Mediator.send(query1)
        self.assertEqual(len(result1), 5)
        self.assertIsNotNone(query1.updated_at)
        query2 = GetArrayQuery1(4)
        result2 = Mediator.send(query2)
        self.assertEqual(len(result2), 4)
        self.assertIsNotNone(query2.updated_at)
        self.assertEqual(query1.updated_at, '123')
        self.assertEqual(query2.updated_at, '123')
        self.assertTrue(query2.common_bahavior_handled)
Пример #7
0
async def get_array_query_behavior_3(request: GetArrayQuery, next):
    request.items_count = 3
    return await next()
Пример #8
0
def get_array_query_behavior(request: GetArrayQuery, next):
    request.items_count = 4
    return next()