public void SetFileContent_HeaderMissing_ThrowException()
        {
            var file      = new FileContent("file.csv", null, new List <string>());
            var processor = new MockingFileProcessor("data value column", "date time column");

            Assert.That(() => processor.SetDataAndPrepareProcessing(file),
                        Throws.Exception.TypeOf <InvalidDataException>()
                        .With.Property("Message").Contains("Header information is missing."));
        }
        public void GetOverMedianByPercentage_MultipleFiles_CorrectResults()
        {
            var dataColumn          = "Data Value";
            var dateTimeStampColumn = "Date/Time";

            var fileA = GetTestingFileA();
            var fileB = GetTestingFileB();
            var fileC = GetTestingFileC();

            var processor = new MockingFileProcessor(dataColumn, dateTimeStampColumn);

            processor.SetDataAndPrepareProcessing(fileB);
            var resultSetB = processor.GetOverMedianByPercentage((decimal)0.1);

            Assert.NotNull(resultSetB.ProcessResults);
            Assert.AreEqual(resultSetB.ProcessResults.Count(), 0);


            processor.SetDataAndPrepareProcessing(fileA);
            var resultSetA = processor.GetOverMedianByPercentage((decimal)0.1);

            var median = (decimal)29.7125;

            Assert.AreEqual(resultSetA.MedianValue, median);
            Assert.AreEqual(resultSetA.FileName, "file.csv");
            Assert.NotNull(resultSetA.ProcessResults);
            Assert.AreEqual(resultSetA.ProcessResults.Count(), 2);
            Assert.IsTrue(resultSetA.ProcessResults.Any(result => result.Value == (decimal)36.42 && result.DateTimeStamp == "31/08/2015 01:00:00"));
            Assert.IsTrue(resultSetA.ProcessResults.Any(result => result.Value == (decimal)32.90 && result.DateTimeStamp == "31/08/2015 01:15:00"));

            processor.SetDataAndPrepareProcessing(fileC);
            var resultSetC = processor.GetOverMedianByPercentage((decimal)0.2);

            median = (decimal)34.013333;
            Assert.AreEqual(resultSetC.MedianValue, median);
            Assert.AreEqual(resultSetC.FileName, "fileC.csv");
            Assert.NotNull(resultSetC.ProcessResults);
            Assert.AreEqual(resultSetC.ProcessResults.Count(), 1);
            Assert.IsTrue(resultSetC.ProcessResults.Any(result => result.Value == (decimal)45.97 && result.DateTimeStamp == "31/09/2015 01:23:00"));
        }
        public void GetColumnIndex_ColumnNotExist_NegativeIndex()
        {
            var dataColumn          = "Data Value";
            var dateTimeStampColumn = "Date/Time";

            var file      = GetTestingFileA();
            var processor = new MockingFileProcessor(dataColumn, dateTimeStampColumn);

            processor.SetDataAndPrepareProcessing(file);
            var index = processor.GetColumnIndex("Column not exists");

            var expected = -1;

            Assert.AreEqual(index, expected);
        }
        public void GetColumnIndex_ColumnExist_MatchResult()
        {
            var dataColumn          = "Data Value";
            var dateTimeStampColumn = "Date/Time";

            var file      = GetTestingFileA();
            var processor = new MockingFileProcessor(dataColumn, dateTimeStampColumn);

            processor.SetDataAndPrepareProcessing(file);
            var index = processor.GetColumnIndex(dataColumn);

            var expected = 5;

            Assert.AreEqual(index, expected);
        }
        public void CalculateMedianValue_Ready_MatchResult()
        {
            var dataColumn          = "Data Value";
            var dateTimeStampColumn = "Date/Time";

            var file      = GetTestingFileA();
            var processor = new MockingFileProcessor(dataColumn, dateTimeStampColumn);

            processor.SetDataAndPrepareProcessing(file);
            var medianValue = processor.CalculateMedianValue();

            decimal expected = (decimal)29.7125;

            Assert.AreEqual(medianValue, expected);
        }
        public void SetFileContent_ColumnNotExist_ThrowException()
        {
            var columnExists  = "Energy";
            var columnMissing = "Date/Time";

            var headers = new List <string> {
                "Column1", "Column2", columnExists, "Column4"
            };
            var file      = new FileContent("file.csv", null, headers);
            var processor = new MockingFileProcessor(columnExists, columnMissing);

            Assert.That(() => processor.SetDataAndPrepareProcessing(file),
                        Throws.Exception.TypeOf <InvalidDataException>()
                        .With.Property("Message").Contains("Date/Time field does not exist in file"));
        }
        public void GetBelowMedianByPercentage_50Percent_RecordNotFound()
        {
            var dataColumn          = "Data Value";
            var dateTimeStampColumn = "Date/Time";

            var file      = GetTestingFileA();
            var processor = new MockingFileProcessor(dataColumn, dateTimeStampColumn);

            processor.SetDataAndPrepareProcessing(file);

            var resultSet = processor.GetBelowMedianByPercentage((decimal)0.5);

            var median = (decimal)29.7125;

            Assert.AreEqual(resultSet.MedianValue, median);
            Assert.AreEqual(resultSet.FileName, "file.csv");
            Assert.NotNull(resultSet.ProcessResults);
            Assert.AreEqual(resultSet.ProcessResults.Count(), 0);
        }
        public void GetOverMedianByPercentage_10Percent_RecordFound()
        {
            var dataColumn          = "Data Value";
            var dateTimeStampColumn = "Date/Time";

            var file      = GetTestingFileA();
            var processor = new MockingFileProcessor(dataColumn, dateTimeStampColumn);

            processor.SetDataAndPrepareProcessing(file);

            var resultSet = processor.GetOverMedianByPercentage((decimal)0.1);

            var median = (decimal)29.7125;

            Assert.AreEqual(resultSet.MedianValue, median);
            Assert.AreEqual(resultSet.FileName, "file.csv");
            Assert.NotNull(resultSet.ProcessResults);
            Assert.AreEqual(resultSet.ProcessResults.Count(), 2);
            Assert.IsTrue(resultSet.ProcessResults.Any(result => result.Value == (decimal)36.42 && result.DateTimeStamp == "31/08/2015 01:00:00"));
            Assert.IsTrue(resultSet.ProcessResults.Any(result => result.Value == (decimal)32.90 && result.DateTimeStamp == "31/08/2015 01:15:00"));
        }