1 parent
4fc129fb7e
commit
e7186f17f0
42 files changed
+1816
-413
No files matched your search
@@ -0,0 +1,37 @@
|
||||
#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);
|
||||
}
|
||||
Reference in new issue
Block a user