def test_first(self): mediator = Mediator() Mediator.register_handler(QueryWithTypedResponseHandler) genericQuery = QueryWithTypedResponse(name="mediatr 123") respModel = mediator.send(genericQuery) self.assertEqual(genericQuery.some_name, respModel.some_name)
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)
def test_1(self): from tests.example_handlers_annotations import GetArrayQueryHandlerWithAnnotations from tests.example_queries import GetArrayQueryWithAnnotations Mediator.register_handler(GetArrayQueryHandlerWithAnnotations) query = GetArrayQueryWithAnnotations(5) self.assertEqual(query.items_count, 5) result = self.ioloop.run_until_complete( self.mediator.send_async(query)) self.assertEqual(query.items_count, 5) array_count = len(result) self.assertEqual(5, array_count)
def test_1(self): class Client: def test_1(self): return 'test_3' get_array_query_handler_with_constructor = GetArrayQueryHandlerWithConstructor(Client) Mediator.register_handler(get_array_query_handler_with_constructor) query = GetArrayQueryWithConstructor(5) self.assertEqual(query.items_count, 5) result = self.ioloop.run_until_complete(self.mediator.send_async(query)) self.assertEqual(query.items_count, 5) array_count = len(result) self.assertEqual(5, array_count)
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)
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)
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)
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)
class ClassHandlersTest(unittest.TestCase): def setUp(self): self.mediator = Mediator(setup_class_handler_manager) self.ioloop = asyncio.get_event_loop() return super().setUp() def test_1(self): class Client: def test_1(self): return 'test_3' get_array_query_handler_with_constructor = GetArrayQueryHandlerWithConstructor(Client) Mediator.register_handler(get_array_query_handler_with_constructor) query = GetArrayQueryWithConstructor(5) self.assertEqual(query.items_count, 5) result = self.ioloop.run_until_complete(self.mediator.send_async(query)) self.assertEqual(query.items_count, 5) array_count = len(result) self.assertEqual(5, array_count)
class ClassHandlersTest(unittest.TestCase): def setUp(self): self.mediator = Mediator() self.ioloop = asyncio.get_event_loop() return super().setUp() @unittest.skipUnless(sys.version_info >= (3, 7), "requires 3.7+") def test_1(self): from tests.example_handlers_annotations import GetArrayQueryHandlerWithAnnotations from tests.example_queries import GetArrayQueryWithAnnotations Mediator.register_handler(GetArrayQueryHandlerWithAnnotations) query = GetArrayQueryWithAnnotations(5) self.assertEqual(query.items_count, 5) result = self.ioloop.run_until_complete( self.mediator.send_async(query)) self.assertEqual(query.items_count, 5) array_count = len(result) self.assertEqual(5, array_count)
def setUp(self): self.mediator = Mediator(setup_class_handler_manager) self.ioloop = asyncio.get_event_loop() return super().setUp()
def setUp(self): self.mediator = Mediator() self.ioloop = asyncio.get_event_loop() return super().setUp()
def test_register_behavior(self): Mediator.register_behavior(get_array_query_behavior) self.assertEqual(len(__behaviors__.keys()), 1)
def test_register_handler(self): Mediator.register_handler(get_array_handler) self.assertEqual(len(__handlers__.keys()), 1)
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)