Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
fix: critical bug with dependents not resolving multi-providers (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolexxa authored Dec 19, 2022
1 parent d688a00 commit 44160b1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion GoDotDep.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Company>Chickensoft</Company>

<PackageId>Chickensoft.GoDotDep</PackageId>
<PackageVersion>1.3.0-beta8</PackageVersion>
<PackageVersion>1.3.1-beta8</PackageVersion>
<PackageReleaseNotes>GoDotDep release.</PackageReleaseNotes>
<PackageIcon></PackageIcon>
<PackageTags>Godot;Dependency;Dependencies;DI;Dependency Injection;Loader;Injector;Chickensoft;Gamedev;Utility;Utilities</PackageTags>
Expand Down
2 changes: 1 addition & 1 deletion src/IDependent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ internal static bool IsProvider(this Type type, Type genericType) {
providedType: providedType
);
}
return providedType == genericType;
if (providedType == genericType) { return true; }
}
}
return false;
Expand Down
35 changes: 35 additions & 0 deletions test/test/DependencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ public partial class TestProviderOneNode : Node, IProvider<TestDummyValueA> {
public override void _Ready() => this.Provided();
}

public partial class TestMultiProviderNode
: Node, IProvider<TestDummyValueA>, IProvider<TestDummyValueB> {
private readonly TestDummyValueA _a;
private readonly TestDummyValueB _b;

public TestMultiProviderNode(TestDummyValueA a, TestDummyValueB b) {
_a = a;
_b = b;
}

TestDummyValueA IProvider<TestDummyValueA>.Get() => _a;
TestDummyValueB IProvider<TestDummyValueB>.Get() => _b;

public override void _Ready() => this.Provided();
}

public partial class TestProviderSubtype : Node, IProvider<ITestDummyValueA> {
private readonly TestDummyValueA _value;

Expand Down Expand Up @@ -267,4 +283,23 @@ public void DependentRequestingSupertypeOfProvidedTypeThrows() {
() => dependent._Ready()
);
}

[Test]
public void MultiProviderProvidesMultipleValues() {
var a = new TestDummyValueA();
var b = new TestDummyValueB();
var provider = new TestMultiProviderNode(a, b);
var loadedCalled = false;
var dependent = new TestDependentNode(
loadedCallback: (node) => {
loadedCalled = true;
node.ValueA.ShouldBe(a);
node.ValueB.ShouldBe(b);
}
);
provider.AddChild(dependent);
provider._Ready();
dependent._Ready();
loadedCalled.ShouldBeTrue();
}
}

0 comments on commit 44160b1

Please sign in to comment.