Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sandermvanvliet committed May 31, 2023
1 parent f80b22c commit fa0382c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under Artistic License 2.0
// See LICENSE or https://choosealicense.com/licenses/artistic-2.0/

using System;
using FluentAssertions;
using RoadCaptain.Adapters;
using RoadCaptain.App.Runner.ViewModels;
Expand Down Expand Up @@ -39,7 +40,7 @@ public void OpenFileDialogIsOpened()
LoadRoute();

_windowService
.OpenFileDialogInvocations
.ShowSelectRouteDialogInvocations
.Should()
.Be(1);
}
Expand All @@ -60,17 +61,17 @@ public void GivenOpenFileDialogIsCanceled_RoutePathRetainsOriginalValue()
}

[Fact]
public void GivenUserSelectedFile_RoutePathIsSet()
public void GivenUserSelectedRoute_RoutePathIsSet()
{
_viewModel.RoutePath = null;
_windowService.OpenFileDialogResult = "someroute.json";
_windowService.ShowSelectRouteDialogResult = new RouteModel { Uri = new Uri("file:///c:/temp/someroute.json")};

LoadRoute();

_viewModel
.RoutePath
.Should()
.Be("someroute.json");
.Be("file:///c:/temp/someroute.json");
}

[Fact]
Expand All @@ -88,7 +89,7 @@ public void GivenUserSelectedFile_RouteIsLoaded()
public void GivenUserSelectedFile_WindowTitleIsUpdatedWithRouteFileName()
{
_viewModel.RoutePath = null;
_windowService.OpenFileDialogResult = "someroute.json";
_windowService.ShowSelectRouteDialogResult = new RouteModel { Uri = new Uri("file:///c:/temp/someroute.json")};

LoadRoute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class WhenCallingStartRouteCommand
private readonly InMemoryGameStateDispatcher _gameStateDispatcher;
private readonly DummyUserPreferences _userPreferences;
private readonly Configuration _configuration;
private StubWindowService _windowService;
private readonly StubWindowService _windowService;
private readonly PlannedRoute _plannedRoute;

public WhenCallingStartRouteCommand()
{
Expand All @@ -32,6 +33,8 @@ public WhenCallingStartRouteCommand()
_configuration = new Configuration(null);

StubRouteStore routeStore = new();
_plannedRoute = routeStore.LoadFrom("someroute.json");

_viewModel = new MainWindowViewModel(
_configuration,
_userPreferences,
Expand All @@ -49,7 +52,7 @@ public WhenCallingStartRouteCommand()
[Fact]
public void RoutePathIsStoredInUserPreferences()
{
_windowService.OpenFileDialogResult = "someroute.json";
_windowService.ShowSelectRouteDialogResult = new RouteModel { Uri = new Uri("file:///c:/temp/someroute.json"), PlannedRoute = _plannedRoute };
_viewModel.LoadRouteCommand.Execute(null);

StartRoute();
Expand All @@ -64,7 +67,7 @@ public void RoutePathIsStoredInUserPreferences()
[Fact]
public void RoutePathIsStoredInConfiguration()
{
_windowService.OpenFileDialogResult = "someroute.json";
_windowService.ShowSelectRouteDialogResult = new RouteModel { Uri = new Uri("file:///c:/temp/someroute.json"), PlannedRoute = _plannedRoute };
_viewModel.LoadRouteCommand.Execute(null);

StartRoute();
Expand All @@ -78,7 +81,7 @@ public void RoutePathIsStoredInConfiguration()
[Fact]
public void StartRouteIsDispatched()
{
_windowService.OpenFileDialogResult = "someroute.json";
_windowService.ShowSelectRouteDialogResult = new RouteModel { Uri = new Uri("file:///c:/temp/someroute.json"), PlannedRoute = _plannedRoute };
_viewModel.LoadRouteCommand.Execute(null);

StartRoute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ public class StubWindowService : IWindowService
public int LogInDialogInvocations { get; private set; }
public int MainWindowInvocations { get; private set; }
public int ErrorDialogInvocations { get; private set; }
public int ShowSelectRouteDialogInvocations { get; private set; }
public Dictionary<Type, object> Overrides { get; } = new();

public List<Type> ClosedWindows { get; } = new();
public List<Type> ShownWindows { get; } = new();
public RouteModel? ShowSelectRouteDialogResult { get; set; }

public Task ShowErrorDialog(string message, Window owner)
{
Expand Down Expand Up @@ -76,7 +78,8 @@ public void ToggleElevationPlot(PlannedRoute? plannedRoute, bool? show)

public Task<RouteModel?> ShowSelectRouteDialog()
{
throw new NotImplementedException();
ShowSelectRouteDialogInvocations++;
return Task.FromResult<RouteModel?>(ShowSelectRouteDialogResult);
}

public Task<string?> ShowOpenFileDialog(string? previousLocation)
Expand Down

0 comments on commit fa0382c

Please sign in to comment.