Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "SharedItemsListInteractorInput.hpp"
- #include "SharedItemsListInteractorOutput.hpp"
- #include "Store.hpp"
- namespace ri {
- class ItemsListInteractor : public SharedItemsListInteractorInput {
- private:
- std::shared_ptr<Store> _store;
- std::shared_ptr<SharedItemsListInteractorOutput> _output;
- public:
- ItemsListInteractor(
- const std::shared_ptr<Store> &store,
- const std::shared_ptr<SharedItemsListInteractorOutput> &output
- );
- void fetchItems() override;
- };
- }
- #include "ItemsListInteractor.hpp"
- #include <iostream>
- namespace ri {
- ItemsListInteractor::ItemsListInteractor(
- const std::shared_ptr<Store> &store,
- const std::shared_ptr<SharedItemsListInteractorOutput> &output
- ) {
- if (store == nullptr) {
- throw std::invalid_argument("Store should not be an std::nullptr");
- }
- if (output == nullptr) {
- throw std::invalid_argument("Output should not be an std::nullptr");
- }
- _store = store;
- _output = output;
- }
- void ItemsListInteractor::fetchItems() {
- _store->getItems(0, [=] (std::vector<SharedItem> items, bool nextPage) {
- if (_output != nullptr) {
- _output->didFetchItems(items, nextPage);
- }
- });
- }
- }
- #include "ItemsListInteractor.hpp"
- #include "catch.hpp"
- #include "fakeit.hpp"
- using namespace Catch;
- using namespace fakeit;
- using namespace ri;
- TEST_CASE( "items list interactor", "[ItemsListInteractor]" ) {
- SECTION( "no store" ) {
- Mock<SharedItemsListInteractorOutput> outputMock;
- Fake(Dtor(outputMock));
- auto output = std::shared_ptr<SharedItemsListInteractorOutput>(&outputMock.get());
- REQUIRE_THROWS_AS(ItemsListInteractor(nullptr, output), std::invalid_argument);
- }
- SECTION( "no output" ) {
- Mock<Store> storeMock;
- Fake(Dtor(storeMock));
- auto store = std::shared_ptr<Store>(&storeMock.get());
- REQUIRE_THROWS_AS(ItemsListInteractor(store, nullptr), std::invalid_argument);
- }
- }
- #include <memory>
- #include <exception>
- _store = store;
- _output = output;
- ItemsListInteractor::ItemsListInteractor(
- std::shared_ptr<Store> store,
- std::shared_ptr<SharedItemsListInteractorOutput> output)
- : store{std::move(store)},
- output{std::move(output)}
- {
- if (!store)
- throw std::invalid_argument("Store should not be null");
- if (!output)
- throw std::invalid_argument("Output should not be null");
- }
- void ItemsListInteractor::fetchItems() {
- store->getItems(0, [=](std::vector<SharedItem> items, bool nextPage) {
- output->didFetchItems(items, nextPage);
- });
- }
Add Comment
Please, Sign In to add comment