public void PivotTable_Simple() { var pvtData = getSamplePivotData(); var pvtTbl = new PivotTable(new string[] { "B" }, new string[] { "A" }, pvtData); Assert.Equal(3, pvtTbl.ColumnKeys.Length); Assert.Equal(3, pvtTbl.RowKeys.Length); Assert.Equal("A1", pvtTbl.ColumnKeys[0].DimKeys[0]); Assert.Equal("B1", pvtTbl.RowKeys[0].DimKeys[0]); Assert.Equal(54, Convert.ToInt32(pvtTbl[null, null].Value)); // global totals Assert.Equal(6, Convert.ToInt32(pvtTbl[0, 0].Value)); Assert.Equal(18, Convert.ToInt32(pvtTbl[0, null].Value)); var pvtData2 = getSamplePivotData(true); var pvtTbl2 = new PivotTable(new string[] { "A", "B" }, new string[] { "C" }, pvtData2); Assert.Equal(6, pvtTbl2.RowKeys.Length); Assert.Equal("A1", pvtTbl2.RowKeys[0].DimKeys[0]); Assert.Equal("B1", pvtTbl2.RowKeys[0].DimKeys[1]); Assert.Equal(20, Convert.ToInt32(pvtTbl2[null, null].Value)); // global totals Assert.Equal(2, Convert.ToInt32(pvtTbl2[5, null].Value)); var pvtTbl3 = new PivotTable(new string[] { "A", "B", "C" }, null, pvtData); Assert.Equal(6, Convert.ToInt32( pvtTbl3.GetValue(new ValueKey(new object[] { "A1", "B1", Key.Empty }), null).Value)); Assert.Equal(18, Convert.ToInt32( pvtTbl3.GetValue(new ValueKey(new object[] { Key.Empty, "B1", Key.Empty }), null).Value)); Assert.Equal(54, Convert.ToInt32( pvtTbl3[null, null].Value)); var diagPvtTbl = new PivotTable(new [] { "B" }, new [] { "B" }, pvtData); for (int i = 0; i < diagPvtTbl.RowKeys.Length; i++) { for (int j = 0; j < diagPvtTbl.ColumnKeys.Length; j++) { if (i == j) { Assert.NotEqual(0, (int)diagPvtTbl[i, j].Count); // "Incorrect diagonal pivot table" } else { Assert.Equal(0, (int)diagPvtTbl[i, j].Count); // "Incorrect diagonal pivot table" } } } }