SVCS - English Documentation
Loading...
Searching...
No Matches
MockHelpService.hxx
Go to the documentation of this file.
1
23#pragma once
24
25#include <string>
26#include <vector>
27#include <map>
28#include <set>
29#include <functional>
30#include <memory>
31#include "MockSubject.hxx"
33
49 * верификации для модульных тестов CLI команд.
50 */
51namespace svcs::test::cli::mocks {
52
54
74class MockHelpService {
75private:
83 std::vector<std::string> availableCommands_;
84
87 * @brief Storage for pre-configured command descriptions.
88 *
89 * @russian
90 * @brief Хранилище для предварительно настроенных описаний команд.
91 */
92 std::map<std::string, std::string> commandDescriptions_;
93
98 * @russian
99 * @brief Записывает имена команд, для которых была запрошена справка через showCommandHelp.
100 */
101 std::set<std::string> calledCommandHelp_;
102
108 * @brief Mock шина событий, используемая для опционального отладочного вывода.
109 */
110 std::shared_ptr<MockSubject> mockEventBus_;
111
115
119 bool wasGeneralHelpCalled_ = false;
120
121public:
122 /**
123 * @english
124 * @brief Constructor for MockHelpService.
125 * @param mockEventBus The shared pointer to the MockSubject used for notifications.
126 *
127 * @russian
128 * @brief Конструктор для MockHelpService.
129 * @param mockEventBus Общий указатель на MockSubject, используемый для уведомлений.
130 */
131 explicit MockHelpService(const std::shared_ptr<MockSubject>& mockEventBus)
132 : mockEventBus_(mockEventBus) {
133 }
134
135 // --- Mock Methods Matching HelpService Interface ---
136
139 * @brief Returns the pre-configured list of available commands.
140 * @return A vector of command names.
141 *
142 * @russian
143 * @brief Возвращает предварительно настроенный список доступных команд.
144 * @return Вектор имен команд.
145 */
146 [[nodiscard]] std::vector<std::string> getAvailableCommands() const {
147 return availableCommands_;
148 }
149
150
158 * @param commandName Имя команды.
159 * @return Настроенное описание или "No description available", если не установлено.
160 */
161 [[nodiscard]] std::string getCommandDescription(const std::string& commandName) const {
162 auto it = commandDescriptions_.find(commandName);
163 if (it != commandDescriptions_.end()) {
164 return it->second;
165 }
166 return "No description available";
167 }
171
178 * @param commandName Имя команды, для которой запрашивается справка.
179 */
180 void showCommandHelp(const std::string& commandName) {
181 calledCommandHelp_.insert(commandName);
182 if (mockEventBus_) {
183 // Создаем объект Event правильно - используем поле details
184 Event event;
186 event.details = "MockHelpService: Showing help for " + commandName;
187 event.source_name = "help";
188 mockEventBus_->notify(event);
189 }
190 }
191
195 * @details Also emits a debug message to the mock event bus.
196 *
197 * @russian
198 * @brief Записывает, что была запрошена общая справка.
199 * @details Также отправляет отладочное сообщение в mock шину событий.
200 */
201 void showGeneralHelp() {
202 wasGeneralHelpCalled_ = true;
203 if (mockEventBus_) {
204 // Создаем объект Event правильно - используем поле details
205 Event event;
207 event.details = "MockHelpService: Showing general help";
208 event.source_name = "help";
209 mockEventBus_->notify(event);
210 }
211 }
212
213 // --- Test Control Methods ---
214
224 void setAvailableCommands(const std::vector<std::string>& commands) {
225 availableCommands_ = commands;
226 }
227
239 void setCommandDescription(const std::string& commandName, const std::string& description) {
240 commandDescriptions_[commandName] = description;
241 }
242
254 [[nodiscard]] bool wasCommandHelpCalled(const std::string& commandName) const {
255 return calledCommandHelp_.find(commandName) != calledCommandHelp_.end();
256 }
257
267 [[nodiscard]] bool wasGeneralHelpCalled() const {
268 return wasGeneralHelpCalled_;
269 }
270
278 void clear() {
279 calledCommandHelp_.clear();
280 availableCommands_.clear();
281 commandDescriptions_.clear();
282 wasGeneralHelpCalled_ = false;
283 }
284};
285
286} // namespace svcs::test::cli::mocks
Defines the event structure used for the Observer pattern notifications.
bool wasGeneralHelpCalled() const
Checks if showGeneralHelp() was called.
Definition MockHelpService.hxx:187
bool wasCommandHelpCalled(const std::string &commandName) const
Checks if showCommandHelp() was called for a specific command.
Definition MockHelpService.hxx:178
void clear()
Resets the mock's internal state (called commands, lists, and descriptions).
Definition MockHelpService.hxx:195
void setAvailableCommands(const std::vector< std::string > &commands)
Sets the list of command names to be returned by getAvailableCommands().
Definition MockHelpService.hxx:158
void showCommandHelp(const std::string &commandName)
Records that help was requested for the given command.
Definition MockHelpService.hxx:122
void showGeneralHelp()
Records that general help was requested.
Definition MockHelpService.hxx:139
std::vector< std::string > getAvailableCommands() const
Returns the pre-configured list of available commands.
Definition MockHelpService.hxx:98
std::string getCommandDescription(const std::string &commandName) const
Returns the pre-configured description for a given command.
Definition MockHelpService.hxx:108
void setCommandDescription(const std::string &commandName, const std::string &description)
Configures a description for a specific command name.
Definition MockHelpService.hxx:168
MockHelpService(const std::shared_ptr< MockSubject > &mockEventBus)
Constructor for MockHelpService.
Definition MockHelpService.hxx:87
Mock implementation of the ISubject interface for unit testing purposes.
Mock objects and test doubles for CLI command testing.
Structure describing an event published by the VCS core.
Definition Event.hxx:30
@ DEBUG_MESSAGE
Debug message for development purposes.
Definition Event.hxx:106
Type type
The type of event that occurred.
Definition Event.hxx:173