@@ -62,47 +62,66 @@ const response::IdType& getFakeFolderId() noexcept
6262 return s_fakeId;
6363}
6464
65- std::unique_ptr<TodayMockService> mock_service ( ) noexcept
65+ std::shared_ptr<Query> mock_query ( const std::shared_ptr<TodayMockService>& service ) noexcept
6666{
67- auto result = std::make_unique<TodayMockService>();
68-
69- auto query = std::make_shared<Query>(
70- [mockService = result.get ()]() -> std::vector<std::shared_ptr<Appointment>> {
71- ++mockService->getAppointmentsCount ;
67+ return std::make_shared<Query>(
68+ [weakService = std::weak_ptr { service }]() -> std::vector<std::shared_ptr<Appointment>> {
69+ if (auto mockService = weakService.lock ())
70+ {
71+ ++mockService->getAppointmentsCount ;
72+ }
7273 return { std::make_shared<Appointment>(response::IdType (getFakeAppointmentId ()),
7374 " tomorrow" ,
7475 " Lunch?" ,
7576 false ) };
7677 },
77- [mockService = result.get ()]() -> std::vector<std::shared_ptr<Task>> {
78- ++mockService->getTasksCount ;
78+ [weakService = std::weak_ptr { service }]() -> std::vector<std::shared_ptr<Task>> {
79+ if (auto mockService = weakService.lock ())
80+ {
81+ ++mockService->getTasksCount ;
82+ }
7983 return {
8084 std::make_shared<Task>(response::IdType (getFakeTaskId ()), " Don't forget" , true )
8185 };
8286 },
83- [mockService = result.get ()]() -> std::vector<std::shared_ptr<Folder>> {
84- ++mockService->getUnreadCountsCount ;
87+ [weakService = std::weak_ptr { service }]() -> std::vector<std::shared_ptr<Folder>> {
88+ if (auto mockService = weakService.lock ())
89+ {
90+ ++mockService->getUnreadCountsCount ;
91+ }
8592 return {
8693 std::make_shared<Folder>(response::IdType (getFakeFolderId ()), " \" Fake\" Inbox" , 3 )
8794 };
8895 });
89- auto mutation = std::make_shared<Mutation>(
96+ }
97+
98+ std::shared_ptr<Mutation> mock_mutation () noexcept
99+ {
100+ return std::make_shared<Mutation>(
90101 [](CompleteTaskInput&& input) -> std::shared_ptr<CompleteTaskPayload> {
91102 return std::make_shared<CompleteTaskPayload>(
92103 std::make_shared<Task>(std::move (input.id ), " Mutated Task!" , *(input.isComplete )),
93104 std::move (input.clientMutationId ));
94105 });
95- auto subscription = std::make_shared<NextAppointmentChange>(
106+ }
107+
108+ std::shared_ptr<NextAppointmentChange> mock_subscription () noexcept
109+ {
110+ return std::make_shared<NextAppointmentChange>(
96111 [](const std::shared_ptr<service::RequestState>&) -> std::shared_ptr<Appointment> {
97112 return { std::make_shared<Appointment>(response::IdType (getFakeAppointmentId ()),
98113 " tomorrow" ,
99114 " Lunch?" ,
100115 true ) };
101116 });
117+ }
118+
119+ std::shared_ptr<TodayMockService> mock_service () noexcept
120+ {
121+ auto result = std::make_shared<TodayMockService>();
102122
103- result->service = std::make_shared<Operations>(std::move (query),
104- std::move (mutation),
105- std::move (subscription));
123+ result->service =
124+ std::make_shared<Operations>(mock_query (result), mock_mutation (), mock_subscription ());
106125
107126 return result;
108127}
0 commit comments