Skip to content

Commit

Permalink
Resolve nullability warnings on SegmentSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
sandermvanvliet committed May 24, 2023
1 parent 04741f1 commit c4ccef1
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 171 deletions.
20 changes: 4 additions & 16 deletions src/RoadCaptain.App.RouteBuilder/ViewModels/RouteViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,8 @@ public void StartOn(Segment segment)
}

_sequence.Add(new SegmentSequenceViewModel(
new SegmentSequence
{
SegmentId = segment.Id,
TurnToNextSegment = TurnDirection.None,
NextSegmentId = null,
Direction = segmentDirection,
Type = SegmentSequenceType.Regular
},
new SegmentSequence(segmentId: segment.Id, turnToNextSegment: TurnDirection.None, nextSegmentId: null,
direction: segmentDirection, type: SegmentSequenceType.Regular),
segment,
_sequence.Count + 1)
{
Expand Down Expand Up @@ -171,14 +165,8 @@ public void StartOn(Segment segment)
}

var segmentSequenceViewModel = new SegmentSequenceViewModel(
new SegmentSequence
{
SegmentId = ontoSegmentId,
TurnToNextSegment = TurnDirection.None,
NextSegmentId = null,
Direction = newSegmentDirection,
Type = newType
},
new SegmentSequence(segmentId: ontoSegmentId, turnToNextSegment: TurnDirection.None,
nextSegmentId: null, direction: newSegmentDirection, type: newType),
segment,
_sequence.Count + 1)
{
Expand Down
30 changes: 6 additions & 24 deletions src/RoadCaptain.App.Runner/ViewModels/DesignTimeInGameViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,12 @@ public DesignTimeInGameViewModel()
ZwiftRouteName = "The Mega Pretzel",
RouteSegmentSequence = new List<SegmentSequence>
{
new()
{
SegmentId = "seg-1",
NextSegmentId = "seg-2",
Direction = SegmentDirection.AtoB,
TurnToNextSegment = TurnDirection.GoStraight,
Type = SegmentSequenceType.Regular
},
new()
{
SegmentId = "seg-2",
NextSegmentId = "seg-3",
Direction = SegmentDirection.AtoB,
TurnToNextSegment = TurnDirection.GoStraight,
Type = SegmentSequenceType.Regular
},
new()
{
SegmentId = "seg-3",
NextSegmentId = null,
Direction = SegmentDirection.AtoB,
TurnToNextSegment = TurnDirection.GoStraight,
Type = SegmentSequenceType.Regular
}
new(segmentId: "seg-1", nextSegmentId: "seg-2", direction: SegmentDirection.AtoB,
turnToNextSegment: TurnDirection.GoStraight, type: SegmentSequenceType.Regular),
new(segmentId: "seg-2", nextSegmentId: "seg-3", direction: SegmentDirection.AtoB,
turnToNextSegment: TurnDirection.GoStraight, type: SegmentSequenceType.Regular),
new(segmentId: "seg-3", nextSegmentId: null, direction: SegmentDirection.AtoB,
turnToNextSegment: TurnDirection.GoStraight, type: SegmentSequenceType.Regular)
}
}
},
Expand Down
60 changes: 59 additions & 1 deletion src/RoadCaptain/SegmentSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,69 @@
// Licensed under Artistic License 2.0
// See LICENSE or https://choosealicense.com/licenses/artistic-2.0/

using Newtonsoft.Json;

