public void TestDeserializeSimulationException() { SimulationException exception = new SimulationException("Custom message", "Name of the simulation", "The filename"); using (Stream stream = ReflectionUtilities.BinarySerialise(exception)) { stream.Seek(0, SeekOrigin.Begin); SimulationException cloned = (SimulationException)ReflectionUtilities.BinaryDeserialise(stream); Assert.AreEqual(exception.Message, cloned.Message); Assert.AreEqual(exception.SimulationName, cloned.SimulationName); Assert.AreEqual(exception.FileName, cloned.FileName); } }
public void WhenLocationIsConstructedWithInvalidValues_ShouldThrowException(int x, int y) { SimulationException ex = null; try { var location = new Location(x, y); } catch (SimulationException e) { ex = e; } Assert.That(ex, Is.Not.Null); }
public void WhenOrientationIsConstructedWithInvalidDirection_ShouldThrowException(string input) { SimulationException exception = null; try { var orientation = new Orientation(input); } catch (SimulationException e) { exception = e; } Assert.That(exception, Is.Not.Null); Assert.That(exception.Message, Is.EqualTo(ErrorMessages.InvalidDirectionMessage)); }
public void Place_WhenGivenDirectionIsInvalid_ShouldThrownException() { var brain = new RobotBrain(); SimulationException exception = null; try { PlaceCommandParameter placementParam = new PlaceCommandParameter(1, 1, "north-ish"); brain.Place(placementParam); } catch (SimulationException e) { exception = e; } Assert.That(exception, Is.Not.Null); }
public void ParseCommand_WhenTheInputIsInvalidCommands_ShouldThrowException(string input, string expectedErrorMessage) { var parser = new InputParser(); SimulationException exception = null; try { var command = parser.ParseCommand(input); } catch (SimulationException e) { exception = e; } Assert.That(exception, Is.Not.Null); Assert.That(exception.Message, Is.EqualTo(expectedErrorMessage)); }
public void ProcessPlaceCommand_WhenCommandHasInvalidLocation_ShouldIgnorePlaceCommand() { var robot = new Domain.Robot(new Domain.RobotBrain()); SimulationException exception = null; try { Domain.PlaceCommandParameter placementParam = new PlaceCommandParameter(-1, -1, Direction.NORTH.ToString()); robot.Process(new Domain.Command(CommandType.PLACE, placementParam)); } catch (SimulationException e) { exception = e; } Assert.That(exception, Is.Not.Null); Assert.That(exception.Message, Is.EqualTo(ErrorMessages.InvalidLocationParameters)); }
public void ProcessPlaceCommand_WhenCommandHasInvalidDirection_ShouldIgnorePlaceCommand() { var robot = new Domain.Robot(new RobotBrain()); SimulationException exception = null; try { PlaceCommandParameter placementParam = new PlaceCommandParameter(1, 1, "north-ish"); robot.Process(new Command(CommandType.PLACE, placementParam)); } catch (SimulationException e) { exception = e; } Assert.That(exception, Is.Not.Null); Assert.That(exception.Message, Is.EqualTo(ErrorMessages.InvalidDirectionMessage)); }
FaultResult _runFaultSimulation(IFaultDefinition faultDefinition, IPlatformEngine sim) { sim.Init(); faultDefinition.InitSimulator(sim); var simResult = Result.Exception; SimulationException simException = null; try { simResult = sim.Run(); } catch (SimulationException e) { simException = e; } return(new FaultResult { Fault = faultDefinition, Result = simResult, Exception = simException }); }