Guest User

Untitled

a guest
Nov 21st, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "SharedItemsListInteractorInput.hpp"
  4. #include "SharedItemsListInteractorOutput.hpp"
  5. #include "Store.hpp"
  6.  
  7. namespace ri {
  8.  
  9. class ItemsListInteractor : public SharedItemsListInteractorInput {
  10. private:
  11. std::shared_ptr<Store> _store;
  12. std::shared_ptr<SharedItemsListInteractorOutput> _output;
  13. public:
  14. ItemsListInteractor(
  15. const std::shared_ptr<Store> &store,
  16. const std::shared_ptr<SharedItemsListInteractorOutput> &output
  17. );
  18.  
  19. void fetchItems() override;
  20. };
  21.  
  22. }
  23.  
  24. #include "ItemsListInteractor.hpp"
  25. #include <iostream>
  26.  
  27. namespace ri {
  28.  
  29. ItemsListInteractor::ItemsListInteractor(
  30. const std::shared_ptr<Store> &store,
  31. const std::shared_ptr<SharedItemsListInteractorOutput> &output
  32. ) {
  33. if (store == nullptr) {
  34. throw std::invalid_argument("Store should not be an std::nullptr");
  35. }
  36. if (output == nullptr) {
  37. throw std::invalid_argument("Output should not be an std::nullptr");
  38. }
  39. _store = store;
  40. _output = output;
  41. }
  42.  
  43. void ItemsListInteractor::fetchItems() {
  44. _store->getItems(0, [=] (std::vector<SharedItem> items, bool nextPage) {
  45. if (_output != nullptr) {
  46. _output->didFetchItems(items, nextPage);
  47. }
  48. });
  49. }
  50.  
  51. }
  52.  
  53. #include "ItemsListInteractor.hpp"
  54. #include "catch.hpp"
  55. #include "fakeit.hpp"
  56.  
  57. using namespace Catch;
  58. using namespace fakeit;
  59. using namespace ri;
  60.  
  61. TEST_CASE( "items list interactor", "[ItemsListInteractor]" ) {
  62.  
  63. SECTION( "no store" ) {
  64. Mock<SharedItemsListInteractorOutput> outputMock;
  65. Fake(Dtor(outputMock));
  66. auto output = std::shared_ptr<SharedItemsListInteractorOutput>(&outputMock.get());
  67.  
  68. REQUIRE_THROWS_AS(ItemsListInteractor(nullptr, output), std::invalid_argument);
  69. }
  70. SECTION( "no output" ) {
  71. Mock<Store> storeMock;
  72. Fake(Dtor(storeMock));
  73. auto store = std::shared_ptr<Store>(&storeMock.get());
  74.  
  75. REQUIRE_THROWS_AS(ItemsListInteractor(store, nullptr), std::invalid_argument);
  76. }
  77. }
  78.  
  79. #include <memory>
  80.  
  81. #include <exception>
  82.  
  83. _store = store;
  84. _output = output;
  85.  
  86. ItemsListInteractor::ItemsListInteractor(
  87. std::shared_ptr<Store> store,
  88. std::shared_ptr<SharedItemsListInteractorOutput> output)
  89. : store{std::move(store)},
  90. output{std::move(output)}
  91. {
  92. if (!store)
  93. throw std::invalid_argument("Store should not be null");
  94. if (!output)
  95. throw std::invalid_argument("Output should not be null");
  96. }
  97.  
  98. void ItemsListInteractor::fetchItems() {
  99. store->getItems(0, [=](std::vector<SharedItem> items, bool nextPage) {
  100. output->didFetchItems(items, nextPage);
  101. });
  102. }
Add Comment
Please, Sign In to add comment