Files
2025-10-04 15:25:55 +03:00

70 lines
2.6 KiB
C++

#ifdef WIN32
#include <sdkddkver.h>
#endif
#define BOOST_TEST_MODULE Controllers
#include <boost/test/included/unit_test.hpp>
#include "./../../src/endpoints_handlers/Controller.h"
#include <cstdint>
#include <cstdlib>
using namespace boost;
using namespace std;
using namespace uad;
using IControllerMock = Controller<beast::http::string_body,
std::allocator<char>,
beast::http::string_body>;
class MockExecutor : public IExecutor<beast::http::string_body,
std::allocator<char>,
beast::http::string_body>
{
public:
beast::http::response<beast::http::string_body> operator ()(
beast::http::request<beast::http::string_body, beast::http::basic_fields<std::allocator<char>>>&& req
) override
{
boost::beast::http::response<boost::beast::http::string_body> res{
boost::beast::http::status::not_found, req.version()};
return res;
}
};
BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_No_Executors)
{
IControllerMock my_controller;
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::get).has_value());
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::post).has_value());
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::put).has_value());
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::delete_).has_value());
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::head).has_value());
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::options).has_value());
}
BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_Unordered_Map_HTTP_Methods_To_Executors)
{
IControllerMock::HTTPMethodsToExecutors executors;
executors[beast::http::verb::get] = make_shared<MockExecutor>();
executors[beast::http::verb::post] = make_shared<MockExecutor>();
executors[beast::http::verb::put] = make_shared<MockExecutor>();
executors[beast::http::verb::delete_] = make_shared<MockExecutor>();
executors[beast::http::verb::head] = make_shared<MockExecutor>();
executors[beast::http::verb::options] = make_shared<MockExecutor>();
IControllerMock my_controller(std::move(executors));
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::get).has_value());
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::post).has_value());
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::put).has_value());
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::delete_).has_value());
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::head).has_value());
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::options).has_value());
}