Skip to content

Commit

Permalink
Added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svermeulen committed Feb 7, 2016
1 parent 34fce22 commit a23ac17
Show file tree
Hide file tree
Showing 35 changed files with 1,612 additions and 0 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UnityEngine;
using Zenject;

namespace ModestTree
{
public class BarMono1 : MonoBehaviour, IInitializable
{
public void Initialize()
{
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UnityEngine;
using Zenject;

namespace ModestTree
{
public class FooMono1 : MonoBehaviour, IInitializable
{
public void Initialize()
{
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using Zenject;

namespace ModestTree
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class InstallerTestAttribute : Attribute
{
}

public abstract class MonoInstallerTestFixture : MonoBehaviour
{
protected DiContainer Container
{
get;
private set;
}

public void Start()
{
StartCoroutine(Run());
}

IEnumerator Run()
{
GlobalCompositionRoot.Instance.EnsureIsInitialized();

var testMethods = this.GetType().GetAllMethods(
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Where(x => x.GetCustomAttributes(typeof(InstallerTestAttribute), false).Any()).ToList();

foreach (var method in testMethods)
{
var wrapper = new InstallerWrapper();
wrapper.InstallCallback = () =>
{
Container = wrapper.GetContainer();
method.Invoke(this, new object[0]);
};

var settings = new SceneCompositionRoot.StaticSettings()
{
Installers = new List<IInstaller>() { wrapper },
ParentNewObjectsUnderRoot = true,
OnlyInjectWhenActive = true,
};

var oldRootObjects = this.gameObject.scene.GetRootGameObjects();

var root = SceneCompositionRoot.Instantiate(gameObject, settings);

// Wait a few frames to have it start up
yield return null;
yield return null;
yield return null;
yield return null;

GameObject.Destroy(root.gameObject);

foreach (Transform childTransform in this.gameObject.transform)
{
GameObject.Destroy(childTransform.gameObject);
}

foreach (var obj in this.gameObject.scene.GetRootGameObjects().Except(oldRootObjects))
{
GameObject.Destroy(obj);
}

yield return null;

Log.Trace("Installer Test '{0}' passed successfully", method.Name);
}

Log.Trace("All Installer Tests passed successfully");
IntegrationTest.Pass();
}

class InstallerWrapper : Installer
{
public Action InstallCallback;

public DiContainer GetContainer()
{
return Container;
}

public override void InstallBindings()
{
InstallCallback();
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &154292
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 4: {fileID: 496146}
- 114: {fileID: 11464982}
m_Layer: 0
m_Name: BarMono1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &496146
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 154292}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!114 &11464982
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 154292}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d63c2c7069c31924fb08fda7448f18fd, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 154292}
m_IsPrefabParent: 1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &154292
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 4: {fileID: 496146}
- 114: {fileID: 11488132}
- 114: {fileID: 11408906}
m_Layer: 0
m_Name: FooMonAndBarMono
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &496146
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 154292}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!114 &11408906
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 154292}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d63c2c7069c31924fb08fda7448f18fd, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &11488132
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 154292}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 99aa66a71b67fe840bd6cd4a04bf061d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 154292}
m_IsPrefabParent: 1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &154292
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 4: {fileID: 496146}
- 114: {fileID: 11488132}
m_Layer: 0
m_Name: FooMono1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &496146
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 154292}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!114 &11488132
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 154292}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 99aa66a71b67fe840bd6cd4a04bf061d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 154292}
m_IsPrefabParent: 1
Loading

0 comments on commit a23ac17

Please sign in to comment.