Esempio n. 1
0
        private static ISampleProvider CreateSampleProvider(BinaryReader binaryReader)
        {
            var reader   = new StreamSequentialReader(binaryReader);
            var header   = HeaderReader.Read(reader);
            var commands = CommandsReader.Read(header, reader);
            var values   = Renderer.Render(commands);
            var provider = new EnumerableSampleProvider(values);

            return(provider);
        }
        public void GetCommands_NoDirectory_ThrowsException()
        {
            //Arrange
            var            mockFileReader = new Mock <IFileReader>();
            CommandsReader commandsReader = new CommandsReader(mockFileReader.Object);

            //Act and Assert
            ArgumentNullException exception = Assert.Throws <ArgumentNullException>(() => commandsReader.GetCommands(null, null));

            Assert.AreEqual("Value cannot be null. (Parameter 'directory')", exception.Message);
        }
        public void GetCommands_ReadFileWithOneCommand_GetOneCommand()
        {
            //Arrange
            var commandsFile   = @"PLACE 1,1,NORTH";
            var mockFileReader = new Mock <IFileReader>();

            mockFileReader.Setup(mockFileReader => mockFileReader.ReadAllText(It.IsAny <string>(), It.IsAny <string>())).Returns(commandsFile);
            CommandsReader commandsReader = new CommandsReader(mockFileReader.Object);

            //Act
            string[] commands = commandsReader.GetCommands("directory", "filePath");

            //Assert
            Assert.AreEqual(1, commands.Length);
            Assert.AreEqual("PLACE 1,1,NORTH", commands[0]);
        }
Esempio n. 4
0
        private static void ProcessVgm(string fileName, VgmFileProcessor processor)
        {
            var fileInfo = new FileInfo(fileName);

            using (var stream = new GZipStream(fileInfo.OpenRead(), CompressionMode.Decompress))
            {
                using (var binaryReader = new BinaryReader(stream))
                {
                    var reader = new StreamSequentialReader(binaryReader);

                    var header   = HeaderReader.Read(reader);
                    var commands = CommandsReader.Read(header, reader);

                    processor(fileName, header, commands);
                }
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            IErrorReporter errorReporter = new ErrorReporter();

            try
            {
                var      commandsReader = new CommandsReader(new SystemIoFileReader());
                string[] commands       = commandsReader.GetCommands("Resources", "commands.txt");

                IPlaceManager placeManager      = new PlaceManager();
                var           toyRobotSimulator = new Simulator(placeManager, errorReporter);
                toyRobotSimulator.Run(commands);
            }
            catch (Exception exception)
            {
                errorReporter.Send(exception);
            }
            Console.Read();
        }