forked from ssannandeji/Zenject-2019
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for failing WithArguments GameObject bindings
Cases copied from TestBindFactoryOne, dropped ones that were not applicable
- Loading branch information
1 parent
578ddc7
commit 819476d
Showing
2 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
...as/IntegrationTests/Tests/Factories/TestBindFactoryOne/TestBindFactoryOneWithArguments.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
using System.Collections; | ||
using ModestTree; | ||
using UnityEngine; | ||
using UnityEngine.TestTools; | ||
using Zenject.Tests.Factories.BindFactoryOne; | ||
|
||
namespace Zenject.Tests.Factories | ||
{ | ||
public class TestBindFactoryOneWithArguments : ZenjectIntegrationTestFixture | ||
{ | ||
private const string ArgumentValue = "asdf"; | ||
|
||
GameObject FooPrefab | ||
{ | ||
get | ||
{ | ||
return FixtureUtil.GetPrefab("TestBindFactoryOne/Foo"); | ||
} | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator TestFromNewComponentOnNewGameObjectSelf() | ||
{ | ||
PreInstall(); | ||
Container.BindIFactory<Foo>() | ||
.FromNewComponentOnNewGameObject() | ||
.WithArguments(ArgumentValue); | ||
|
||
AddFactoryUser<Foo>(); | ||
|
||
PostInstall(); | ||
|
||
FixtureUtil.AssertComponentCount<Foo>(1); | ||
FixtureUtil.AssertNumGameObjects(1); | ||
yield break; | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator TestFromNewComponentOnNewGameObjectConcrete() | ||
{ | ||
PreInstall(); | ||
Container.BindIFactory<IFoo>() | ||
.To<Foo>() | ||
.FromNewComponentOnNewGameObject() | ||
.WithArguments(ArgumentValue); | ||
|
||
AddFactoryUser<IFoo>(); | ||
|
||
PostInstall(); | ||
|
||
FixtureUtil.AssertComponentCount<Foo>(1); | ||
FixtureUtil.AssertNumGameObjects(1); | ||
yield break; | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator TestFromComponentInNewPrefabSelf() | ||
{ | ||
PreInstall(); | ||
Container.BindIFactory<Foo>() | ||
.FromComponentInNewPrefab(FooPrefab) | ||
.WithGameObjectName("asdf") | ||
.WithArguments(ArgumentValue); | ||
|
||
AddFactoryUser<Foo>(); | ||
|
||
PostInstall(); | ||
|
||
FixtureUtil.AssertComponentCount<Foo>(1); | ||
FixtureUtil.AssertNumGameObjects(1); | ||
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1); | ||
yield break; | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator TestFromComponentInNewPrefabConcrete() | ||
{ | ||
PreInstall(); | ||
Container.BindIFactory<IFoo>() | ||
.To<Foo>() | ||
.FromComponentInNewPrefab(FooPrefab) | ||
.WithGameObjectName("asdf") | ||
.WithArguments(ArgumentValue); | ||
|
||
AddFactoryUser<IFoo>(); | ||
|
||
PostInstall(); | ||
|
||
FixtureUtil.AssertComponentCount<Foo>(1); | ||
FixtureUtil.AssertNumGameObjects(1); | ||
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1); | ||
yield break; | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator TestFromComponentInNewPrefabResourceSelf() | ||
{ | ||
PreInstall(); | ||
Container.BindIFactory<Foo>() | ||
.FromComponentInNewPrefabResource("TestBindFactoryOne/Foo") | ||
.WithGameObjectName("asdf") | ||
.WithArguments(ArgumentValue); | ||
|
||
AddFactoryUser<Foo>(); | ||
|
||
PostInstall(); | ||
|
||
FixtureUtil.AssertComponentCount<Foo>(1); | ||
FixtureUtil.AssertNumGameObjects(1); | ||
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1); | ||
yield break; | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator TestFromComponentInNewPrefabResourceConcrete() | ||
{ | ||
PreInstall(); | ||
Container.BindIFactory<IFoo>().To<Foo>() | ||
.FromComponentInNewPrefabResource("TestBindFactoryOne/Foo") | ||
.WithGameObjectName("asdf") | ||
.WithArguments(ArgumentValue); | ||
|
||
AddFactoryUser<IFoo>(); | ||
|
||
PostInstall(); | ||
|
||
FixtureUtil.AssertComponentCount<Foo>(1); | ||
FixtureUtil.AssertNumGameObjects(1); | ||
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1); | ||
yield break; | ||
} | ||
|
||
// Note that unlike the TestBindFactory tests, WithArguments still doesn't work nicely with subcontainers... | ||
|
||
void AddFactoryUser<TValue>() | ||
where TValue : IFoo | ||
{ | ||
Container.Bind<IInitializable>() | ||
.To<FooFactoryTester<TValue>>().AsSingle(); | ||
|
||
Container.BindExecutionOrder<FooFactoryTester<TValue>>(-100); | ||
} | ||
|
||
public class FooFactoryTester<TValue> : IInitializable | ||
where TValue : IFoo | ||
{ | ||
readonly IFactory<TValue> _factory; | ||
|
||
public FooFactoryTester(IFactory<TValue> factory) | ||
{ | ||
_factory = factory; | ||
} | ||
|
||
public void Initialize() | ||
{ | ||
Assert.IsEqual(_factory.Create().Value, ArgumentValue); | ||
|
||
Log.Info("Factory created foo successfully"); | ||
} | ||
} | ||
} | ||
} | ||
|
3 changes: 3 additions & 0 deletions
3
...tegrationTests/Tests/Factories/TestBindFactoryOne/TestBindFactoryOneWithArguments.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.