Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace RedCatEngine.StateMachine.Exceptions
{
public class QueueStateIsEmptyException : Exception
{
public string StateMachineName;

public QueueStateIsEmptyException(string stateMachineName)
: base(string.Format("Queue is empty in state machine {0}", stateMachineName))
{
StateMachineName = stateMachineName;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public ITypedQueueStateMachine Enter<TState, TPayload>(TPayload payload)

public ITypedQueueStateMachine EnterNextFromQueue()
{
if (_queue.Count == 0)
throw new QueueStateIsEmptyException(_name);

var data = _queue.Dequeue();
AddToHistory(data);
var nextState = SelectStateAsActive(data.StateType);
Expand Down Expand Up @@ -152,4 +155,4 @@ protected virtual TBaseState GetState(Type type)
return targetState;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,26 @@ public void GivenStateMachine_WhenEnterUnknownState_ThenCatchNotFoundStateExcept

Assert.IsTrue(false, "Not catch exception");
}

[Test]
public void GivenStateMachine_WhenEnterNextFromEmptyQueue_ThenCatchQueueStateIsEmptyException()
{
try
{
_stateMachine.EnterNextFromQueue();
}
catch (Exception exception)
{
Assert.IsTrue(
exception is QueueStateIsEmptyException,
"Catch incorrect error");
Assert.IsTrue(
exception.Message.Contains("TestedTypedStateMachine"),
"State machine name is not specified in exception message");
return;
}

Assert.IsTrue(false, "Not catch exception");
}
}
}
}
Loading