-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3219 from PrismLibrary/dev/ds/module-fix
Modularity Fix
- Loading branch information
Showing
4 changed files
with
101 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
89 changes: 89 additions & 0 deletions
89
tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Modularity/ModuleCatalogTests.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,89 @@ | ||
namespace Prism.DryIoc.Maui.Tests.Fixtures.Modularity; | ||
|
||
public class ModuleCatalogTests(ITestOutputHelper testOutputHelper) : TestBase(testOutputHelper) | ||
{ | ||
public readonly IModuleInfo ModuleA = new ModuleInfo(typeof(MockModuleA)); | ||
public readonly IModuleInfo ModuleB = new ModuleInfo(typeof(MockModuleB)); | ||
|
||
[Fact] | ||
public void UsesCustomModuleCatalog() | ||
{ | ||
var builder = CreateBuilder(prism => | ||
{ | ||
prism.RegisterTypes(c => c.RegisterSingleton<IModuleCatalog, CustomMoudleCatalog>()) | ||
.ConfigureModuleCatalog(catalog => { }); | ||
}); | ||
var app = builder.Build(); | ||
|
||
var moduleCatalog = app.Services.GetService<IModuleCatalog>(); | ||
Assert.NotNull(moduleCatalog); | ||
Assert.IsType<CustomMoudleCatalog>(moduleCatalog); | ||
} | ||
|
||
[Fact] | ||
public void InjectsModulesFromDI() | ||
{ | ||
var builder = CreateBuilder(prism => | ||
{ | ||
prism.RegisterTypes(c => c.RegisterInstance<IModuleInfo>(ModuleA)) | ||
.ConfigureModuleCatalog(c => { }); | ||
}); | ||
var app = builder.Build(); | ||
|
||
var moduleCatalog = app.Services.GetService<IModuleCatalog>(); | ||
Assert.Single(moduleCatalog.Modules); | ||
Assert.Equal(ModuleA.ModuleType, moduleCatalog.Modules.Single().ModuleType); | ||
} | ||
|
||
[Fact] | ||
public void InjectsModulesFromConfigureDelegate() | ||
{ | ||
var builder = CreateBuilder(prism => | ||
prism.ConfigureModuleCatalog(c => c.AddModule<MockModuleA>())); | ||
var app = builder.Build(); | ||
|
||
var moduleCatalog = app.Services.GetService<IModuleCatalog>(); | ||
Assert.Single(moduleCatalog.Modules); | ||
Assert.Equal(ModuleA.ModuleType, moduleCatalog.Modules.Single().ModuleType); | ||
} | ||
|
||
[Fact] | ||
public void CombinesModulesFromConfigureMethodAndDI() | ||
{ | ||
var builder = CreateBuilder(prism => | ||
{ | ||
prism.RegisterTypes(c => c.RegisterInstance<IModuleInfo>(ModuleA)) | ||
.ConfigureModuleCatalog(c => c.AddModule<MockModuleB>()); | ||
}); | ||
var app = builder.Build(); | ||
|
||
var moduleCatalog = app.Services.GetService<IModuleCatalog>(); | ||
Assert.Equal(2, moduleCatalog.Modules.Count()); | ||
Assert.Contains(ModuleA.ModuleType, moduleCatalog.Modules.Select(m => m.ModuleType)); | ||
Assert.Contains(ModuleB.ModuleType, moduleCatalog.Modules.Select(m => m.ModuleType)); | ||
} | ||
|
||
public class CustomMoudleCatalog : ModuleCatalogBase { } | ||
|
||
public class MockModuleA : IModule | ||
{ | ||
public void OnInitialized(IContainerProvider containerProvider) | ||
{ | ||
} | ||
|
||
public void RegisterTypes(IContainerRegistry containerRegistry) | ||
{ | ||
} | ||
} | ||
|
||
public class MockModuleB : IModule | ||
{ | ||
public void OnInitialized(IContainerProvider containerProvider) | ||
{ | ||
} | ||
|
||
public void RegisterTypes(IContainerRegistry containerRegistry) | ||
{ | ||
} | ||
} | ||
} |