Older/UnitTest/DatabaseTest.cpp
luocai 889faa4404
All checks were successful
Deploy / Build (push) Successful in 6m54s
use dbo, not test.
2024-11-27 19:23:06 +08:00

83 lines
2.4 KiB
C++

#include "BoostLog.h"
#include "Database/Session.h"
#include <Wt/Dbo/SqlConnectionPool.h>
#include <boost/test/unit_test.hpp>
#include <filesystem>
using namespace std::chrono;
BOOST_AUTO_TEST_CASE(DatabaseTest) {
auto session = Database::session();
Wt::Dbo ::Transaction transaction(*session);
auto task = std::make_unique<Task>();
task->comment = "my_comment";
task->content = "my_content";
auto p = session->add(std::move(task));
{
task = std::make_unique<Task>();
task->comment = "my_comment1";
task->content = "my_content1";
auto c = session->add(std::move(task));
p.modify()->children.insert(c);
}
{
task = std::make_unique<Task>();
task->comment = "my_comment2";
task->content = "my_content2";
auto c = session->add(std::move(task));
p.modify()->children.insert(c);
{
task = std::make_unique<Task>();
task->comment = "my_comment3";
task->content = "my_content3";
auto d = session->add(std::move(task));
c.modify()->children.insert(d);
}
{
task = std::make_unique<Task>();
task->comment = "my_comment4";
task->content = "my_content4";
auto d = session->add(std::move(task));
c.modify()->children.insert(d);
}
}
Wt::Dbo::ptr<Task> tt = session->find<Task>("where id = 3");
LOG(info) << tt->parent->content;
LOG(info) << tt->children.size();
{
auto item = std::make_unique<HomeBox::Item>();
item->cost = 1499;
item->location = "抽屉";
item->name = "手机";
auto d = session->add(std::move(item));
}
}
BOOST_AUTO_TEST_CASE(VisitorRecordTest) {
// database.updateVisitCount("/note", "uuid_123", "chrome", now_time);
// database.updateVisitCount("/note/1", "uuid_1232", "chrome", now_time);
// database.updateVisitCount("/note", "uuid_123", "chrome", now_time);
// database.updateVisitCount("/note", "uuid_1234", "chrome", now_time);
auto session = Database::session();
{
Wt::Dbo ::Transaction transaction(*session);
auto now = std::chrono::system_clock::now();
auto record = std::make_unique<VisitorRecord>();
record->time = now;
record->url = "/note";
record->userAgent = "chrome";
record->visitorUuid = "uuid_123";
auto d = session->add(std::move(record));
}
}