Exemplo n.º 1
0
        public void Convert_WhenSpecifiedOnTheClass_BooleansAreAllConvertedTheSameWay(
            bool bool1Input, string bool1ExpectedOutput,
            bool bool2Input, string bool2ExpectedOutput,
            bool?bool3Input, string bool3ExpectedOutput,
            bool bool4Input, string bool4ExpectedOutput,
            bool bool5Input, string bool5ExpectedOutput)
        {
            // Arrange
            var rowWriterMock  = new FakeRowWriter();
            var classUnderTest = new CsvWriterService <CsvConverterBooleanWriteData2>(rowWriterMock);

            classUnderTest.Configuration.HasHeaderRow = true;

            var data = new CsvConverterBooleanWriteData2()
            {
                Bool1 = bool1Input, Bool2 = bool2Input, Bool3 = bool3Input, Bool4 = bool4Input, Bool5 = bool5Input
            };

            // Act
            classUnderTest.WriteRecord(data);

            // Assert
            Assert.AreEqual(2, rowWriterMock.Rows.Count);
            var dataRow = rowWriterMock.Rows[1];

            Assert.AreEqual(bool1ExpectedOutput, dataRow[0]);
            Assert.AreEqual(bool2ExpectedOutput, dataRow[1]);
            Assert.AreEqual(bool3ExpectedOutput, dataRow[2]);
            Assert.AreEqual(bool4ExpectedOutput, dataRow[3]);
            Assert.AreEqual(bool5ExpectedOutput, dataRow[4]);
        }
Exemplo n.º 2
0
        public void Convert_WhenSpecifiedTheClassPropertyAttributesCanOverrideClassAttributes_PropertiesTakePrecedence(
            bool bool1Input, string bool1ExpectedOutput,
            bool bool2Input, string bool2ExpectedOutput,
            bool?bool3Input, string bool3ExpectedOutput,
            bool bool4Input, string bool4ExpectedOutput,
            bool bool5Input, string bool5ExpectedOutput)
        {
            // Arrange
            var rowWriterMock  = new FakeRowWriter();
            var classUnderTest = new CsvWriterService <CsvConverterBooleanWriteData3>(rowWriterMock);

            classUnderTest.Configuration.HasHeaderRow = true;

            var data = new CsvConverterBooleanWriteData3()
            {
                Bool1 = bool1Input, Bool2 = bool2Input, Bool3 = bool3Input, Bool4 = bool4Input, Bool5 = bool5Input
            };

            // Act
            classUnderTest.WriteRecord(data);

            // Assert
            Assert.AreEqual(2, rowWriterMock.Rows.Count);
            var dataRow = rowWriterMock.Rows[1];

            Assert.AreEqual(bool1ExpectedOutput, dataRow[0]);
            Assert.AreEqual(bool2ExpectedOutput, dataRow[1]);
            Assert.AreEqual(bool3ExpectedOutput, dataRow[2]);
            Assert.AreEqual(bool4ExpectedOutput, dataRow[3]);
            Assert.AreEqual(bool5ExpectedOutput, dataRow[4]);
        }
Exemplo n.º 3
0
        public void Convert_WhenSpecifiedTheClassPropertyAttributesCanOverrideClassAttributes_PropertiesTakePrecedence(
            int year, int month, int day, int hour, int minute, int second,
            string expectedStringRow1, string expectedStringRow2, string expectedStringRow3)
        {
            // Arrange
            var rowWriterMock = new FakeRowWriter();

            var classUnderTest = new CsvWriterService <CsvConverterDateTimeWriteData3>(rowWriterMock);

            classUnderTest.Configuration.HasHeaderRow = true;



            var data = new CsvConverterDateTimeWriteData3()
            {
                Date1 = new DateTime(year, month, day, hour, minute, second),
                Date2 = new DateTime(year, month, day, hour, minute, second),
                Date3 = new DateTime(year, month, day, hour, minute, second)
            };

            // Act
            classUnderTest.WriteRecord(data);

            // Assert
            Assert.AreEqual(expectedStringRow1, rowWriterMock.LastRow[0], "Order column problem for Date1");
            Assert.AreEqual(expectedStringRow2, rowWriterMock.LastRow[1], "Order column problem for Date2!");
            Assert.AreEqual(expectedStringRow3, rowWriterMock.LastRow[2], "Order column problem for Date3!");
        }
Exemplo n.º 4
0
        public void Convert_WhenSpecifiedTheClassPropertyAttributesCanOverrideClassAttributes_PropertiesTakePrecedence(
            int inputData1, string expectedData1,
            int inputData2, string expectedData2,
            int?inputData3, string expectedData3,
            int inputData4, string expectedData4)
        {
            // Arrange
            var rowWriterMock  = new FakeRowWriter();
            var classUnderTest = new CsvWriterService <CsvConverterNumberIntWriteData3>(rowWriterMock);

            classUnderTest.Configuration.HasHeaderRow = true;

            var data = new CsvConverterNumberIntWriteData3()
            {
                Num1 = inputData1,
                Num2 = inputData2,
                Num3 = inputData3,
                Num4 = inputData4
            };

            // Act
            classUnderTest.WriteRecord(data);

            // Assert
            Assert.AreEqual(2, rowWriterMock.Rows.Count);
            var dataRow = rowWriterMock.Rows[1];

            var index = 0;

            Assert.AreEqual(expectedData1, dataRow[index++], $"Problem with input {index} -> {inputData1}");
            Assert.AreEqual(expectedData2, dataRow[index++], $"Problem with input {index} -> {inputData2}");
            Assert.AreEqual(expectedData3, dataRow[index++], $"Problem with input {index} -> {inputData3}");
        }
