Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Assets/Plugins/Uniject/impl/TestableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public void OnUpdate() {
}
}

public virtual void Start() {
}

public virtual void Update() {
}

Expand Down
7 changes: 7 additions & 0 deletions src/Assets/Plugins/Uniject/impl/TestableGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public virtual void Destroy () {
}
}

public void Start() {
for (int t = 0; t < components.Count; t++) {
TestableComponent component = components[t];
component.Start();
}
}

public void Update() {
if (active) {
for (int t = 0; t < components.Count; t++) {
Expand Down
5 changes: 5 additions & 0 deletions src/Assets/Plugins/Uniject/impl/UnityGameObjectBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
using UnityEngine;

public class UnityGameObjectBridge : MonoBehaviour {

public void Start() {
wrapping.Start();
}

public void OnDestroy() {
wrapping.Destroy();
}
Expand Down
1 change: 1 addition & 0 deletions src/test/tests/src/Impl/framework/TestUpdatableManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public void step(int numUpdates) {

foreach (TestableGameObject o in toAdd) {
objects.Add(o);
o.Start();
}
toAdd.Clear();

Expand Down
43 changes: 43 additions & 0 deletions src/test/tests/src/Tests/TestUniject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ public HasInjectedPrefab(TestableGameObject parent, [Resource("mesh/sphere")] Te
}
}

public interface IStartUpdateCallback {
void OnConstructor();
void OnStart();
void OnUpdate();
}

[GameObjectBoundary]
public class HasStartUpdateCallback : TestableComponent {
public IStartUpdateCallback callback;
public HasStartUpdateCallback(TestableGameObject obj, IStartUpdateCallback callback) : base(obj) {
this.callback = callback;
this.callback.OnConstructor();
}
public override void Start() { callback.OnStart(); }
public override void Update() { callback.OnUpdate(); }
}

/// <summary>
/// Tests the testable component has its Update method called.
/// </summary>
Expand All @@ -67,6 +84,32 @@ public void TestTestableComponentIsUpdated() {
Assert.AreEqual(1, component.updateCount);
}

/// <summary>
/// Tests that the testable component has its constructor called
/// first, its Start method second, and its Update method last.
/// </summary>
[Test]
public void TestTestableComponentStartFiresBeforeUpdate()
{
Mock<IStartUpdateCallback> mockCallback = new Mock<IStartUpdateCallback>();
mockCallback.Setup(c => c.OnConstructor()).Callback(() => {
mockCallback.Verify(c => c.OnStart(), Times.Never());
mockCallback.Verify(c => c.OnUpdate(), Times.Never());
});
mockCallback.Setup(c => c.OnStart()).Callback(() => {
mockCallback.Verify(c => c.OnConstructor(), Times.Once());
mockCallback.Verify(c => c.OnUpdate(), Times.Never());
});
mockCallback.Setup(c => c.OnUpdate()).Callback(() => {
mockCallback.Verify(c => c.OnConstructor(), Times.Once());
mockCallback.Verify(c => c.OnStart(), Times.Once());
});

kernel.Bind<IStartUpdateCallback>().ToMethod(context => mockCallback.Object);
HasStartUpdateCallback component = kernel.Get<HasStartUpdateCallback>();
step();
}

[Test]
public void TestDestroyedObjectsNotUpdated() {
MockComponent component = kernel.Get<MockComponent>();
Expand Down