コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
ファイル: RobotTests.cs プロジェクト: has-taiar/Toy.Robot
        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));
        }
コード例 #7
0
ファイル: RobotTests.cs プロジェクト: has-taiar/Toy.Robot
        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));
        }
コード例 #8
0
        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
            });
        }