public void GetHeaderReturnsWithHeaderWithNullsTest()
        {
            var containerItem = new TestItemContainer
            {
                Items = new List <TestItem>
                {
                    new TestItem {
                        Field1 = "field1"
                    },
                    new TestItem {
                        Field1 = "another field"
                    },
                    new TestItem {
                        Field1 = null
                    }
                }
            };

            var pivot = new ListPivot <TestItemContainer, TestItem>(
                "test",
                x => x.Items,
                x => x.Field1,
                x => x.Field2);

            var writer = ListPivotWriter <TestItemContainer, TestItem> .GetWriter(
                new List <TestItemContainer> {
                containerItem
            },
                pivot);

            var header = writer.GetHeader();

            Assert.Equal("field1,another field,", header);
        }
 public void ThrowsOnNullPivotTest()
 {
     Assert.Throws <ArgumentNullException>(
         () => ListPivotWriter <string, string> .GetWriter(
             new List <string>(),
             null));
 }
        public void GetLineThrowsWithMultipleIdenticalHeaderValuesTest()
        {
            var containerItem = new TestItemContainer
            {
                Items = new List <TestItem>
                {
                    new TestItem {
                        Field1 = "field1"
                    },
                    new TestItem {
                        Field1 = "field1"
                    }
                }
            };

            var pivot = new ListPivot <TestItemContainer, TestItem>(
                "test",
                x => x.Items,
                x => x.Field1,
                x => x.Field2);

            var writer = ListPivotWriter <TestItemContainer, TestItem> .GetWriter(
                new List <TestItemContainer> {
                containerItem
            },
                pivot);

            var ex = Assert.Throws <InvalidOperationException>(
                () => writer.GetLine(containerItem));

            Assert.Equal("cannot have two identical column names", ex.Message);
        }
        public void ThrowsOnNullItemsTest()
        {
            var pivot = new ListPivot <string, string>(
                "test",
                x => new List <string>(),
                x => x,
                x => x);

            Assert.Throws <ArgumentNullException>(
                () => ListPivotWriter <string, string> .GetWriter(
                    null,
                    pivot));
        }
        public void GetLineReturnsLineInCorrectOrderTest()
        {
            var containerItems = new List <TestItemContainer>
            {
                new TestItemContainer
                {
                    Items = new List <TestItem>
                    {
                        new TestItem {
                            Field1 = "headervalue1", Field2 = "field2"
                        },
                        new TestItem {
                            Field1 = "headervalue2", Field2 = "field2"
                        },
                    }
                },
                new TestItemContainer
                {
                    Items = new List <TestItem>
                    {
                        new TestItem {
                            Field1 = "headervalue2", Field2 = "value1"
                        },
                        new TestItem {
                            Field1 = "headervalue1", Field2 = "value2"
                        },
                    }
                }
            };

            var pivot = new ListPivot <TestItemContainer, TestItem>(
                "test",
                x => x.Items,
                x => x.Field1,
                x => x.Field2);

            var writer = ListPivotWriter <TestItemContainer, TestItem> .GetWriter(
                containerItems,
                pivot);

            var line = writer.GetLine(containerItems[1]);

            Assert.Equal("value2,value1", line);
        }
        public void GetLineReturnsLineWithMissingValuesTest()
        {
            var containerItems = new List <TestItemContainer>
            {
                new TestItemContainer
                {
                    Items = new List <TestItem>
                    {
                        new TestItem {
                            Field1 = "field1", Field2 = "field2"
                        },
                        new TestItem {
                            Field1 = "another field", Field2 = "field2"
                        },
                    }
                },
                new TestItemContainer
                {
                    Items = new List <TestItem>
                    {
                        new TestItem {
                            Field1 = "another field", Field2 = "field2"
                        },
                    }
                }
            };

            var pivot = new ListPivot <TestItemContainer, TestItem>(
                "test",
                x => x.Items,
                x => x.Field1,
                x => x.Field2);

            var writer = ListPivotWriter <TestItemContainer, TestItem> .GetWriter(
                containerItems,
                pivot);

            var line = writer.GetLine(containerItems[1]);

            Assert.Equal(",field2", line);
        }
예제 #7
0
 private static ListPivotWriter <T, TPivot> BuildPivotWriter <T, TPivot>(
     ICollection <T> items,
     ListPivot <T, TPivot> pivot)
     where T : class
     where TPivot : class =>
 ListPivotWriter <T, TPivot> .GetWriter(items, pivot);