namespace RoadCaptain
{
public class SegmentSequence
{
public string? SegmentId { get; set; }
[JsonConstructor]
public SegmentSequence(string segmentId, string? nextSegmentId, SegmentDirection direction, TurnDirection turnToNextSegment, SegmentSequenceType type)
{
SegmentId = segmentId;
NextSegmentId = nextSegmentId;
Direction = direction;
TurnToNextSegment = turnToNextSegment;
Type = type;
}

public SegmentSequence(string segmentId, SegmentDirection direction, SegmentSequenceType type)
{
SegmentId = segmentId;
Direction = direction;
Type = type;
}

public SegmentSequence(string segmentId, SegmentSequenceType type)
{
SegmentId = segmentId;
Type = type;
}

public SegmentSequence(string segmentId, string? nextSegmentId, SegmentDirection direction, TurnDirection turnToNextSegment)
{
SegmentId = segmentId;
NextSegmentId = nextSegmentId;
Direction = direction;
TurnToNextSegment = turnToNextSegment;
}

public SegmentSequence(string segmentId, SegmentSequenceType type, SegmentDirection direction, int index)
{
SegmentId = segmentId;
Type = type;
Direction = direction;
Index = index;
}

public SegmentSequence(string segmentId, SegmentDirection direction)
{
SegmentId = segmentId;
Direction = direction;
}

public SegmentSequence(string segmentId, string? nextSegmentId)
{
SegmentId = segmentId;
NextSegmentId = nextSegmentId;
}

public SegmentSequence(string segmentId)
{
SegmentId = segmentId;
}

public string SegmentId { get; set; }
public TurnDirection TurnToNextSegment { get; set; } = TurnDirection.None;
public string? NextSegmentId { get; set; }
public SegmentDirection Direction { get; set; } = SegmentDirection.Unknown;
Expand Down
24 changes: 4 additions & 20 deletions src/RoadCaptain/SegmentSequenceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ public SegmentSequenceBuilder()

public SegmentSequenceBuilder StartingAt(string segmentId)
{
var step = new SegmentSequence
{
SegmentId = segmentId,
Type = SegmentSequenceType.Regular
};
var step = new SegmentSequence(segmentId: segmentId, type: SegmentSequenceType.Regular);

_route.RouteSegmentSequence.Add(step);

Expand All @@ -40,11 +36,7 @@ public SegmentSequenceBuilder TurningLeftTo(string segmentId)
Last.NextSegmentId = segmentId;
Last.TurnToNextSegment = TurnDirection.Left;

var step = new SegmentSequence
{
SegmentId = segmentId,
Type = SegmentSequenceType.Regular
};
var step = new SegmentSequence(segmentId: segmentId, type: SegmentSequenceType.Regular);

_route.RouteSegmentSequence.Add(step);

Expand All @@ -56,11 +48,7 @@ public SegmentSequenceBuilder GoingStraightTo(string segmentId)
Last.NextSegmentId = segmentId;
Last.TurnToNextSegment = TurnDirection.GoStraight;

var step = new SegmentSequence
{
SegmentId = segmentId,
Type = SegmentSequenceType.Regular
};
var step = new SegmentSequence(segmentId: segmentId, type: SegmentSequenceType.Regular);

_route.RouteSegmentSequence.Add(step);

Expand All @@ -72,11 +60,7 @@ public SegmentSequenceBuilder TurningRightTo(string segmentId)
Last.NextSegmentId = segmentId;
Last.TurnToNextSegment = TurnDirection.Right;

var step = new SegmentSequence
{
SegmentId = segmentId,
Type = SegmentSequenceType.Regular
};
var step = new SegmentSequence(segmentId: segmentId, type: SegmentSequenceType.Regular);

_route.RouteSegmentSequence.Add(step);

Expand Down
5 changes: 5 additions & 0 deletions src/RoadCaptain/UseCases/ConnectToZwiftUseCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public async Task ExecuteAsync(ConnectCommand connectCommand)
{
var relayUri = await _zwift.RetrieveRelayUrl(connectCommand.AccessToken);

if (relayUri == null)
{
throw new Exception("Unable to retrieve the Zwift relay URI");
}

await _zwift.InitiateRelayAsync(connectCommand.AccessToken, relayUri, ipAddress, connectCommand.ConnectionEncryptionSecret);
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ private void GivenLoadedRoute()
World = new World { Id = "watopia" }
};

plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { Direction = SegmentDirection.AtoB, SegmentId = "watopia-beach-island-loop-001" });
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(direction: SegmentDirection.AtoB,
segmentId: "watopia-beach-island-loop-001"));
SetFieldValueByName("_loadedRoute", plannedRoute);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public void GivenPlannedRouteIsNull_ModelWithoutRouteIsReturned()
public void GivenPlannedRouteWithOneSegment_TotalDistanceIsLengthOfSegment()
{
var plannedRoute = new PlannedRoute();
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-1", Type = SegmentSequenceType.Regular, Direction = SegmentDirection.AtoB, Index = 0 });
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-1",
type: SegmentSequenceType.Regular, direction: SegmentDirection.AtoB, index: 0));

var result = RouteModel.From(plannedRoute, _segments, _markers);

Expand All @@ -78,7 +79,8 @@ public void GivenPlannedRouteWithOneSegment_TotalDistanceIsLengthOfSegment()
public void GivenPlannedRouteWithOneSegment_TotalAscentIsAscentOfSegment()
{
var plannedRoute = new PlannedRoute();
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-1", Type = SegmentSequenceType.Regular, Direction = SegmentDirection.AtoB, Index = 0 });
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-1",
type: SegmentSequenceType.Regular, direction: SegmentDirection.AtoB, index: 0));

var result = RouteModel.From(plannedRoute, _segments, _markers);

Expand All @@ -92,7 +94,8 @@ public void GivenPlannedRouteWithOneSegment_TotalAscentIsAscentOfSegment()
public void GivenPlannedRouteWithOneSegment_TotalDescentIsDescentOfSegment()
{
var plannedRoute = new PlannedRoute();
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-1", Type = SegmentSequenceType.Regular, Direction = SegmentDirection.AtoB, Index = 0 });
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-1",
type: SegmentSequenceType.Regular, direction: SegmentDirection.AtoB, index: 0));