Exemplo n.º 5
0
        public void Convert_WhenSpecifiedOnEachProperty_IntsAreConvertedAccordingToAttributes(
            int inputData1, string expectedData1,
            int inputData2, string expectedData2,
            int?inputData3, string expectedData3,
            int inputData4, string expectedData4)
        {
            // Arrange
            var rowWriterMock  = new FakeRowWriter();
            var classUnderTest = new CsvWriterService <CsvConverterNumberIntWriteData1>(rowWriterMock);

            classUnderTest.Configuration.HasHeaderRow = true;

            var data = new CsvConverterNumberIntWriteData1()
            {
                Num1 = inputData1, Num2 = inputData2, Num3 = inputData3, Num4 = inputData4
            };

            // Act
            classUnderTest.WriteRecord(data);

            // Assert
            Assert.AreEqual(2, rowWriterMock.Rows.Count);
            var dataRow = rowWriterMock.Rows[1];

            var index = 0;

            Assert.AreEqual(expectedData1, dataRow[index++], $"Problem with input {index} -> {inputData1}");
            Assert.AreEqual(expectedData2, dataRow[index++], $"Problem with input {index} -> {inputData2}");
            Assert.AreEqual(expectedData3, dataRow[index++], $"Problem with input {index} -> {inputData3}");

            // Note:  Windows 7 and Windows 10 format percentages in different ways so I'm just remove
            // the space between the number and percentage sign so that I can test for a proper conversion.
            Assert.AreEqual(expectedData4, dataRow[index++].Replace(" ", ""), $"Problem with input {index} -> {inputData4}");
        }
Exemplo n.º 6
0
        public void WriterRecord_CanWriteDataInCorrectOrderWithNoHeaderRow_DataIsWritenCorrectlyToTheRowWriter(
            int order, int age, string name, string expectedOrder, string expectedAge, string expectedName)
        {
            // Arrange
            var rowWriterMock  = new FakeRowWriter();
            var classUnderTest = new CsvWriterService <WriteNoHeaderTestsData1>(rowWriterMock);

            classUnderTest.Configuration.HasHeaderRow = false;

            var data = new WriteNoHeaderTestsData1()
            {
                Order = order, Age = age, Name = name
            };

            // Act
            classUnderTest.WriteRecord(data);

            // Assert
            Assert.AreEqual(1, rowWriterMock.Rows.Count, "There should only be one row written!");
            Assert.AreEqual(expectedName, rowWriterMock.LastRow[0], "Name column problem!");
            Assert.AreEqual(expectedOrder, rowWriterMock.LastRow[1], "Order column problem!");
            Assert.AreEqual(expectedAge, rowWriterMock.LastRow[2], "Age column problem!");
        }
Exemplo n.º 7
0
        [DataRow(" moose ", "moose")]  // 1st converter gets NO match and 2nd converter REMOVES spaces
        public void Convert_OrderMatters_FirstDoExactMatchAndThenRemoveSpaces(
            string animialTypeInput, string animialTypeExpectedOutput)
        {
            // Arrange
            var rowWriterMock  = new FakeRowWriter();
            var classUnderTest = new CsvWriterService <ClassLevelAttributeOrderWriteData2>(rowWriterMock);

            classUnderTest.Configuration.HasHeaderRow = true;

            var data = new ClassLevelAttributeOrderWriteData2()
            {
                AnimalType = animialTypeInput
            };

            // Act
            classUnderTest.WriteRecord(data);

            // Assert
            Assert.AreEqual(2, rowWriterMock.Rows.Count); // header row and then 1 data row (count of 2)
            var dataRow = rowWriterMock.Rows[1];          // first row below header row

            Assert.AreEqual(animialTypeExpectedOutput, dataRow[0]);
        }
Exemplo n.º 8
0
        public void WriterRecord_CanWriteColumnInCorrectOrder_DataIsWritenCorrectlyToTheRowWriter()
        {
            // Arrange
            var rowWriterMock  = new FakeRowWriter();
            var classUnderTest = new CsvWriterService <WriteHeaderTestData1>(rowWriterMock);

            classUnderTest.Configuration.HasHeaderRow = true;

            var data = new WriteHeaderTestData1()
            {
                Order = 1, Age = 23, Name = "James"
            };

            // Act
            classUnderTest.WriteRecord(data);

            // Assert
            Assert.AreEqual(2, rowWriterMock.Rows.Count);
            var headerRow = rowWriterMock.Rows[0];

            Assert.AreEqual("Order", headerRow[0]);
            Assert.AreEqual("Age", headerRow[1]);
            Assert.AreEqual("Name", headerRow[2]);
        }