Index: Core/Components/src/Core.Components.Stack/Data/RowChartData.cs =================================================================== diff -u -r63d179e733e9d84cc09055b8919476f3712002d7 -rf84603903b35f1b130fc86de39dbb8fb8120ac05 --- Core/Components/src/Core.Components.Stack/Data/RowChartData.cs (.../RowChartData.cs) (revision 63d179e733e9d84cc09055b8919476f3712002d7) +++ Core/Components/src/Core.Components.Stack/Data/RowChartData.cs (.../RowChartData.cs) (revision f84603903b35f1b130fc86de39dbb8fb8120ac05) @@ -20,7 +20,9 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Drawing; +using System.Linq; namespace Core.Components.Stack.Data { @@ -38,7 +40,7 @@ /// Thrown when /// or /// is null. - public RowChartData(string name, double[] values, Color? color) + public RowChartData(string name, List values, Color? color) { if (name == null) { @@ -66,6 +68,6 @@ /// /// Gets the values of the row. /// - public double[] Values { get; } + public List Values { get; } } } \ No newline at end of file Index: Core/Components/src/Core.Components.Stack/Data/StackChartData.cs =================================================================== diff -u -red515ccdb8582831729533a466fccc439a8e07a2 -rf84603903b35f1b130fc86de39dbb8fb8120ac05 --- Core/Components/src/Core.Components.Stack/Data/StackChartData.cs (.../StackChartData.cs) (revision ed515ccdb8582831729533a466fccc439a8e07a2) +++ Core/Components/src/Core.Components.Stack/Data/StackChartData.cs (.../StackChartData.cs) (revision f84603903b35f1b130fc86de39dbb8fb8120ac05) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; using Core.Common.Base; namespace Core.Components.Stack.Data @@ -31,61 +32,111 @@ /// public class StackChartData : Observable { + private readonly List columns; + private readonly List rows; + /// /// Creates a new instance of . /// public StackChartData() { - Columns = new List(); - Rows = new List(); + columns = new List(); + rows = new List(); } /// /// Gets the columns of the . /// - public List Columns { get; } + public IEnumerable Columns + { + get + { + return columns; + } + } /// /// Gets the rows of the . /// - public List Rows { get; } + public IEnumerable Rows + { + get + { + return rows; + } + } /// /// Adds a column to the . /// /// The name of the column. - /// Thrown when - /// is null. + /// Thrown when + /// is null. public void AddColumn(string name) { - Columns.Add(new ColumnChartData(name)); + columns.Add(new ColumnChartData(name)); } /// + /// Adds a columns to with + /// values to add to the rows that are already present. + /// + /// The name of the column. + /// The values to add to the rows for this column. + /// Thrown when no + /// are present. + /// Thrown when + /// is null. + /// Thrown when the amount of + /// is not equal to the amount of . + public void AddColumnWithValues(string name, List values) + { + if (!Rows.Any()) + { + throw new InvalidOperationException("Rows should be added before this method is called."); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + + if (values.Count != rows.Count) + { + throw new ArgumentException("The number of value items must be the same as the number of rows."); + } + + AddColumn(name); + + for (var i = 0; i < values.Count; i++) + { + rows[i].Values.Add(values[i]); + } + } + + /// /// Adds a row to the . /// /// The name of the row. /// The values of the row. /// The color of the row. - /// Thrown when - /// or - /// is null. - /// Thrown when the - /// amount of is not equal to - /// the amount of . - public void AddRow(string name, double[] values, Color? color = null) + /// Thrown when + /// or is null. + /// Thrown when the amount of + /// is not equal to the amount of . + public void AddRow(string name, List values, Color? color = null) { if (values == null) { throw new ArgumentNullException(nameof(values)); } - if (values.Length != Columns.Count) + if (values.Count != columns.Count) { throw new ArgumentException("The number of value items must be the same as the number of columns."); } - Rows.Add(new RowChartData(name, values, color)); + rows.Add(new RowChartData(name, values, color)); } } } \ No newline at end of file Index: Core/Components/test/Core.Components.Stack.Test/Data/RowChartDataTest.cs =================================================================== diff -u -r63d179e733e9d84cc09055b8919476f3712002d7 -rf84603903b35f1b130fc86de39dbb8fb8120ac05 --- Core/Components/test/Core.Components.Stack.Test/Data/RowChartDataTest.cs (.../RowChartDataTest.cs) (revision 63d179e733e9d84cc09055b8919476f3712002d7) +++ Core/Components/test/Core.Components.Stack.Test/Data/RowChartDataTest.cs (.../RowChartDataTest.cs) (revision f84603903b35f1b130fc86de39dbb8fb8120ac05) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Drawing; using Core.Components.Stack.Data; using NUnit.Framework; @@ -33,7 +34,7 @@ public void Constructor_NameNull_ThrowsArgumentNullException() { // Call - TestDelegate test = () => new RowChartData(null, new double[0], Color.White); + TestDelegate test = () => new RowChartData(null, new List(), Color.White); // Assert var exception = Assert.Throws(test); @@ -57,7 +58,7 @@ // Setup const string name = "Row 1"; Color color = Color.Blue; - var values = new[] + var values = new List { 1.2, 2.3 Index: Core/Components/test/Core.Components.Stack.Test/Data/StackChartDataTest.cs =================================================================== diff -u -red515ccdb8582831729533a466fccc439a8e07a2 -rf84603903b35f1b130fc86de39dbb8fb8120ac05 --- Core/Components/test/Core.Components.Stack.Test/Data/StackChartDataTest.cs (.../StackChartDataTest.cs) (revision ed515ccdb8582831729533a466fccc439a8e07a2) +++ Core/Components/test/Core.Components.Stack.Test/Data/StackChartDataTest.cs (.../StackChartDataTest.cs) (revision f84603903b35f1b130fc86de39dbb8fb8120ac05) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Drawing; using System.Linq; using Core.Common.Base; @@ -69,19 +70,125 @@ data.AddColumn(columnName); // Assert - Assert.AreEqual(1, data.Columns.Count); + Assert.AreEqual(1, data.Columns.Count()); ColumnChartData column = data.Columns.First(); Assert.AreEqual(columnName, column.Name); } [Test] + public void AddColumnWithValues_NameNull_ThrowsArgumentNullException() + { + // Setup + var data = new StackChartData(); + data.AddColumn("Column 1"); + data.AddRow("Row 1", new List + { + 4.5 + }); + + // Call + TestDelegate test = () => data.AddColumnWithValues(null, new List + { + 1 + }); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("name", exception.ParamName); + } + + [Test] + public void AddColumnWithValues_ValuesNull_ThrowsArgumentNullException() + { + // Setup + var data = new StackChartData(); + data.AddColumn("Column 1"); + data.AddRow("Row 1", new List + { + 4.5 + }); + + // Call + TestDelegate test = () => data.AddColumnWithValues("test", null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("values", exception.ParamName); + } + + [Test] + public void AddColumnWithValues_NumberOfRowsDifferentThanValueItems_ThrowsArgumentException() + { + // Setup + var data = new StackChartData(); + data.AddColumn("Column 1"); + data.AddRow("Row 1", new List + { + 4.5 + }); + + // Call + TestDelegate test = () => data.AddColumnWithValues("test", new List + { + 2.1, + 3.4 + }); + + // Assert + const string message = "The number of value items must be the same as the number of rows."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + [Test] + public void AddColumnWithValues_NoRowsAdded_ThrowsInvalidOperationException() + { + // Setup + var data = new StackChartData(); + + // Call + TestDelegate test = () => data.AddColumnWithValues("test", new List()); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("Rows should be added before this method is called.", exception.Message); + } + + [Test] + public void AddColumnWithValues_ValidData_AddColumnAndValuesExistingRows() + { + // Setup + var data = new StackChartData(); + data.AddColumn("Column 1"); + data.AddRow("Row 1", new List + { + 1.0 + }); + + // Call + data.AddColumnWithValues("Column 2", new List + { + 2.0 + }); + + // Assert + Assert.AreEqual(2, data.Columns.Count()); + Assert.AreEqual("Column 2", data.Columns.Last().Name); + Assert.AreEqual(1, data.Rows.Count()); + CollectionAssert.AreEqual(new[] + { + 1.0, + 2.0 + }, data.Rows.First().Values); + } + + [Test] public void AddRow_NameNull_ThrowsArgumentNullException() { // Setup var data = new StackChartData(); // Call - TestDelegate test = () => data.AddRow(null, new double[0], Color.White); + TestDelegate test = () => data.AddRow(null, new List(), Color.White); // Assert var exception = Assert.Throws(test); @@ -110,7 +217,7 @@ var data = new StackChartData(); // Call - TestDelegate test = () => data.AddRow("test", new[] + TestDelegate test = () => data.AddRow("test", new List { 2.1 }); @@ -125,7 +232,7 @@ { // Setup const string name = "Row 1"; - var values = new[] + var values = new List { 1.2 }; @@ -138,10 +245,10 @@ data.AddRow(name, values, color); // Assert - Assert.AreEqual(1, data.Rows.Count); + Assert.AreEqual(1, data.Rows.Count()); RowChartData row = data.Rows.First(); Assert.AreEqual(name, row.Name); - Assert.AreSame(values, row.Values); + CollectionAssert.AreEqual(values, row.Values); Assert.AreEqual(color, row.Color); } @@ -150,7 +257,7 @@ { // Setup const string name = "Row 1"; - var values = new[] + var values = new List { 1.2 }; @@ -162,10 +269,10 @@ data.AddRow(name, values); // Assert - Assert.AreEqual(1, data.Rows.Count); + Assert.AreEqual(1, data.Rows.Count()); RowChartData row = data.Rows.First(); Assert.AreEqual(name, row.Name); - Assert.AreSame(values, row.Values); + CollectionAssert.AreEqual(values, row.Values); Assert.IsNull(row.Color); } }