aboutsummaryrefslogtreecommitdiff
path: root/test/container.test.cpp
blob: ec3e332f5174decb30192e19def08907948daddd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "yacppdic/container.hpp"
#include "yacppdic/auto_wirable.hpp"
#include "gtest/gtest.h"

#include <string_view>

TEST(ContainerTest, BindAndGet)
{
	auto container = yacppdic::DIContainer();

	class IObject
	{
	public:
		virtual ~IObject() = default;

		virtual void destroy() = 0;

		virtual std::string_view name() = 0;
	};

	class Object : public IObject, public yacppdic::AutoWirable<IObject, Object>
	{
	public:
		void destroy() {}

		std::string_view name()
		{
			return "A object";
		}
	};

	container.bind<IObject>().to<Object>();

	auto object = container.get<IObject>();

	EXPECT_EQ(object->name(), "A object");

	auto object_two = container.get<IObject>();

	EXPECT_NE(object, object_two);
}