kima2/test/test_database.cpp

56 lines
1.6 KiB
C++
Raw Normal View History

2018-07-09 21:42:38 +02:00
#define BOOST_TEST_MODULE database
#include "../src/core/database.h"
2018-07-11 15:57:39 +02:00
#include "../src/core/seller.h"
2018-07-09 21:42:38 +02:00
2018-07-10 14:12:37 +02:00
#include <filesystem>
2018-07-09 21:42:38 +02:00
#include <boost/test/included/unit_test.hpp>
2018-07-10 15:46:55 +02:00
BOOST_AUTO_TEST_CASE(create_database)
{
2018-07-17 10:19:41 +02:00
BOOST_CHECK_NO_THROW(Database db(":memory:"));
2018-07-11 15:57:39 +02:00
}
2018-07-10 15:46:55 +02:00
2018-07-11 15:57:39 +02:00
BOOST_AUTO_TEST_CASE(store_seller_fail)
{
Database db(":memory:");
2018-07-16 15:30:24 +02:00
std::vector<std::unique_ptr<Seller>> sellers;
sellers.push_back(std::make_unique<Seller>());
sellers.push_back(std::make_unique<Seller>());
2018-07-11 15:57:39 +02:00
BOOST_CHECK_THROW(db.storeSellers(sellers), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(store_sellers_succ)
{
Database db(":memory:");
2018-07-16 15:30:24 +02:00
std::vector<std::unique_ptr<Seller>> sellers;
auto a = std::make_unique<Seller>();
2018-07-13 13:06:08 +02:00
a->createUuid();
a->setSellerNo(1);
2018-07-16 15:30:24 +02:00
auto b = std::make_unique<Seller>("Max", "Mustermann");
2018-07-13 13:06:08 +02:00
b->createUuid();
b->setSellerNo(2);
auto c = std::make_shared<Article>();
c->createUuid();
c->setPrice(500);
c->setDescription("Test");
b->addArticle(c);
BOOST_TEST(a->getUuid() != b->getUuid());
2018-07-16 15:30:24 +02:00
sellers.push_back(std::move(a));
sellers.push_back(std::move(b));
2018-07-11 15:57:39 +02:00
BOOST_CHECK_NO_THROW(db.storeSellers(sellers));
}
BOOST_AUTO_TEST_CASE(seller_states)
{
Database db(":memory:");
2018-07-16 15:30:24 +02:00
std::vector<std::unique_ptr<Seller>> sellers;
auto a = std::make_unique<Seller>();
2018-07-13 13:06:08 +02:00
a->setSellerNo(3);
a->createUuid();
2018-07-16 15:30:24 +02:00
sellers.push_back(std::move(a));
2018-07-13 13:06:08 +02:00
BOOST_TEST((sellers.at(0)->getState() == Entity::State::NEW));
2018-07-11 15:57:39 +02:00
BOOST_TEST(db.storeSellers(sellers) == 1);
2018-07-13 13:06:08 +02:00
BOOST_TEST((sellers.at(0)->getState() == Entity::State::OK));
2018-07-11 15:57:39 +02:00
BOOST_TEST(db.storeSellers(sellers) == 0);
2018-07-09 21:42:38 +02:00
}