/
farado
/
farado-binara
Обзор
Документация
Войти
/
farado
/
farado-binara
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
develop
tests/data_elements/test_data_element_phase.cpp
79 строк
3 KB
Ostapenko Alexey
[common][datenaro][tests] Добавлена сущность предметной области: phase.
25 мар 2024, 18:07
25 мар 2024, 18:07
0f59364
Код
Авторство
О чём код?
#define BOOST_TEST_MODULE testDataElementPhase #include <boost/test/unit_test.hpp> #include "common/helpers/container_helper.hpp" #include "common/elements/element_maker.h" #include "common/elements/phase.h" #include "datenaro/database/data_elements/data_phase.h" #include "datenaro/database/data_gate.h" #include "datenaro/database/migrator.h" BOOST_AUTO_TEST_CASE(testDataElementPhase) { // Создание и апгрейд БД. const auto migrationResult = Database::Migrator("test.db").run(); assert(0 == migrationResult); Database::DataGate gate("test.db"); // Создание тестируемого объекта предметной области с конкретным идентификатором. auto first = std::make_shared<Elements::Phase>(); first->setId(1); first->setProjectId(3); first->setCaption("a"); first->setDescription("b"); first->setSearchCaption("c"); first->setSearchDescription("D"); const std::time_t beginDate = std::time(nullptr); const std::time_t endDate = std::time(nullptr); first->setBeginDate(beginDate); first->setEndDate(endDate); // Сохранение в тестовую БД. gate.saveElement(first); // Чтение из тестовой БД и проверка полей. auto second = gate.loadElement(Elements::ElementType::Phase, 1)->elementCast<Elements::Phase>(); BOOST_CHECK(1 == second->id()); BOOST_CHECK(3 == second->projectId()); BOOST_CHECK("a" == second->caption()); BOOST_CHECK("b" == second->description()); BOOST_CHECK("c" == second->searchCaption()); BOOST_CHECK("d" == second->searchDescription()); BOOST_CHECK(beginDate == second->beginDate()); BOOST_CHECK(endDate == second->endDate()); // Удаление из тестовой БД и проверка, объект был и удалился. BOOST_CHECK(true == Common::contains(gate.getElementsIds(Database::DataPhase::ids), 1)); gate.remove(Database::DataPhase::removeOne, 1); BOOST_CHECK(false == Common::contains(gate.getElementsIds(Database::DataPhase::ids), 1)); // Удаление всех объектов данного типа из тестовой БД. gate.remove(Database::DataPhase::remove, gate.getElementsIds(Database::DataPhase::ids)); // Имитация нового объекта. first->setId(0); // Сохранение в тестовую БД. gate.saveElement(first); // Элементу назначен идентификатор при сохранении в БД. BOOST_CHECK(0 != first->id()); // Чтение из тестовой БД и проверка полей. auto third = gate.loadElement(Elements::ElementType::Phase, 1)->elementCast<Elements::Phase>(); BOOST_CHECK(1 == third->id()); BOOST_CHECK(3 == third->projectId()); BOOST_CHECK("a" == third->caption()); BOOST_CHECK("b" == third->description()); BOOST_CHECK("c" == third->searchCaption()); BOOST_CHECK("d" == third->searchDescription()); BOOST_CHECK(beginDate == third->beginDate()); BOOST_CHECK(endDate == third->endDate()); // Удаление всех объектов данного типа из тестовой БД. gate.remove(Database::DataPhase::remove, gate.getElementsIds(Database::DataPhase::ids)); }