kima2/test/test_database.cpp
2018-07-20 11:52:26 +02:00

56 lines
No EOL
1.6 KiB
C++

#define BOOST_TEST_MODULE database
#include "../src/core/database.h"
#include "../src/core/seller.h"
#include <filesystem>
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(create_database)
{
BOOST_CHECK_NO_THROW(Database db(":memory:"));
}
BOOST_AUTO_TEST_CASE(store_seller_fail)
{
Database db(":memory:");
std::vector<std::unique_ptr<Seller>> sellers;
sellers.push_back(std::make_unique<Seller>());
sellers.push_back(std::make_unique<Seller>());
BOOST_CHECK_THROW(db.storeSellers(sellers), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(store_sellers_succ)
{
Database db(":memory:");
std::vector<std::unique_ptr<Seller>> sellers;
auto a = std::make_unique<Seller>();
a->createUuid();
a->setSellerNo(1);
auto b = std::make_unique<Seller>("Max", "Mustermann");
b->createUuid();
b->setSellerNo(2);
auto c = std::make_unique<Article>();
c->createUuid();
c->setPrice(500);
c->setDescription("Test");
b->addArticle(std::move(c));
BOOST_TEST(a->getUuid() != b->getUuid());
sellers.push_back(std::move(a));
sellers.push_back(std::move(b));
BOOST_CHECK_NO_THROW(db.storeSellers(sellers));
}
BOOST_AUTO_TEST_CASE(seller_states)
{
Database db(":memory:");
std::vector<std::unique_ptr<Seller>> sellers;
auto a = std::make_unique<Seller>();
a->setSellerNo(3);
a->createUuid();
sellers.push_back(std::move(a));
BOOST_TEST((sellers.at(0)->getState() == Entity::State::NEW));
BOOST_TEST(db.storeSellers(sellers) == 1);
BOOST_TEST((sellers.at(0)->getState() == Entity::State::OK));
BOOST_TEST(db.storeSellers(sellers) == 0);
}