xtd 0.2.0
xtd::tunit::directory_assert Class Referencefinal
Inheritance diagram for xtd::tunit::directory_assert:
xtd::tunit::base_assert

Definition

The directory_assert class contains a collection of static methods that implement the most directory assertions used in xtd::tUnit.

Namespace
xtd::tunit
Library
xtd.tunit
Remarks
Assertions are central to unit testing in any of the xUnit frameworks, and xtd.tunit is no exception. xtd.tunit provides a rich set of assertions as static methods of the Assert class.
If an assertion fails, the method call does not return and an error is reported. If a test contains multiple assertions, any that follow the one that failed will not be executed. For this reason, it's usually best to try for one assertion per test.
Each method may be called without a message, with a simple text message or with a message and arguments. In the last case the message is formatted using the provided text and arguments.
Examples
This example show how to used some methods :
#include <xtd/xtd.tunit>
#include <stdexcept>
using namespace xtd;
using namespace xtd::io;
using namespace xtd::tunit;
namespace unit_tests {
// The class test must be declared with test_class_ helper.
class test_class_(test) {
void test_method_(test_case1) {
}
void test_method_(test_case2) {
directory_assert::exists(path::combine("unknown root folder", "unknown sub folder", "unknown xtd example folder"));
}
void test_method_(test_case3) {
}
};
}
auto main() -> int {
return console_unit_test().run();
}
// This code can produce the following output :
//
// Start 3 tests from 1 test case
// Run tests:
// SUCCEED unit_tests::test.test_case1 (0 ms total)
// FAILED unit_tests::test.test_case2 (0 ms total)
// Expected: directory exists
// But was: "unknown root folder/unknown sub folder/unknown xtd example folder"
// Stack Trace: in |---OMITTED---|/directory_assert.cpp:16
// FAILED unit_tests::test.test_case3 (0 ms total)
// Expected: "|---OMITTED---|/Music"
// But was: "|---OMITTED---|/Movies"
// Stack Trace: in |---OMITTED---|/directory_assert.cpp:20
//
// Test results:
// SUCCEED 1 test.
// FAILED 2 tests.
// End 3 tests from 1 test case ran. (0 ms total)
@ my_music
The My Music folder.
Definition environment.hpp:167
@ my_videos
The file system directory that serves as a repository for videos that belong to a user.
Definition environment.hpp:169
static xtd::string get_folder_path(environment::special_folder folder)
Gets the path to the system special folder that is identified by the specified enumeration.
Definition environment.hpp:613
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories...
Definition directory_info.hpp:130
static xtd::string get_temp_path() noexcept
Returns the path of the current user's temporary folder.
static xtd::string combine(const xtd::string &path1, const xtd::string &path2)
Combines two path strings.
static void are_equal(const std::filesystem::directory_entry &expected, const std::filesystem::directory_entry &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that two std::filesystem::directory_entry are equal.
static void exists(const std::filesystem::directory_entry &directory, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that directory exists.
#define test_method_(method_name)
Add test method to class test.
Definition test_method_attribute.hpp:72
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:17
The tunit namespace contains a unit test library.
Definition abort_error.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8

Public Static Methods

static void are_equal (const std::filesystem::directory_entry &expected, const std::filesystem::directory_entry &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that two std::filesystem::directory_entry are equal.
 
static void are_equal (const std::filesystem::directory_entry &expected, const std::filesystem::directory_entry &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that two std::filesystem::directory_entry are equal.
 
static void are_equal (const xtd::io::directory_info &expected, const xtd::io::directory_info &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that two xtd::io::directory_info are equal.
 
static void are_equal (const xtd::io::directory_info &expected, const xtd::io::directory_info &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that two xtd::io::directory_info are equal.
 
static void are_not_equal (const std::filesystem::directory_entry &expected, const std::filesystem::directory_entry &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that two std::filesystem::directory_entry are not equal.
 
static void are_not_equal (const std::filesystem::directory_entry &expected, const std::filesystem::directory_entry &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that two std::filesystem::directory_entry are not equal.
 
static void are_not_equal (const xtd::io::directory_info &expected, const xtd::io::directory_info &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that two xtd::io::directory_info are not equal.
 
static void are_not_equal (const xtd::io::directory_info &expected, const xtd::io::directory_info &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that two xtd::io::directory_info are not equal.
 
static void does_not_exist (const std::filesystem::directory_entry &directory, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory not exists.
 
static void does_not_exist (const std::filesystem::directory_entry &directory, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory not exists.
 
static void does_not_exist (const xtd::io::directory_info &directory, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory not exists.
 
static void does_not_exist (const xtd::io::directory_info &directory, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory not exists.
 
template<class char_t>
static void does_not_exist (const xtd::basic_string< char_t > &directory, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory not exists.
 
template<class char_t>
static void does_not_exist (const xtd::basic_string< char_t > &directory, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory not exists.
 
static void exists (const std::filesystem::directory_entry &directory, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory exists.
 
static void exists (const std::filesystem::directory_entry &directory, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory exists.
 
static void exists (const xtd::io::directory_info &directory, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory exists.
 
static void exists (const xtd::io::directory_info &directory, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory exists.
 
template<class char_t>
static void exists (const xtd::basic_string< char_t > &directory, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory exists.
 
template<class char_t>
static void exists (const xtd::basic_string< char_t > &directory, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Asserts that directory exists.
 

Member Function Documentation

◆ are_equal() [1/4]

static void xtd::tunit::directory_assert::are_equal ( const std::filesystem::directory_entry & expected,
const std::filesystem::directory_entry & actual,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that two std::filesystem::directory_entry are equal.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
std::filesystem::directory_entry d1(std::filesystem::path("."));
std::filesystem::directory_entry d2(std::filesystem::path("."));
std::filesystem::directory_entry d3(std::filesystem::path(".."));
xtd::tunit::directory_assert::are_equal(d1, d3); // test throws an assert_error exception.
@ d1
The 1 key.
Definition console_key.hpp:70
@ d2
The 2 key.
Definition console_key.hpp:72
@ d3
The 3 key.
Definition console_key.hpp:74

◆ are_equal() [2/4]

static void xtd::tunit::directory_assert::are_equal ( const std::filesystem::directory_entry & expected,
const std::filesystem::directory_entry & actual,
const std::string & message,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that two std::filesystem::directory_entry are equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
std::filesystem::directory_entry d1(std::filesystem::path("."));
std::filesystem::directory_entry d2(std::filesystem::path("."));
std::filesystem::directory_entry d3(std::filesystem::path(".."));
xtd::tunit::directory_assert::are_equal(d1, d2, "User message..."); // test ok.
xtd::tunit::directory_assert::are_equal(d1, d3, "User message..."); // test throws an assert_error exception.

◆ are_equal() [3/4]

static void xtd::tunit::directory_assert::are_equal ( const xtd::io::directory_info & expected,
const xtd::io::directory_info & actual,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that two xtd::io::directory_info are equal.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
xtd::io::directory_info d3("..")
xtd::tunit::directory_assert::are_equal(d1, d3); // test throws an assert_error exception.
The directory_assert class contains a collection of static methods that implement the most directory ...
Definition directory_assert.hpp:29

◆ are_equal() [4/4]

static void xtd::tunit::directory_assert::are_equal ( const xtd::io::directory_info & expected,
const xtd::io::directory_info & actual,
const std::string & message,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that two xtd::io::directory_info are equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
xtd::io::directory_info d3("..")
xtd::tunit::directory_assert::are_equal(d1, d2, "User message..."); // test ok.
xtd::tunit::directory_assert::are_equal(d1, d3, "User message..."); // test throws an assert_error exception.

◆ are_not_equal() [1/4]

static void xtd::tunit::directory_assert::are_not_equal ( const std::filesystem::directory_entry & expected,
const std::filesystem::directory_entry & actual,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that two std::filesystem::directory_entry are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
std::filesystem::directory_entry d1(std::filesystem::path("."));
std::filesystem::directory_entry d2(std::filesystem::path("."));
std::filesystem::directory_entry d3(std::filesystem::path(".."));
xtd::tunit::directory_assert::are_not_equal(d1, d3, "User message..."); // test ok.
xtd::tunit::directory_assert::are_not_equal(d1, d2, "User message..."); // test throws an assert_error exception.
static void are_not_equal(const std::filesystem::directory_entry &expected, const std::filesystem::directory_entry &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that two std::filesystem::directory_entry are not equal.

◆ are_not_equal() [2/4]

static void xtd::tunit::directory_assert::are_not_equal ( const std::filesystem::directory_entry & expected,
const std::filesystem::directory_entry & actual,
const std::string & message,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that two std::filesystem::directory_entry are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
std::filesystem::directory_entry d1(std::filesystem::path("."));
std::filesystem::directory_entry d2(std::filesystem::path("."));
std::filesystem::directory_entry d3(std::filesystem::path(".."));
xtd::tunit::directory_assert::are_not_equal(d1, d3, "User message..."); // test ok.
xtd::tunit::directory_assert::are_not_equal(d1, d2, "User message..."); // test throws an assert_error exception.

◆ are_not_equal() [3/4]

static void xtd::tunit::directory_assert::are_not_equal ( const xtd::io::directory_info & expected,
const xtd::io::directory_info & actual,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that two xtd::io::directory_info are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
xtd::io::directory_info d3("..")
xtd::tunit::directory_assert::are_not_equal(d1, d3, "User message..."); // test ok.
xtd::tunit::directory_assert::are_not_equal(d1, d2, "User message..."); // test throws an assert_error exception.

◆ are_not_equal() [4/4]

static void xtd::tunit::directory_assert::are_not_equal ( const xtd::io::directory_info & expected,
const xtd::io::directory_info & actual,
const std::string & message,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that two xtd::io::directory_info are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
xtd::io::directory_info d3("..")
xtd::tunit::directory_assert::are_not_equal(d1, d3, "User message..."); // test ok.
xtd::tunit::directory_assert::are_not_equal(d1, d2, "User message..."); // test throws an assert_error exception.

◆ does_not_exist() [1/6]

static void xtd::tunit::directory_assert::does_not_exist ( const std::filesystem::directory_entry & directory,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that directory not exists.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
xtd::io::directory_info d2(std::filesystem::directory_entry d1(std::filesystem::path(xtd::io::path::combine(environment::get_folder_path(environment::special_folder::common_application_data)) / "__xtd_test_directory_not_found__");
xtd::tunit::directory_assert::does_not_exist(d1); // test throws an assert_error exception.
@ common_application_data
The directory that serves as a common repository for application-specific data that is used by all us...
Definition environment.hpp:201
static void does_not_exist(const std::filesystem::directory_entry &directory, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that directory not exists.

◆ does_not_exist() [2/6]

static void xtd::tunit::directory_assert::does_not_exist ( const std::filesystem::directory_entry & directory,
const std::string & message,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that directory not exists.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
xtd::io::directory_info d2(std::filesystem::directory_entry d1(std::filesystem::path(xtd::io::path::combine(environment::get_folder_path(environment::special_folder::common_application_data)) / "__xtd_test_directory_not_found__");
xtd::tunit::directory_assert::does_not_exist(d1); // test throws an assert_error exception.

◆ does_not_exist() [3/6]

static void xtd::tunit::directory_assert::does_not_exist ( const xtd::io::directory_info & directory,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that directory not exists.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples

◆ does_not_exist() [4/6]

static void xtd::tunit::directory_assert::does_not_exist ( const xtd::io::directory_info & directory,
const std::string & message,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that directory not exists.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples

◆ does_not_exist() [5/6]

template<class char_t>
static void xtd::tunit::directory_assert::does_not_exist ( const xtd::basic_string< char_t > & directory,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
inlinestatic

Asserts that directory not exists.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
xtd::tunit::directory_assert::does_not_exist(d1); // test throws an assert_error exception.
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43

◆ does_not_exist() [6/6]

template<class char_t>
static void xtd::tunit::directory_assert::does_not_exist ( const xtd::basic_string< char_t > & directory,
const std::string & message,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
inlinestatic

Asserts that directory not exists.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples

◆ exists() [1/6]

static void xtd::tunit::directory_assert::exists ( const std::filesystem::directory_entry & directory,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that directory exists.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
xtd::io::directory_info d2(std::filesystem::directory_entry d1(std::filesystem::path(xtd::io::path::combine(environment::get_folder_path(environment::special_folder::common_application_data)) / "__xtd_test_directory_not_found__");
xtd::tunit::directory_assert::exists(d2); // test throws an assert_error exception.

◆ exists() [2/6]

static void xtd::tunit::directory_assert::exists ( const std::filesystem::directory_entry & directory,
const std::string & message,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that directory exists.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples
xtd::io::directory_info d2(std::filesystem::directory_entry d1(std::filesystem::path(xtd::io::path::combine(environment::get_folder_path(environment::special_folder::common_application_data)) / "__xtd_test_directory_not_found__");
xtd::tunit::directory_assert::exists(d2); // test throws an assert_error exception.

◆ exists() [3/6]

static void xtd::tunit::directory_assert::exists ( const xtd::io::directory_info & directory,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that directory exists.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples

◆ exists() [4/6]

static void xtd::tunit::directory_assert::exists ( const xtd::io::directory_info & directory,
const std::string & message,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
static

Asserts that directory exists.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples

◆ exists() [5/6]

template<class char_t>
static void xtd::tunit::directory_assert::exists ( const xtd::basic_string< char_t > & directory,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
inlinestatic

Asserts that directory exists.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples

◆ exists() [6/6]

template<class char_t>
static void xtd::tunit::directory_assert::exists ( const xtd::basic_string< char_t > & directory,
const std::string & message,
const xtd::diagnostics::stack_frame & stack_frame = xtd::diagnostics::stack_frame::current() )
inlinestatic

Asserts that directory exists.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::assert_errorIf bad assertion.
Examples

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