var result = RouteModel.From(plannedRoute, _segments, _markers);

Expand All @@ -106,7 +109,8 @@ public void GivenPlannedRouteWithOneSegment_TotalDescentIsDescentOfSegment()
public void GivenPlannedRouteWithMarkerOnRoute_ResultingModelContainsMarker()
{
var plannedRoute = new PlannedRoute();
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-1", Type = SegmentSequenceType.Regular, Direction = SegmentDirection.AtoB, Index = 0 });
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-1",
type: SegmentSequenceType.Regular, direction: SegmentDirection.AtoB, index: 0));

var result = RouteModel.From(plannedRoute, _segments, _markers);

Expand All @@ -121,10 +125,8 @@ public void GivenPlannedRouteWithMarkerOnRoute_ResultingModelContainsMarker()
public void GivenPlannedRouteWithSegmentThatDoesntExist_MissingSegmentExceptionIsThrown()
{
var plannedRoute = new PlannedRoute();
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence
{
SegmentId = "seg-2", Type = SegmentSequenceType.Regular, Direction = SegmentDirection.AtoB, Index = 0
});
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-2",
type: SegmentSequenceType.Regular, direction: SegmentDirection.AtoB, index: 0));

Action action = () => RouteModel.From(plannedRoute, _segments, _markers);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ public void GivenOnSegmentStateIsReceivedAndRiderOnFirstSegmentOfRouteButWrongDi
public void GivenOnRouteStateAndRouteLockIsLost_InstructionIsMakeUTurn()
{
var plannedRoute = new PlannedRoute();
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-1", NextSegmentId = "seg-2"});
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-2", NextSegmentId = "seg-3"});
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-3", });
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-1", nextSegmentId: "seg-2"));
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-2", nextSegmentId: "seg-3"));
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-3"));
plannedRoute.EnteredSegment("seg-1");
plannedRoute.EnteredSegment("seg-2");
WhenUpdating(new OnRouteState(1, 2, new TrackPoint(1, 2, 3), new Segment(new List<TrackPoint>()) { Id = "seg-1"}, plannedRoute, SegmentDirection.AtoB, 0, 0, 0));
Expand All @@ -250,9 +250,9 @@ public void GivenOnRouteStateAndRouteLockIsLost_InstructionIsMakeUTurn()
public void GivenRouteLockWasLostAndUserReturnsToRoute_InstructionTextIsCleared()
{
var plannedRoute = new PlannedRoute();
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-1", NextSegmentId = "seg-2"});
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-2", NextSegmentId = "seg-3"});
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-3", });
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-1", nextSegmentId: "seg-2"));
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-2", nextSegmentId: "seg-3"));
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-3"));
plannedRoute.EnteredSegment("seg-1");
plannedRoute.EnteredSegment("seg-2");
WhenUpdating(new OnRouteState(1, 2, new TrackPoint(1, 2, 3), new Segment(new List<TrackPoint>()) { Id = "seg-1"}, plannedRoute, SegmentDirection.AtoB, 0, 0, 0));
Expand All @@ -268,9 +268,9 @@ public void GivenRouteLockWasLostAndUserReturnsToRoute_InstructionTextIsCleared(
public void GivenOnRouteStateIsReceived_NextSegmentIsTheSecondSegmentOfTheRoute()
{
var plannedRoute = new PlannedRoute();
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-1", NextSegmentId = "seg-2"});
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-2", NextSegmentId = "seg-3"});
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence { SegmentId = "seg-3", });
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-1", nextSegmentId: "seg-2"));
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-2", nextSegmentId: "seg-3"));
plannedRoute.RouteSegmentSequence.Add(new SegmentSequence(segmentId: "seg-3"));
plannedRoute.EnteredSegment("seg-1");
WhenUpdating(new OnRouteState(1, 2, new TrackPoint(1, 2, 3), new Segment(new List<TrackPoint>()) { Id = "seg-1"}, plannedRoute, SegmentDirection.AtoB, 0, 0, 0));

Expand All @@ -295,21 +295,9 @@ public WhenUpdatingGameState()
World = _world,
RouteSegmentSequence =
{
new SegmentSequence
{
Direction = SegmentDirection.AtoB,
SegmentId = "seg-1"
},
new SegmentSequence
{
Direction = SegmentDirection.AtoB,
SegmentId = "seg-2"
},
new SegmentSequence
{
Direction = SegmentDirection.AtoB,
SegmentId = "seg-3"
}
new SegmentSequence(direction: SegmentDirection.AtoB, segmentId: "seg-1"),
new SegmentSequence(direction: SegmentDirection.AtoB, segmentId: "seg-2"),
new SegmentSequence(direction: SegmentDirection.AtoB, segmentId: "seg-3")
}
}
};
Expand Down
Loading

0 comments on commit c4ccef1

Please sign in to comment.