예제 #1
0
        public void GetRecord_ThrowsExceptionsForBogusData_ExceptionThrown(string orderInput, int orderExpected,
                                                                           string perBodyFatInput1, double perBodyFatExpected1,
                                                                           string perBodyFatInput2, double perBodyFatExpected2,
                                                                           string perBodyMuscelInput, double perBodyMuscleExpected)
        {
            // Arrange
            var rowReaderMock = new Mock <IRowReader>();

            rowReaderMock.SetupSequence(m => m.CanRead()).Returns(true).Returns(true).Returns(true).Returns(false);
            rowReaderMock.Setup(m => m.IsRowBlank).Returns(false);
            rowReaderMock.SetupSequence(m => m.ReadRow())
            .Returns(new List <string> {
                "Order", "PercentageBodyFat1", "PercentageBodyFat2", "PercentageMuscle"
            })
            .Returns(new List <string> {
                orderInput, perBodyFatInput1, perBodyFatInput2, perBodyMuscelInput
            });

            var classUnderTest = new CsvReaderService <CsvConverterNumberDoubleReadData3>(rowReaderMock.Object);

            classUnderTest.Configuration.HasHeaderRow = true;

            // Act
            CsvConverterNumberDoubleReadData3 row1 = classUnderTest.GetRecord();
            CsvConverterNumberDoubleReadData3 row2 = classUnderTest.GetRecord();

            // Assert
            Assert.Fail("Should recieve an exception above for bogus input data");
        }
예제 #2
0
        public void GetRecord_WhenClassAttributeIsUsedYouCanOverrideIndividualProperties_ValuesComputed(
            string orderInput, int orderExpected,
            string perBodyFatInput1, double perBodyFatExpected1,
            string perBodyFatInput2, double perBodyFatExpected2,
            string perBodyMuscelInput, double perBodyMuscleExpected)
        {
            // Arrange
            var rowReaderMock = new Mock <IRowReader>();

            rowReaderMock.SetupSequence(m => m.CanRead()).Returns(true).Returns(true).Returns(true).Returns(false);
            rowReaderMock.Setup(m => m.IsRowBlank).Returns(false);
            rowReaderMock.SetupSequence(m => m.ReadRow())
            .Returns(new List <string> {
                "Order", "PercentageBodyFat1", "PercentageBodyFat2", "PercentageMuscle"
            })
            .Returns(new List <string> {
                orderInput, perBodyFatInput1, perBodyFatInput2, perBodyMuscelInput
            });

            var classUnderTest = new CsvReaderService <CsvConverterNumberDoubleReadData3>(rowReaderMock.Object);

            classUnderTest.Configuration.HasHeaderRow = true;

            // Act
            CsvConverterNumberDoubleReadData3 row1 = classUnderTest.GetRecord();
            CsvConverterNumberDoubleReadData3 row2 = classUnderTest.GetRecord();

            // Assert
            Assert.AreEqual(orderExpected, row1.Order);
            Assert.AreEqual(perBodyFatExpected1, row1.PercentageBodyFat1, "PercentageBodyFat1 MidpointRounding.ToEven");
            Assert.AreEqual(perBodyFatExpected2, row1.PercentageBodyFat2, "PercentageBodyFat2 MidpointRounding.AwayFromZero");
            Assert.AreEqual(perBodyMuscleExpected, row1.PercentageMuscle);

            Assert.IsNull(row2, "There is no 2nd row!");
            rowReaderMock.VerifyAll();
        }