示例#1
0
        public void WhenValidHistoryDataIsLoadedFromCsvFile_ShouldYieldCorrectValues()
        {
            //Arrange
            var expectedResult = new HistoryAnalysis
            {
                AnalysedDuration         = new TimeSpan(7, 45, 0),
                DriverRating             = 0.7638m,
                DriverRatingAfterPenalty = 0.3819m
            };
            var fileName = "History.csv";
            //Get the path of directory in which data files are kept from the configuration file
            //Combine the directory path with the file name provided as input
            string path    = Path.Combine(ConfigurationManager.AppSettings["CannedDataDirectoryPath"], fileName);
            var    reader  = ContentReaderLookup.GetContentReader();
            var    content = reader.ReadData(path);
            var    parser  = DataParserLookup.GetParser("Csv");
            var    data    = parser.ParseData(content);

            //Act
            var actualResult = analyser.Analyse(data);

            //Assert
            Assert.That(actualResult.AnalysedDuration, Is.EqualTo(expectedResult.AnalysedDuration));
            Assert.That(actualResult.DriverRating, Is.EqualTo(expectedResult.DriverRating).Within(0.001m));
            Assert.That(actualResult.DriverRatingAfterPenalty, Is.EqualTo(expectedResult.DriverRatingAfterPenalty).Within(0.001m));
        }
        public void Execute()
        {
            //Get the path of directory in which data files are kept from the configuration file
            //Combine the directory path with the file name provided as input
            string path     = Path.Combine(ConfigurationManager.AppSettings["CannedDataDirectoryPath"], _source);
            var    reader   = ContentReaderLookup.GetContentReader();
            var    parser   = DataParserLookup.GetParser("Csv");
            var    data     = parser.ParseData(reader.ReadData(path));
            var    analysis = _analyser.Analyse(data);

            Console.Out.WriteLine($"Analysed period: {analysis.AnalysedDuration:g}");
            Console.Out.WriteLine($"Driver rating: {analysis.DriverRating:P}");
            Console.Out.WriteLine($"Driver rating after penalty: {analysis.DriverRatingAfterPenalty:P}");
        }
示例#3
0
        public void WhenCorrectFileIsPassed_ShouldLoadAppropriateData()
        {
            //Arrange
            var fileName = "History.csv";
            //Get the path of directory in which data files are kept from the configuration file
            //Combine the directory path with the file name provided as input
            string path    = Path.Combine(ConfigurationManager.AppSettings["CannedDataDirectoryPath"], fileName);
            var    reader  = ContentReaderLookup.GetContentReader();
            var    content = reader.ReadData(path);
            //Act
            var data = parser.ParseData(content);

            //Assert
            Assert.IsNotNull(data);
            Assert.That(data.Any());
        }