Skip to content

Commit

Permalink
Fix #479: IOC Registraation fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineatrhea committed Oct 17, 2023
1 parent 0d29d96 commit 99e9c5a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
namespace COMET.Web.Common.Tests.Components.Applications
{
using CDP4Dal;
using CDP4Dal.DAL;

using COMET.Web.Common.Components.Applications;
using COMET.Web.Common.Model.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@

namespace COMET.Web.Common.Tests.Extensions
{
using System.Reflection;

using COMET.Web.Common.Extensions;
using COMET.Web.Common.Services.SessionManagement;

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

using Moq;
Expand All @@ -37,16 +41,34 @@ namespace COMET.Web.Common.Tests.Extensions
public class ServiceCollectionExtensionsTestFixture
{
[Test]
public void VerifyRegistration()
public void VerifyServerRegistration()
{
var serviceCollection = new ServiceCollection();
var configuration = new Mock<IConfiguration>();
serviceCollection.AddSingleton(configuration.Object);
serviceCollection.AddLogging();
serviceCollection.RegisterCommonLibrary(globalOptions: _ => { });
var serviceProvider = serviceCollection.BuildServiceProvider();

foreach (var service in serviceCollection.Where(x => x.ServiceType.Assembly == Assembly.GetAssembly(typeof(ISessionService))))
{
Assert.That(() => serviceProvider.GetService(service.ServiceType), Throws.Nothing);
}
}

[Test]
public void VerifyWebAssemblyRegistration()
{
var serviceCollection = new Mock<IServiceCollection>();

Assert.Multiple(() =>
var serviceCollection = new ServiceCollection();
serviceCollection.AddScoped(_ => new HttpClient());
serviceCollection.AddLogging();
serviceCollection.RegisterCommonLibrary(false,globalOptions: _ => { });
var serviceProvider = serviceCollection.BuildServiceProvider();

foreach (var service in serviceCollection.Where(x => x.ServiceType.Assembly == Assembly.GetAssembly(typeof(ISessionService))))
{
Assert.That(() => serviceCollection.Object.RegisterCommonLibrary(), Throws.Nothing);
Assert.That(() => serviceCollection.Object.RegisterCommonLibrary(false), Throws.Nothing);
Assert.That(() => serviceCollection.Object.RegisterCommonLibrary(false, options => { }), Throws.Nothing);
});
Assert.That(() => serviceProvider.GetService(service.ServiceType), Throws.Nothing);
}
}
}
}
1 change: 1 addition & 0 deletions COMET.Web.Common/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private static void RegisterCommonViewModels(this IServiceCollection serviceProv
serviceProvider.AddScoped<ISessionMenuViewModel, SessionMenuViewModel>();
serviceProvider.AddScoped<IModelMenuViewModel, ModelMenuViewModel>();
serviceProvider.AddTransient<IIterationSelectorViewModel, IterationSelectorViewModel>();
serviceProvider.AddTransient<IEngineeringModelSelectorViewModel, EngineeringModelSelectorViewModel>();
serviceProvider.AddTransient<ISingleIterationApplicationTemplateViewModel, SingleIterationApplicationTemplateViewModel>();
serviceProvider.AddTransient<ISingleEngineeringModelApplicationTemplateViewModel, SingleEngineeringModelApplicationTemplateViewModel>();
serviceProvider.AddTransient<IApplicationTemplateViewModel, ApplicationTemplateViewModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ApplicationTemplateViewModel : DisposableObject, IApplicationTempla
/// Initializes a new <see cref="ApplicationTemplateViewModel" />
/// </summary>
/// <param name="sessionService">The <see cref="ISessionService" /></param>
protected ApplicationTemplateViewModel(ISessionService sessionService)
public ApplicationTemplateViewModel(ISessionService sessionService)
{
this.SessionService = sessionService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public async Task VerifyModelDashboardComponent()
this.sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny<Iteration>())).Returns(themalDomain);
CDPMessageBus.Current.SendMessage(new DomainChangedEvent(iteration, themalDomain));
await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);
await Task.Delay(1000);

var buttonToDo = renderer.Find(".todo-btn");
await renderer.InvokeAsync(() => buttonToDo.ClickAsync(new MouseEventArgs()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ModelDashboardTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2023 RHEA System S.A.
//
Expand Down

0 comments on commit 99e9c5a

Please sign in to comment.