Skip to content

Commit

Permalink
Fix ParameterEditorBodyViewModelTestFixture test because of missing m…
Browse files Browse the repository at this point in the history
…ock session definition
  • Loading branch information
mserra-github committed Nov 20, 2023
1 parent ecc5448 commit 7dae8f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public abstract class ApplicationBaseViewModel : HaveObjectChangedTracking, IApp
protected ApplicationBaseViewModel(ISessionService sessionService)
{
this.Disposables.Add(CDPMessageBus.Current.Listen<SessionEvent>()
.Where(x => x.Session == this.SessionService.Session && x.Status == SessionStatus.EndUpdate)
.Where(x => x.Session == this.SessionService?.Session && x.Status == SessionStatus.EndUpdate)
.SubscribeAsync(_ => this.OnSessionRefreshed()));

this.SessionService = sessionService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// <copyright file="ParameterEditorBodyViewModelTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2023 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Miguel Serra
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
Expand Down Expand Up @@ -56,6 +56,7 @@ public class ParameterEditorBodyViewModelTestFixture
private IParameterEditorBodyViewModel viewModel;
private Mock<IParameterTableViewModel> tableViewModel;
private Iteration iteration;
private Mock<ISession> session;

[SetUp]
public void SetUp()
Expand Down Expand Up @@ -209,11 +210,11 @@ public void SetUp()
this.iteration.DefaultOption = this.iteration.Option.First();

var sessionService = new Mock<ISessionService>();
var session = new Mock<ISession>();
this.session = new Mock<ISession>();
var permissionService = new Mock<IPermissionService>();
permissionService.Setup(x => x.CanWrite(It.IsAny<Thing>())).Returns(true);
session.Setup(x => x.PermissionService).Returns(permissionService.Object);
sessionService.Setup(x => x.Session).Returns(session.Object);
this.session.Setup(x => x.PermissionService).Returns(permissionService.Object);
sessionService.Setup(x => x.Session).Returns(this.session.Object);
sessionService.Setup(x => x.GetDomainOfExpertise(this.iteration)).Returns(domain);

var subscriptionService = new Mock<ISubscriptionService>();
Expand Down Expand Up @@ -281,7 +282,7 @@ public async Task VerifyApplyFilters()
[Test]
public async Task VerifyRefresh()
{
CDPMessageBus.Current.SendMessage(new SessionEvent(null, SessionStatus.EndUpdate));
CDPMessageBus.Current.SendMessage(new SessionEvent(this.session.Object, SessionStatus.EndUpdate));

Assert.Multiple(() =>
{
Expand All @@ -297,19 +298,19 @@ public async Task VerifyRefresh()

this.iteration.Element.Add(elementDefinition);
CDPMessageBus.Current.SendObjectChangeEvent(elementDefinition, EventKind.Added);
CDPMessageBus.Current.SendMessage(new SessionEvent(null, SessionStatus.EndUpdate));
CDPMessageBus.Current.SendMessage(new SessionEvent(this.session.Object, SessionStatus.EndUpdate));

await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);
this.tableViewModel.Verify(x => x.AddRows(It.Is<IEnumerable<Thing>>(c => c.Any())), Times.Once);

CDPMessageBus.Current.SendObjectChangeEvent(elementDefinition, EventKind.Updated);
CDPMessageBus.Current.SendMessage(new SessionEvent(null, SessionStatus.EndUpdate));
CDPMessageBus.Current.SendMessage(new SessionEvent(this.session.Object, SessionStatus.EndUpdate));

await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);
this.tableViewModel.Verify(x => x.UpdateRows(It.Is<IEnumerable<Thing>>(c => c.Any())), Times.Once);

CDPMessageBus.Current.SendObjectChangeEvent(elementDefinition, EventKind.Removed);
CDPMessageBus.Current.SendMessage(new SessionEvent(null, SessionStatus.EndUpdate));
CDPMessageBus.Current.SendMessage(new SessionEvent(this.session.Object, SessionStatus.EndUpdate));

await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);
this.tableViewModel.Verify(x => x.RemoveRows(It.Is<IEnumerable<Thing>>(c => c.Any())), Times.Once);
Expand All @@ -319,7 +320,7 @@ public async Task VerifyRefresh()
Container = new Iteration()
}, EventKind.Removed);

CDPMessageBus.Current.SendMessage(new SessionEvent(null, SessionStatus.EndUpdate));
CDPMessageBus.Current.SendMessage(new SessionEvent(this.session.Object, SessionStatus.EndUpdate));

await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);
this.tableViewModel.Verify(x => x.RemoveRows(It.Is<IEnumerable<Thing>>(c => c.Any())), Times.Once);
Expand Down

0 comments on commit 7dae8f3

Please sign in to comment.