Initial Commit

This commit is contained in:
2026-03-16 14:38:46 +02:00
commit b8f7327a21
2327 changed files with 253610 additions and 0 deletions
@@ -0,0 +1,40 @@
#if !(UNITY_WSA && ENABLE_DOTNET)
using System;
namespace Zenject.Tests.Convention
{
public class ConventionTestAttribute : Attribute
{
public ConventionTestAttribute(int num)
{
Num = num;
}
public int Num
{
get;
private set;
}
}
public interface IFoo
{
}
public class Foo1 : IFoo
{
}
[ConventionTest(0)]
public class Foo2 : IFoo
{
}
[ConventionTest(1)]
public class Foo3 : IFoo
{
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: df03d112f1cade745b9c6eb4344fc519
timeCreated: 1462127518
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,14 @@
#if !(UNITY_WSA && ENABLE_DOTNET)
namespace Zenject.Tests.Convention.NamespaceTest
{
public class Bar
{
}
public class Foo4 : IFoo
{
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d233b33d1863c004293dc5c5dbec63c9
timeCreated: 1462127515
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,81 @@
#if !(UNITY_WSA && ENABLE_DOTNET)
using System.Linq;
using ModestTree;
using NUnit.Framework;
using UnityEngine;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.Convention
{
[TestFixture]
public class TestConvention : ZenjectUnitTestFixture
{
[Test]
public void TestDerivingFrom()
{
Container.Bind<IFoo>()
.To(x => x.AllTypes().DerivingFrom<IFoo>().FromThisAssembly()).AsTransient();
Assert.IsEqual(Container.ResolveAll<IFoo>().Count(), 4);
}
[Test]
public void TestDerivingFrom2()
{
Container.Bind<IFoo>()
.To(x => x.AllTypes().DerivingFrom<IFoo>()).AsTransient();
Assert.IsEqual(Container.ResolveAll<IFoo>().Count(), 4);
}
[Test]
public void TestMatchAll()
{
// Should automatically filter by contract types
Container.Bind<IFoo>().To(x => x.AllNonAbstractClasses()).AsTransient();
Assert.IsEqual(Container.ResolveAll<IFoo>().Count(), 4);
}
#if !NOT_UNITY3D
[Test]
public void TestDerivingFromFail()
{
Container.Bind<IFoo>()
.To(x => x.AllTypes().DerivingFrom<IFoo>().FromAssemblyContaining<Vector3>()).AsTransient();
Assert.That(Container.ResolveAll<IFoo>().IsEmpty());
}
#endif
[Test]
public void TestAttributeFilter()
{
Container.Bind<IFoo>()
.To(x => x.AllTypes().WithAttribute<ConventionTestAttribute>()).AsTransient();
Assert.IsEqual(Container.ResolveAll<IFoo>().Count(), 2);
}
[Test]
public void TestAttributeWhereFilter()
{
Container.Bind<IFoo>()
.To(x => x.AllTypes().WithAttributeWhere<ConventionTestAttribute>(a => a.Num == 1)).AsTransient();
Assert.IsEqual(Container.ResolveAll<IFoo>().Count(), 1);
}
[Test]
public void TestInNamespace()
{
Container.Bind<IFoo>()
.To(x => x.AllTypes().DerivingFrom<IFoo>().InNamespace("Zenject.Tests.Convention.NamespaceTest")).AsTransient();
Assert.IsEqual(Container.ResolveAll<IFoo>().Count(), 1);
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 69363ffe277b0e84ea97667444992554
timeCreated: 1462127494
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
#if !(UNITY_WSA && ENABLE_DOTNET)
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.Convention.Two
{
[TestFixture]
public class TestConvention2
{
[Test]
public void TestBindAllInterfacesSimple()
{
var container = new DiContainer();
container.Bind(x => x.AllInterfaces()).To<Foo>().AsTransient();
Assert.That(container.Resolve<IFoo>() is Foo);
Assert.That(container.Resolve<IBar>() is Foo);
}
[Test]
public void TestBindAllInterfaces2()
{
var container = new DiContainer();
container.Bind(x => x.AllInterfaces())
.To(x => x.AllNonAbstractClasses().InNamespace("Zenject.Tests.Convention.Two")).AsTransient();
Assert.IsEqual(container.ResolveAll<IFoo>().Count, 2);
Assert.IsEqual(container.ResolveAll<IBar>().Count, 2);
}
public interface IFoo
{
}
public interface IBar
{
}
public class Foo : IFoo, IBar
{
}
public class Bar : IBar, IFoo
{
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 37e019ec982c85046baf80bc37b38d11
timeCreated: 1464576582
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
#if !(UNITY_WSA && ENABLE_DOTNET)
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.Convention.Names
{
[TestFixture]
public class TestConventionNames : ZenjectUnitTestFixture
{
[Test]
public void TestWithSuffix()
{
Container.Bind<IController>()
.To(x => x.AllNonAbstractClasses().InNamespace("Zenject.Tests.Convention.Names").WithSuffix("Controller")).AsTransient();
Assert.That(Container.Resolve<IController>() is FooController);
}
[Test]
public void TestWithPrefix()
{
Container.Bind<IController>()
.To(x => x.AllTypes().InNamespace("Zenject.Tests.Convention.Names").WithPrefix("Controller")).AsTransient();
Assert.That(Container.Resolve<IController>() is ControllerBar);
}
[Test]
public void TestMatchingRegex()
{
Container.Bind<IController>()
.To(x => x.AllNonAbstractClasses().InNamespace("Zenject.Tests.Convention.Names").MatchingRegex("Controller$")).AsTransient();
Assert.That(Container.Resolve<IController>() is FooController);
}
interface IController
{
}
class FooController : IController
{
}
class ControllerBar : IController
{
}
class QuxControllerAsdf : IController
{
}
class IgnoredFooController
{
}
class ControllerBarIgnored
{
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a8a9ff36735244a47babe85319e21e38
timeCreated: 1464576609
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: