Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
database::testing::mock_database_builder Class Reference

Builder for common mock configurations. More...

#include <mock_database.h>

Collaboration diagram for database::testing::mock_database_builder:
Collaboration graph

Public Member Functions

 mock_database_builder ()
 
mock_database_builderwith_type (database_types type)
 
mock_database_builderwith_default_result (const core::database_result &result)
 
mock_database_builderthat_fails_on_connect ()
 
mock_database build ()
 

Static Public Member Functions

static mock_database empty_database ()
 
static mock_database with_data (const std::string &table_name, const core::database_result &data)
 
static mock_database failing_database (const std::string &error="Mock database error")
 

Private Attributes

std::unique_ptr< mock_databasemock_
 

Detailed Description

Builder for common mock configurations.

Definition at line 120 of file mock_database.h.

Constructor & Destructor Documentation

◆ mock_database_builder()

database::testing::mock_database_builder::mock_database_builder ( )

Definition at line 267 of file mock_database.cpp.

268 : mock_(std::make_unique<mock_database>())
269{
270}
std::unique_ptr< mock_database > mock_

Member Function Documentation

◆ build()

mock_database database::testing::mock_database_builder::build ( )

Definition at line 303 of file mock_database.cpp.

303 {
304 return std::move(*mock_);
305}

References mock_.

◆ empty_database()

mock_database database::testing::mock_database_builder::empty_database ( )
static

Definition at line 272 of file mock_database.cpp.

272 {
273 return mock_database();
274}

◆ failing_database()

mock_database database::testing::mock_database_builder::failing_database ( const std::string & error = "Mock database error")
static

Definition at line 282 of file mock_database.cpp.

282 {
283 mock_database db;
284 db.expect_any().will_fail(error);
285 return db;
286}

References database::testing::mock_database::expect_any(), and database::testing::expectation_builder::will_fail().

Here is the call graph for this function:

◆ that_fails_on_connect()

mock_database_builder & database::testing::mock_database_builder::that_fails_on_connect ( )

Definition at line 298 of file mock_database.cpp.

298 {
299 mock_->simulate_connection_failure();
300 return *this;
301}

References mock_.

◆ with_data()

mock_database database::testing::mock_database_builder::with_data ( const std::string & table_name,
const core::database_result & data )
static

Definition at line 276 of file mock_database.cpp.

276 {
277 mock_database db;
278 db.expect_pattern("SELECT.*FROM.*" + table_name).will_return(data);
279 return db;
280}

References database::testing::mock_database::expect_pattern(), and database::testing::expectation_builder::will_return().

Here is the call graph for this function:

◆ with_default_result()

mock_database_builder & database::testing::mock_database_builder::with_default_result ( const core::database_result & result)

Definition at line 293 of file mock_database.cpp.

293 {
294 mock_->set_default_select_result(result);
295 return *this;
296}

References mock_.

◆ with_type()

mock_database_builder & database::testing::mock_database_builder::with_type ( database_types type)

Definition at line 288 of file mock_database.cpp.

288 {
289 mock_->set_database_type(type);
290 return *this;
291}

References mock_.

Member Data Documentation

◆ mock_

std::unique_ptr<mock_database> database::testing::mock_database_builder::mock_
private

Definition at line 137 of file mock_database.h.

Referenced by build(), that_fails_on_connect(), with_default_result(), and with_type().


The documentation for this class was generated from the following files: