/*******************************************************************************
***  This file is part of Dux Rei Nummariae.                                 ***
***                                                                          ***
***  Copyright (C) 2017, 2018, 2019, 2020, 2021                              ***
***  John Schneiderman <Licensing _AT_ Schneiderman _DOT_ me>                ***
***                                                                          ***
***  This program is free software: you can redistribute it and/or modify it ***
***  under the terms of the GNU Affero General Public License as published   ***
***  by the Free Software Foundation, either version 3 of the License, or    ***
***  (at your option) any later version.                                     ***
***                                                                          ***
***  This program is distributed in the hope that it will be useful, but     ***
***  WITHOUT ANY WARRANTY; without even the implied warranty of              ***
***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    ***
***  See the GNU Affero General Public License for more details.             ***
***                                                                          ***
***  You should have received a copy of the GNU Affero General Public License***
***  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
*******************************************************************************/
#include <QTest>
using ::QObject;
// using QTEST_MAIN
// using QVERIFY_EXCEPTION_THROWN
#include <qt-mocks/Matchers.h>
// using QVERIFY_THAT
using qt_mocks::equals;
using qt_mocks::isFalse;
using qt_mocks::isTrue;

#include <set>
using std::set;
#include <string>
using std::string;

#include <accounting/AccountCode.h>
using drn::accounting::AccountCode;
using drn::accounting::AccountNumber;
#include <banking/Bank.h>
using drn::banking::Bank;
#include <banking/BankingErrors.h>
using drn::banking::BankError;


namespace drn
{
namespace banking
{
namespace tests
{

struct BankUT : QObject
{
	Q_OBJECT

private slots:
	//{ Constructor Tests

	void constructor_empty_ShouldBeDefaults()
	{
		const set<AccountNumber> expectedNumbers{};
		const BankName expectedName{};
		const Bank b{};
		QVERIFY_THAT(b.accounts(), equals(expectedNumbers));
		QVERIFY_THAT(b.name_, equals(expectedName));
		QVERIFY_THAT(b.isClosed(), isFalse());
	}

	void constructor_partialInit_ShouldBeValues()
	{
		const set<AccountNumber> expectedAccountNumbers{};
		const BankName expectedName{"Home Federal"};
		const Bank b{expectedName};
		QVERIFY_THAT(b.accounts(), equals(expectedAccountNumbers));
		QVERIFY_THAT(b.name_, equals(expectedName));
		QVERIFY_THAT(b.isClosed(), isFalse());
	}

	void constructor_fullInit_ShouldBeValues()
	{
		const set<AccountNumber> expectedAccountNumbers{AccountNumber{1010u}, AccountNumber{1020u}};
		const BankName expectedName{"Home Federal"};
		const Bank b{expectedName, expectedAccountNumbers, true};
		QVERIFY_THAT(b.accounts(), equals(expectedAccountNumbers));
		QVERIFY_THAT(b.name_, equals(expectedName));
		QVERIFY_THAT(b.isClosed(), isTrue());
	}

	//}

	//{ remove Tests

	void remove_hasAccount_ShouldRemove()
	{
		const AccountNumber chequing{1010u};
		const AccountNumber savingsCode{1020u};
		const set<AccountNumber> expectedAccountNumbers{chequing, savingsCode};
		const BankName expectedName{"Home Federal"};
		Bank b{expectedName, expectedAccountNumbers, true};
		QVERIFY_NO_THROW(b.remove(savingsCode));
		const set<AccountNumber> expected{chequing};
		QVERIFY_THAT(b.accounts(), equals(expected));
	}

	void remove_hasNotAccount_ShouldThrow()
	{
		const BankName expectedName{"Home Federal"};
		Bank b{expectedName};
		QVERIFY_EXCEPTION_THROWN(b.remove(AccountNumber{1020u}), BankError);
	}

	//}
};

}}}

QTEST_MAIN(drn::banking::tests::BankUT)
#include "Bank-unit-tests.moc"
