Skip to content

Commit

Permalink
Add new unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander van Delft committed Dec 9, 2024
1 parent 3eb60ec commit 4d288c1
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace COMET.Web.Common.Tests.ViewModels.Components
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Model;
using COMET.Web.Common.Model.Configuration;
using COMET.Web.Common.Services.Cache;
using COMET.Web.Common.Services.ConfigurationService;
Expand Down Expand Up @@ -62,6 +64,13 @@ public void Setup()
this.viewModel = new OpenModelViewModel(this.sessionService.Object, this.configurationService.Object, this.cacheService.Object);
this.models = CreateData().ToList();
this.sessionService.Setup(x => x.GetParticipantModels()).Returns(this.models);

object result;
this.cacheService.Setup(x => x.TryGetBrowserSessionSetting(BrowserSessionSettingKey.LastUsedDomainOfExpertise, out result)).Returns(false);

this.cacheService.Setup(x => x.TryGetBrowserSessionSetting(BrowserSessionSettingKey.LastUsedEngineeringModel, out result)).Returns(false);

this.cacheService.Setup(x => x.TryGetBrowserSessionSetting(BrowserSessionSettingKey.LastUsedIterationData, out result)).Returns(false);
}

[Test]
Expand Down Expand Up @@ -101,7 +110,32 @@ public void VerifyInitializeViewModel()
serverConfiguration.RdlFilter.Kinds = new[] { EngineeringModelKind.STUDY_MODEL };
serverConfiguration.RdlFilter.RdlShortNames = Enumerable.Empty<string>();
this.viewModel.InitializesProperties();
Assert.That(this.viewModel.AvailableEngineeringModelSetups.Count(), Is.EqualTo(4));
Assert.That(this.viewModel.AvailableEngineeringModelSetups.Count(), Is.EqualTo(4));
}

[Test]
public void VerifyInitializeViewModelWithBrowserSessionSettings()
{
//Initialize without server configuration
this.viewModel.InitializesProperties();
Assert.That(this.viewModel.AvailableEngineeringModelSetups.Count(), Is.EqualTo(5));

var preselectedEngineeringModel = this.viewModel.AvailableEngineeringModelSetups.First();

object domainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), null, null);
object engineeringModelSetup = preselectedEngineeringModel;
object iterationData = new IterationData(preselectedEngineeringModel.IterationSetup.First());

this.cacheService.Setup(x => x.TryGetBrowserSessionSetting(BrowserSessionSettingKey.LastUsedDomainOfExpertise, out domainOfExpertise)).Returns(true);

this.cacheService.Setup(x => x.TryGetBrowserSessionSetting(BrowserSessionSettingKey.LastUsedEngineeringModel, out engineeringModelSetup)).Returns(true);

this.cacheService.Setup(x => x.TryGetBrowserSessionSetting(BrowserSessionSettingKey.LastUsedIterationData, out iterationData)).Returns(true);

this.viewModel.InitializesProperties();
Assert.That(this.viewModel.SelectedEngineeringModel, Is.EqualTo(engineeringModelSetup));
Assert.That(this.viewModel.SelectedIterationSetup, Is.EqualTo(iterationData));
Assert.That(this.viewModel.SelectedDomainOfExpertise, Is.EqualTo(domainOfExpertise));
}

private static List<EngineeringModelSetup> CreateData()
Expand Down

0 comments on commit 4d288c1

Please sign in to comment.