38 lines
928 B
C++
38 lines
928 B
C++
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
#include <Void/TestingMock/Mock.hpp>
|
|
#include <Void/TestingMock/MockFunction.hpp>
|
|
|
|
#include <string_view>
|
|
|
|
struct Database
|
|
{
|
|
virtual ~Database() = default;
|
|
virtual int get_user_id(std::string_view name) = 0;
|
|
};
|
|
|
|
class MockDatabase : public Void::TestingMock::Mock<MockDatabase>,
|
|
public Database
|
|
{
|
|
public:
|
|
|
|
Void::TestingMock::MockFunction<int(std::string_view)>
|
|
get_user_id_mock{"get_user_id"};
|
|
|
|
int get_user_id(std::string_view name) override
|
|
{
|
|
return get_user_id_mock(name);
|
|
}
|
|
};
|
|
|
|
// @tag mock
|
|
Void::Testing::Test mock_database()
|
|
{
|
|
using namespace Void::TestingMock;
|
|
MockDatabase db;
|
|
db.get_user_id_mock.expect(Eq<std::string_view>("alice")).returns(42);
|
|
db.get_user_id_mock.expect(_<std::string_view>()).returns(-1);
|
|
Void::Testing::expect_eq(db.get_user_id("alice"), 42);
|
|
Void::Testing::expect_eq(db.get_user_id("bob"), -1);
|
|
}
|