Beispiel #1
0
        public void TokensAreEmptyExpectFailure()
        {
            Mock <IMeterCsvValidator> mockValidator = new Mock <IMeterCsvValidator>();

            MeterCsvLineParser csvReader = new MeterCsvLineParser(mockValidator.Object);

            string tokens = "";

            Assert.IsFalse(csvReader.TryParseMeterLine(tokens, out MeterReading meterReading));
        }
Beispiel #2
0
        public void AccountIdTokenIsInvalidExpectFailure()
        {
            Mock <IMeterCsvValidator> mockValidator = new Mock <IMeterCsvValidator>();

            int expectedAccountId = 123;

            mockValidator.Setup(v => v.TryParseAccountId(It.IsAny <string>(), out expectedAccountId)).Returns(false);

            MeterCsvLineParser csvReader = new MeterCsvLineParser(mockValidator.Object);

            string tokens = "A,B,C";

            Assert.IsFalse(csvReader.TryParseMeterLine(tokens, out MeterReading meterReading));
        }
Beispiel #3
0
        public void MeterReadingIsInvalidExpectFailure()
        {
            Mock <IMeterCsvValidator> mockValidator = new Mock <IMeterCsvValidator>();

            int      expectedAccountId            = 123;
            DateTime expectedMeterReadingDateTime = new DateTime(2000, 05, 21);
            string   expectedMeterReading         = "00012";

            mockValidator.Setup(v => v.TryParseAccountId(It.IsAny <string>(), out expectedAccountId)).Returns(true);
            mockValidator.Setup(v => v.TryParseMeterReadingDateTime(It.IsAny <string>(), out expectedMeterReadingDateTime)).Returns(true);
            mockValidator.Setup(v => v.TryParseMeterReading(It.IsAny <string>(), out expectedMeterReading)).Returns(false);

            MeterCsvLineParser csvReader = new MeterCsvLineParser(mockValidator.Object);

            string tokens = "A,B,C";

            Assert.IsFalse(csvReader.TryParseMeterLine(tokens, out MeterReading meterReading));
        }
Beispiel #4
0
        public void TokensAreValidExpectMeterReadingRecordReturned()
        {
            Mock <IMeterCsvValidator> mockValidator = new Mock <IMeterCsvValidator>();

            int      expectedAccountId            = 123;
            DateTime expectedMeterReadingDateTime = new DateTime(2000, 05, 21);
            string   expectedMeterReading         = "00012";

            mockValidator.Setup(v => v.TryParseAccountId(It.IsAny <string>(), out expectedAccountId)).Returns(true);
            mockValidator.Setup(v => v.TryParseMeterReadingDateTime(It.IsAny <string>(), out expectedMeterReadingDateTime)).Returns(true);
            mockValidator.Setup(v => v.TryParseMeterReading(It.IsAny <string>(), out expectedMeterReading)).Returns(true);

            MeterCsvLineParser csvReader = new MeterCsvLineParser(mockValidator.Object);

            string tokens = "A,B,C";

            csvReader.TryParseMeterLine(tokens, out MeterReading meterReading);

            Assert.AreEqual(expectedAccountId, meterReading.AccountId);
            Assert.AreEqual(expectedMeterReadingDateTime, meterReading.MeterReadingDateTime);
            Assert.AreEqual(expectedMeterReading, meterReading.MeterReadValue);
        }