SVCS - English Documentation
Loading...
Searching...
No Matches
MockSubject.hxx
Go to the documentation of this file.
1
19#pragma once
20
22#include <gmock/gmock.h>
23#include <vector>
24#include <string>
25
44
45using namespace svcs::services;
46
66class MockSubject : public ISubject {
67public:
72 * @russian
73 * @brief Хранит историю всех событий, полученных через метод notify(), для проверки утверждений.
74 */
75 std::vector<Event> notifications;
76
80 * @param observer The observer to attach (unused in mock).
81 *
82 * @russian
83 * @brief Выполняет требования интерфейса ISubject, но не выполняет никаких операций.
84 * @param observer Наблюдатель для присоединения (не используется в mock).
85 */
86 void attach(std::shared_ptr<IObserver> observer) override {}
87
90 * @brief Satisfies the ISubject interface, but performs no operation.
91 * @param observer The observer to detach (unused in mock).
92 *
93 * @russian
94 * @brief Выполняет требования интерфейса ISubject, но не выполняет никаких операций.
95 * @param observer Наблюдатель для отсоединения (не используется в mock).
96 */
97 void detach(std::shared_ptr<IObserver> observer) override {}
98
106 * @russian
107 * @brief Захватывает событие во внутренний вектор уведомлений.
108 * @details Это основная тестовая функция, позволяющая тестовым случаям проверять,
109 * что были опубликованы правильные события.
110 * @param event Константная ссылка на структуру события для захвата.
111 */
112 void notify(const Event& event) const override {
113 const_cast<MockSubject*>(this)->notifications.push_back(event);
114 }
115
120 * @russian
121 * @brief Очищает все захваченные уведомления.
122 */
123 void clear() {
124 notifications.clear();
125 }
126
127 /**
128 * @english
129 * @brief Checks if any captured notification's details contain the specified message substring.
130 * @param message The substring to search for within notification details.
131 * @return true if a matching message is found, false otherwise.
132 *
133 * @russian
134 * @brief Проверяет, содержат ли детали любого захваченного уведомления указанную подстроку сообщения.
135 * @param message Подстрока для поиска в деталях уведомлений.
136 * @return true если найдено соответствующее сообщение, false в противном случае.
137 */
138 [[nodiscard]] bool containsMessage(const std::string& message) const {
139 for (const auto& notification : notifications) {
140 if (notification.details.find(message) != std::string::npos) {
141 return true;
142 }
143 }
144 return false;
145 }
146
158 [[nodiscard]] bool containsEventType(Event::Type type) const {
159 for (const auto& notification : notifications) {
160 if (notification.type == type) {
161 return true;
162 }
163 }
164 return false;
165 }
166
176 void storeNotification(const Event& event) {
177 notifications.push_back(event);
178 }
179
187 void clearNotifications() {
188 notifications.clear();
189 }
190
200 [[nodiscard]] const std::vector<Event>& getNotifications() const {
201 return notifications;
202 }
203};
204
205}
Defines the interface for the Subject (Publisher) component of the Observer pattern.
The Subject (Publisher) Interface (Abstract Base Class).
Definition ISubject.hxx:38
A mock implementation of ISubject for testing event-driven components.
Definition MockSubject.hxx:43
void storeNotification(const Event &event)
Stores a notification in the internal vector (alias for notify functionality).
Definition MockSubject.hxx:119
bool containsEventType(Event::Type type) const
Checks if any captured notification matches the specified Event Type.
Definition MockSubject.hxx:105
void detach(std::shared_ptr< IObserver > observer) override
Satisfies the ISubject interface, but performs no operation.
Definition MockSubject.hxx:63
const std::vector< Event > & getNotifications() const
Returns a constant reference to the notifications vector for inspection.
Definition MockSubject.hxx:136
void clearNotifications()
Clears all notifications from the internal storage.
Definition MockSubject.hxx:127
bool containsMessage(const std::string &message) const
Checks if any captured notification's details contain the specified message substring.
Definition MockSubject.hxx:90
void clear()
Clears all captured notifications.
Definition MockSubject.hxx:80
void notify(const Event &event) const override
Captures the event into the internal notifications vector.
Definition MockSubject.hxx:72
std::vector< Event > notifications
Stores a history of all events received via the notify() method for assertion.
Definition MockSubject.hxx:49
void attach(std::shared_ptr< IObserver > observer) override
Satisfies the ISubject interface, but performs no operation.
Definition MockSubject.hxx:56
Service layer components and infrastructure services.
Mock objects and test doubles for CLI command testing.
Structure describing an event published by the VCS core.
Definition Event.hxx:30
Type
Types of events that can be published.
Definition Event.hxx:35