Skip to content

Commit

Permalink
Added tests in BusinessLogic
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinHo64 committed May 28, 2024
1 parent c84d366 commit 8bcf9ae
Show file tree
Hide file tree
Showing 19 changed files with 768 additions and 102 deletions.
20 changes: 10 additions & 10 deletions BusinessLogic/Commands/Layout/ChangeLearningSpaceLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace BusinessLogic.Commands.Layout;

public class ChangeLearningSpaceLayout : IChangeLearningSpaceLayout
{
private IMemento? _mementoSpace;
private IMemento? _mementoSpaceLayout;
private IMemento? _mementoWorld;
internal IMemento? MementoSpace;
internal IMemento? MementoSpaceLayout;

public ChangeLearningSpaceLayout(ILearningSpace learningSpace, LearningWorld learningWorld,
FloorPlanEnum floorPlanName, Action<LearningWorld> mappingAction, ILogger<ChangeLearningSpaceLayout> logger)
Expand All @@ -30,8 +30,8 @@ public ChangeLearningSpaceLayout(ILearningSpace learningSpace, LearningWorld lea

public void Execute()
{
_mementoSpaceLayout = LearningSpace.LearningSpaceLayout.GetMemento();
_mementoSpace = LearningSpace.GetMemento();
MementoSpaceLayout = LearningSpace.LearningSpaceLayout.GetMemento();
MementoSpace = LearningSpace.GetMemento();
_mementoWorld = LearningWorld.GetMemento();

LearningSpace.UnsavedChanges = true;
Expand Down Expand Up @@ -74,23 +74,23 @@ public void Execute()

public void Undo()
{
if (_mementoSpaceLayout == null)
if (MementoSpaceLayout == null)
{
throw new InvalidOperationException("_mementoSpaceLayout is null");
throw new InvalidOperationException("MementoSpaceLayout is null");
}

if (_mementoSpace == null)
if (MementoSpace == null)
{
throw new InvalidOperationException("_mementoSpace is null");
throw new InvalidOperationException("MementoSpace is null");
}

if (_mementoWorld == null)
{
throw new InvalidOperationException("_mementoWorld is null");
}

LearningSpace.LearningSpaceLayout.RestoreMemento(_mementoSpaceLayout);
LearningSpace.RestoreMemento(_mementoSpace);
LearningSpace.LearningSpaceLayout.RestoreMemento(MementoSpaceLayout);
LearningSpace.RestoreMemento(MementoSpace);
LearningWorld.RestoreMemento(_mementoWorld);

Logger.LogTrace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace BusinessLogic.Commands.Layout;
/// </summary>
public class PlaceLearningElementInLayoutFromLayout : IPlaceLearningElementInLayoutFromLayout
{
private IMemento? _mementoLayout;
private IMemento? _mementoSpace;
internal IMemento? MementoLayout;

public PlaceLearningElementInLayoutFromLayout(LearningSpace parentSpace, ILearningElement learningElement,
int newSlotIndex,
Expand All @@ -31,7 +31,7 @@ public PlaceLearningElementInLayoutFromLayout(LearningSpace parentSpace, ILearni

public void Execute()
{
_mementoLayout = ParentSpace.LearningSpaceLayout.GetMemento();
MementoLayout = ParentSpace.LearningSpaceLayout.GetMemento();
_mementoSpace = ParentSpace.GetMemento();

ParentSpace.UnsavedChanges = true;
Expand All @@ -55,17 +55,17 @@ public void Execute()

public void Undo()
{
if (_mementoLayout == null)
if (MementoLayout == null)
{
throw new InvalidOperationException("_mementoLayout is null");
throw new InvalidOperationException("MementoLayout is null");
}

if (_mementoSpace == null)
{
throw new InvalidOperationException("_mementoSpace is null");
}

ParentSpace.LearningSpaceLayout.RestoreMemento(_mementoLayout);
ParentSpace.LearningSpaceLayout.RestoreMemento(MementoLayout);
ParentSpace.RestoreMemento(_mementoSpace);

Logger.LogTrace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace BusinessLogic.Commands.Layout;
/// </summary>
public class PlaceLearningElementInLayoutFromUnplaced : IPlaceLearningElementInLayoutFromUnplaced
{
private IMemento? _mementoSpace;
private IMemento? _mementoSpaceLayout;
private IMemento? _mementoWorld;
internal IMemento? MementoSpace;
internal IMemento? MementoWorld;

public PlaceLearningElementInLayoutFromUnplaced(LearningWorld learningWorld, LearningSpace learningSpace,
ILearningElement learningElement, int newSlotIndex, Action<LearningWorld> mappingAction,
Expand All @@ -34,8 +34,8 @@ public PlaceLearningElementInLayoutFromUnplaced(LearningWorld learningWorld, Lea

public void Execute()
{
_mementoWorld = LearningWorld.GetMemento();
_mementoSpace = LearningSpace.GetMemento();
MementoWorld = LearningWorld.GetMemento();
MementoSpace = LearningSpace.GetMemento();
_mementoSpaceLayout = LearningSpace.LearningSpaceLayout.GetMemento();

LearningSpace.UnsavedChanges = true;
Expand Down Expand Up @@ -67,23 +67,23 @@ public void Execute()

public void Undo()
{
if (_mementoWorld == null)
if (MementoWorld == null)
{
throw new InvalidOperationException("_mementoWorld is null");
throw new InvalidOperationException("MementoWorld is null");
}

if (_mementoSpace == null)
if (MementoSpace == null)
{
throw new InvalidOperationException("_mementoSpace is null");
throw new InvalidOperationException("MementoSpace is null");
}

if (_mementoSpaceLayout == null)
{
throw new InvalidOperationException("_mementoSpaceLayout is null");
}

LearningWorld.RestoreMemento(_mementoWorld);
LearningSpace.RestoreMemento(_mementoSpace);
LearningWorld.RestoreMemento(MementoWorld);
LearningSpace.RestoreMemento(MementoSpace);
LearningSpace.LearningSpaceLayout.RestoreMemento(_mementoSpaceLayout);

Logger.LogTrace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@ namespace BusinessLogic.Commands.Layout;

public class PlaceStoryElementInLayoutFromLayout : IPlaceStoryElementInLayoutFromLayout
{
private IMemento? _mementoLayout;
private IMemento? _mementoSpace;
internal IMemento? MementoLayout;

public PlaceStoryElementInLayoutFromLayout(LearningSpace parentSpace, ILearningElement learningElement,
int newSlotIndex, Action<LearningSpace> mappingAction,
ILogger<PlaceStoryElementInLayoutFromLayout> logger)
{
ParentSpace = parentSpace;
LearningElement = ParentSpace.LearningSpaceLayout.StoryElements.First(x => x.Value.Id == learningElement.Id).Value;
LearningElement = ParentSpace.LearningSpaceLayout.StoryElements.First(x => x.Value.Id == learningElement.Id)
.Value;
NewSlotIndex = newSlotIndex;
MappingAction = mappingAction;
Logger = logger;
}

internal LearningSpace ParentSpace { get; }
internal int NewSlotIndex { get; }
internal ILearningElement LearningElement { get; }
internal Action<LearningSpace> MappingAction { get; }
internal ILogger<PlaceStoryElementInLayoutFromLayout> Logger { get; }
public string Name => nameof(PlaceStoryElementInLayoutFromLayout);

public void Execute()
{
_mementoLayout = ParentSpace.LearningSpaceLayout.GetMemento();
MementoLayout = ParentSpace.LearningSpaceLayout.GetMemento();
_mementoSpace = ParentSpace.GetMemento();

ParentSpace.UnsavedChanges = true;
Expand All @@ -50,17 +53,17 @@ public void Execute()

public void Undo()
{
if (_mementoLayout == null)
if (MementoLayout == null)
{
throw new InvalidOperationException("_mementoLayout is null");
throw new InvalidOperationException("MementoLayout is null");
}

if (_mementoSpace == null)
{
throw new InvalidOperationException("_mementoSpace is null");
}

ParentSpace.LearningSpaceLayout.RestoreMemento(_mementoLayout);
ParentSpace.LearningSpaceLayout.RestoreMemento(MementoLayout);
ParentSpace.RestoreMemento(_mementoSpace);

Logger.LogTrace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace BusinessLogic.Commands.Layout;

public class PlaceStoryElementInLayoutFromUnplaced : IPlaceStoryElementInLayoutFromUnplaced
{
private IMemento? _mementoSpace;
private IMemento? _mementoSpaceLayout;
private IMemento? _mementoWorld;
internal IMemento? MementoSpace;
internal IMemento? MementoWorld;

public PlaceStoryElementInLayoutFromUnplaced(LearningWorld learningWorld, LearningSpace learningSpace,
ILearningElement learningElement, int newSlotIndex, Action<LearningWorld> mappingAction,
Expand All @@ -32,8 +32,8 @@ public PlaceStoryElementInLayoutFromUnplaced(LearningWorld learningWorld, Learni

public void Execute()
{
_mementoWorld = LearningWorld.GetMemento();
_mementoSpace = LearningSpace.GetMemento();
MementoWorld = LearningWorld.GetMemento();
MementoSpace = LearningSpace.GetMemento();
_mementoSpaceLayout = LearningSpace.LearningSpaceLayout.GetMemento();

LearningSpace.UnsavedChanges = true;
Expand Down Expand Up @@ -65,23 +65,23 @@ public void Execute()

public void Undo()
{
if (_mementoWorld == null)
if (MementoWorld == null)
{
throw new InvalidOperationException("_mementoWorld is null");
throw new InvalidOperationException("MementoWorld is null");
}

if (_mementoSpace == null)
if (MementoSpace == null)
{
throw new InvalidOperationException("_mementoSpace is null");
throw new InvalidOperationException("MementoSpace is null");
}

if (_mementoSpaceLayout == null)
{
throw new InvalidOperationException("_mementoSpaceLayout is null");
}

LearningWorld.RestoreMemento(_mementoWorld);
LearningSpace.RestoreMemento(_mementoSpace);
LearningWorld.RestoreMemento(MementoWorld);
LearningSpace.RestoreMemento(MementoSpace);
LearningSpace.LearningSpaceLayout.RestoreMemento(_mementoSpaceLayout);

Logger.LogTrace(
Expand Down
20 changes: 10 additions & 10 deletions BusinessLogic/Commands/Layout/RemoveLearningElementFromLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace BusinessLogic.Commands.Layout;

public class RemoveLearningElementFromLayout : IRemoveLearningElementFromLayout
{
private IMemento? _mementoSpace;
private IMemento? _mementoSpaceLayout;
private IMemento? _mementoWorld;
internal IMemento? MementoSpace;
internal IMemento? MementoWorld;

public RemoveLearningElementFromLayout(LearningWorld learningWorld, LearningSpace learningSpace,
ILearningElement learningElement, Action<LearningWorld> mappingAction,
Expand All @@ -29,8 +29,8 @@ public RemoveLearningElementFromLayout(LearningWorld learningWorld, LearningSpac

public void Execute()
{
_mementoWorld = LearningWorld.GetMemento();
_mementoSpace = LearningSpace.GetMemento();
MementoWorld = LearningWorld.GetMemento();
MementoSpace = LearningSpace.GetMemento();
_mementoSpaceLayout = LearningSpace.LearningSpaceLayout.GetMemento();

LearningSpace.UnsavedChanges = true;
Expand All @@ -55,23 +55,23 @@ public void Execute()

public void Undo()
{
if (_mementoWorld is null)
if (MementoWorld is null)
{
throw new InvalidOperationException("_mementoWorld is null");
throw new InvalidOperationException("MementoWorld is null");
}

if (_mementoSpace is null)
if (MementoSpace is null)
{
throw new InvalidOperationException("_mementoSpace is null");
throw new InvalidOperationException("MementoSpace is null");
}

if (_mementoSpaceLayout is null)
{
throw new InvalidOperationException("_mementoSpaceLayout is null");
}

LearningWorld.RestoreMemento(_mementoWorld);
LearningSpace.RestoreMemento(_mementoSpace);
LearningWorld.RestoreMemento(MementoWorld);
LearningSpace.RestoreMemento(MementoSpace);
LearningSpace.LearningSpaceLayout.RestoreMemento(_mementoSpaceLayout);

Logger.LogTrace(
Expand Down
28 changes: 16 additions & 12 deletions BusinessLogic/Commands/Layout/RemoveStoryElementFromLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ namespace BusinessLogic.Commands.Layout;

public class RemoveStoryElementFromLayout : IRemoveStoryElementFromLayout
{
private IMemento? _mementoSpace;
private IMemento? _mementoSpaceLayout;
private IMemento? _mementoWorld;
internal IMemento? MementoSpace;
internal IMemento? MementoWorld;

public RemoveStoryElementFromLayout(LearningWorld learningWorld, LearningSpace learningSpace, ILearningElement learningElement, Action<LearningWorld> mappingAction, ILogger<RemoveStoryElementFromLayout> logger)
public RemoveStoryElementFromLayout(LearningWorld learningWorld, LearningSpace learningSpace,
ILearningElement learningElement, Action<LearningWorld> mappingAction,
ILogger<RemoveStoryElementFromLayout> logger)
{
LearningWorld = learningWorld;
LearningSpace = LearningWorld.LearningSpaces.First(x => x.Id == learningSpace.Id);
LearningElement = LearningSpace.LearningSpaceLayout.StoryElements.First(x => x.Value.Id == learningElement.Id).Value;
LearningElement = LearningSpace.LearningSpaceLayout.StoryElements.First(x => x.Value.Id == learningElement.Id)
.Value;
MappingAction = mappingAction;
Logger = logger;
}
Expand All @@ -25,10 +28,11 @@ public RemoveStoryElementFromLayout(LearningWorld learningWorld, LearningSpace l
internal Action<LearningWorld> MappingAction { get; }
internal ILogger<RemoveStoryElementFromLayout> Logger { get; }
public string Name => nameof(RemoveStoryElementFromLayout);

public void Execute()
{
_mementoWorld = LearningWorld.GetMemento();
_mementoSpace = LearningSpace.GetMemento();
MementoWorld = LearningWorld.GetMemento();
MementoSpace = LearningSpace.GetMemento();
_mementoSpaceLayout = LearningSpace.LearningSpaceLayout.GetMemento();

LearningSpace.UnsavedChanges = true;
Expand All @@ -53,23 +57,23 @@ public void Execute()

public void Undo()
{
if (_mementoWorld is null)
if (MementoWorld is null)
{
throw new InvalidOperationException("_mementoWorld is null");
throw new InvalidOperationException("MementoWorld is null");
}

if (_mementoSpace is null)
if (MementoSpace is null)
{
throw new InvalidOperationException("_mementoSpace is null");
throw new InvalidOperationException("MementoSpace is null");
}

if (_mementoSpaceLayout is null)
{
throw new InvalidOperationException("_mementoSpaceLayout is null");
}

LearningWorld.RestoreMemento(_mementoWorld);
LearningSpace.RestoreMemento(_mementoSpace);
LearningWorld.RestoreMemento(MementoWorld);
LearningSpace.RestoreMemento(MementoSpace);
LearningSpace.LearningSpaceLayout.RestoreMemento(_mementoSpaceLayout);

Logger.LogTrace(
Expand Down
Loading

0 comments on commit 8bcf9ae

Please sign in to comment.