DI
This commit is contained in:
3
Tests/Runtime.meta
Normal file
3
Tests/Runtime.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38d2e5d9c5d2492fb523c373872899e0
|
||||
timeCreated: 1742002103
|
||||
8
Tests/Runtime/Engine.meta
Normal file
8
Tests/Runtime/Engine.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4abcb79b93f19b448aa8369c5894eabc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
78
Tests/Runtime/Engine/DIContextTests.cs
Normal file
78
Tests/Runtime/Engine/DIContextTests.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using NUnit.Framework.Internal;
|
||||
using RebootKit.Engine.Foundation;
|
||||
|
||||
namespace Tests.Runtime.Engine {
|
||||
internal interface ITestService {
|
||||
int Value();
|
||||
}
|
||||
|
||||
internal class TestServiceA : ITestService {
|
||||
public const int k_ReturnValue = 1;
|
||||
|
||||
public int Value() {
|
||||
return k_ReturnValue;
|
||||
}
|
||||
}
|
||||
|
||||
internal 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();
|
||||
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");
|
||||
}
|
||||
|
||||
private class TestObject {
|
||||
[Inject]
|
||||
public ITestService Service;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Single_Bind_And_Field_Inject() {
|
||||
DIContext context = new();
|
||||
context.Bind<ITestService>(new TestServiceB());
|
||||
|
||||
TestObject obj = new();
|
||||
context.Inject(obj);
|
||||
|
||||
Assert.IsNotNull(obj.Service, "obj.Service != null");
|
||||
Assert.IsTrue(obj.Service.Value() == TestServiceB.k_ReturnValue);
|
||||
}
|
||||
|
||||
|
||||
private class TestObjectMethod {
|
||||
public ITestService Service;
|
||||
|
||||
[Inject]
|
||||
public void Setup(ITestService service) {
|
||||
Service = service;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Single_Bind_And_Method_Inject() {
|
||||
DIContext context = new();
|
||||
context.Bind<ITestService>(new TestServiceA());
|
||||
|
||||
TestObjectMethod obj = new();
|
||||
context.Inject(obj);
|
||||
|
||||
Assert.IsNotNull(obj.Service, "obj.Service != null");
|
||||
Assert.IsTrue(obj.Service.Value() == TestServiceA.k_ReturnValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Tests/Runtime/Engine/DIContextTests.cs.meta
Normal file
3
Tests/Runtime/Engine/DIContextTests.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb99eda81d534ddcb15cff09441d98bc
|
||||
timeCreated: 1742002479
|
||||
20
Tests/Runtime/Engine/RebootKit.Engine.Tests.asmdef
Normal file
20
Tests/Runtime/Engine/RebootKit.Engine.Tests.asmdef
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "RebootKit.Engine.Tests",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:284059c7949783646b281a1b815580e6",
|
||||
"GUID:0acc523941302664db1f4e527237feb3",
|
||||
"GUID:27619889b8ba8c24980f49ee34dbb44a"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Tests/Runtime/Engine/RebootKit.Engine.Tests.asmdef.meta
Normal file
7
Tests/Runtime/Engine/RebootKit.Engine.Tests.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 863a7983695eedb40a4fb34e2a16b5ba
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user