This commit is contained in:
2025-07-17 06:36:37 +02:00
parent 4ec3dedd42
commit 1054061d91
52 changed files with 804 additions and 704 deletions

View File

@@ -1,75 +0,0 @@
using NUnit.Framework;
using RebootKit.Engine.Foundation;
namespace Tests.Runtime.Engine {
interface ITestService {
int Value();
}
class TestServiceA : ITestService {
public const int k_ReturnValue = 1;
public int Value() {
return k_ReturnValue;
}
}
class TestServiceB : ITestService {
public const int k_ReturnValue = 2;
public int Value() {
return k_ReturnValue;
}
}
public class DIContextTests {
[Test]
public void Single_Bind_And_Resolve() {
DIContext context = new DIContext();
context.Bind<ITestService>(new TestServiceA());
ITestService testService = context.Resolve<ITestService>();
Assert.IsNotNull(testService, "Resolved service is null!");
Assert.IsTrue(testService.Value() == TestServiceA.k_ReturnValue, "Invalid return value of resolved service");
}
[Test]
public void Single_Bind_And_Field_Inject() {
DIContext context = new DIContext();
context.Bind<ITestService>(new TestServiceB());
TestObject obj = new TestObject();
context.Inject(obj);
Assert.IsNotNull(obj.Service, "obj.Service != null");
Assert.IsTrue(obj.Service.Value() == TestServiceB.k_ReturnValue);
}
[Test]
public void Single_Bind_And_Method_Inject() {
DIContext context = new DIContext();
context.Bind<ITestService>(new TestServiceA());
TestObjectMethod obj = new TestObjectMethod();
context.Inject(obj);
Assert.IsNotNull(obj.Service, "obj.Service != null");
Assert.IsTrue(obj.Service.Value() == TestServiceA.k_ReturnValue);
}
class TestObject {
[Inject] public ITestService Service;
}
class TestObjectMethod {
public ITestService Service;
[Inject]
public void Setup(ITestService service) {
Service = service;
}
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: fb99eda81d534ddcb15cff09441d98bc
timeCreated: 1742002479