public void GivenChartControlWithoutData_WhenDataSetToStackChartData_ThenChartControlUpdated() { // Given using (var chart = new StackChartControl()) { var data = new StackChartData(); data.AddColumn("Column 1"); data.AddColumn("Column 2"); data.AddRow("Row 1", new[] { 0.4, 0.2 }); data.AddRow("Row 2", new[] { 0.6, 0.8 }); // When chart.Data = data; // Then CategoryPlotView plotView = chart.Controls.OfType <CategoryPlotView>().Single(); AssertColumns(data.Columns.ToList(), plotView); AssertSeries(data.Rows.Select(r => r.Name).ToList(), plotView); } }
public void GivenChartControlWithData_WhenDataSetToOtherStackChartData_ThenChartControlUpdated() { // Given using (var chart = new StackChartControl()) { var data = new StackChartData(); data.AddColumn("Column 1"); data.AddColumn("Column 2"); data.AddRow("Row 1", new[] { 0.4, 0.2 }); data.AddRow("Row 2", new[] { 0.6, 0.8 }); chart.Data = data; // Precondition CategoryPlotView plotView = chart.Controls.OfType <CategoryPlotView>().Single(); AssertColumns(data.Columns.ToList(), plotView); AssertSeries(data.Rows.Select(r => r.Name).ToList(), plotView); // When var newData = new StackChartData(); newData.AddColumn("Column 3"); newData.AddColumn("Column 4"); newData.AddRow("Row 3", new[] { 0.5, 0.7 }); newData.AddRow("Row 4", new[] { 0.5, 0.3 }); chart.Data = newData; // Then ElementCollection <Series> series = plotView.Model.Series; Assert.AreEqual(2, series.Count); Assert.AreEqual("Row 3", series[0].Title); Assert.AreEqual("Row 4", series[1].Title); CategoryAxis axis = plotView.Model.Axes.OfType <CategoryAxis>().Single(); Assert.AreEqual(2, axis.Labels.Count); Assert.AreEqual("Column 3", axis.Labels[0]); Assert.AreEqual("Column 4", axis.Labels[1]); AssertColumns(newData.Columns.ToList(), plotView); AssertSeries(newData.Rows.Select(r => r.Name).ToList(), plotView); } }
public void GivenChartControlWithData_WhenDataNotified_ThenChartControlUpdated() { // Given using (var chart = new StackChartControl()) { var data = new StackChartData(); data.AddColumn("Column 1"); data.AddColumn("Column 2"); data.AddRow("Row 1", new[] { 0.4, 0.2 }); data.AddRow("Row 2", new[] { 0.6, 0.8 }); chart.Data = data; CategoryPlotView plotView = chart.Controls.OfType <CategoryPlotView>().Single(); AssertColumns(data.Columns.ToList(), plotView); AssertSeries(data.Rows.Select(r => r.Name).ToList(), plotView); // When data.Clear(); data.AddColumn("New column 1"); data.AddColumn("New column 2"); data.AddRow("New row 1", new[] { 0.3, 0.8 }); data.AddRow("New row 2", new[] { 0.8, 0.2 }); data.NotifyObservers(); // Then ElementCollection <Series> series = plotView.Model.Series; Assert.AreEqual(2, series.Count); Assert.AreEqual("New row 1", series[0].Title); Assert.AreEqual("New row 2", series[1].Title); CategoryAxis axis = plotView.Model.Axes.OfType <CategoryAxis>().Single(); Assert.AreEqual(2, axis.Labels.Count); Assert.AreEqual("New column 1", axis.Labels[0]); Assert.AreEqual("New column 2", axis.Labels[1]); } }
private static void AssertColumns(IEnumerable <string> expectedColumnTitles, CategoryPlotView plotView) { CategoryAxis axis = plotView.Model.Axes.OfType <CategoryAxis>().First(); int expectedColumnTitlesCount = expectedColumnTitles.Count(); Assert.AreEqual(expectedColumnTitlesCount, axis.Labels.Count); for (var i = 0; i < expectedColumnTitlesCount; i++) { Assert.AreEqual(expectedColumnTitles.ElementAt(i), axis.Labels[i]); } }
private static void AssertSeries(IEnumerable <string> expectedSeriesTitles, CategoryPlotView plotView) { ElementCollection <Series> series = plotView.Model.Series; int expectedSeriesTitlesCount = expectedSeriesTitles.Count(); Assert.AreEqual(expectedSeriesTitlesCount, series.Count); for (var i = 0; i < expectedSeriesTitlesCount; i++) { Assert.AreEqual(expectedSeriesTitles.ElementAt(i), series[i].Title); } }
public void AddLabels_LabelsNull_ThrowsArgumentNullException() { // Setup var plotView = new CategoryPlotView(); // Call TestDelegate test = () => plotView.AddLabels(null); // Assert var exception = Assert.Throws <ArgumentNullException>(test); Assert.AreEqual("labels", exception.ParamName); }
public void AddLabel_EmptyLabels_AbsoluteMaximumSet() { // Setup var plotView = new CategoryPlotView(); // Call plotView.AddLabels(Enumerable.Empty <string>()); // Assert CategoryAxis axis = plotView.Model.Axes.OfType <CategoryAxis>().First(); Assert.AreEqual(0, axis.Labels.Count); Assert.AreEqual(0, axis.AbsoluteMaximum); }
public void Constructor_ExpectedValues() { // Call var chart = new StackChartControl(); // Assert Assert.IsInstanceOf <Control>(chart); Assert.IsInstanceOf <IStackChartControl>(chart); Assert.IsNull(chart.Data); CategoryPlotView plotView = chart.Controls.OfType <CategoryPlotView>().Single(); Assert.AreEqual(Color.White, plotView.BackColor); Assert.IsTrue(plotView.Model.IsLegendVisible); }
public void AddLabel_WithLabel_LabelAddedAndAbsoluteMaximumSet() { // Setup const string label = "Test"; var plotView = new CategoryPlotView(); // Call plotView.AddLabels(new[] { label }); // Assert CategoryAxis axis = plotView.Model.Axes.OfType <CategoryAxis>().First(); Assert.AreEqual(1, axis.Labels.Count); Assert.AreEqual(label, axis.Labels[0]); Assert.AreEqual(0.5, axis.AbsoluteMaximum); }
public void ModelTitle_Always_SetsNewTitleToModelAndInvalidatesView(string newTitle) { // Setup using (var form = new Form()) using (var view = new CategoryPlotView()) { form.Controls.Add(view); var invalidated = 0; view.Invalidated += (sender, args) => invalidated++; form.Show(); // Call view.ModelTitle = newTitle; // Assert Assert.AreEqual(newTitle, view.Model.Title); Assert.AreEqual(1, invalidated); } }
public void ClearLabels_Always_LabelsCleared() { // Setup var plotView = new CategoryPlotView(); plotView.AddLabels(new[] { "Test" }); // Precondition CategoryAxis axis = plotView.Model.Axes.OfType <CategoryAxis>().First(); Assert.AreEqual(1, axis.Labels.Count); // Call plotView.ClearLabels(); // Assert CollectionAssert.IsEmpty(axis.Labels); }
public void Constructor_ExpectedValues() { // Call var plotView = new CategoryPlotView(); // Assert Assert.IsInstanceOf <PlotView>(plotView); Assert.AreEqual(DockStyle.Fill, plotView.Dock); Assert.IsNull(plotView.ModelTitle); Assert.IsNull(plotView.VerticalAxisTitle); PlotModel plotModel = plotView.Model; ElementCollection <Axis> axes = plotModel.Axes; Assert.AreEqual(2, axes.Count); Axis categoryAxis = axes.First(ax => ax.GetType() == typeof(CategoryAxis)); Assert.AreEqual(1, categoryAxis.MinorStep); Assert.AreEqual(90, categoryAxis.Angle); Assert.AreEqual(-0.5, categoryAxis.AbsoluteMinimum); Assert.IsFalse(categoryAxis.IsPanEnabled); Assert.IsFalse(categoryAxis.IsZoomEnabled); Axis linearAxis = axes.First(ax => ax.GetType() == typeof(LinearAxis)); Assert.AreEqual(0, linearAxis.MinimumPadding); Assert.IsFalse(linearAxis.IsPanEnabled); Assert.IsFalse(linearAxis.IsZoomEnabled); Assert.IsNull(linearAxis.Title); Assert.AreEqual(0, plotModel.LegendBorderThickness); Assert.AreEqual(LegendOrientation.Horizontal, plotModel.LegendOrientation); Assert.AreEqual(LegendPlacement.Outside, plotModel.LegendPlacement); Assert.AreEqual(LegendPosition.TopCenter, plotModel.LegendPosition); }
public void SetVerticalAxisTitle_Always_SetsVerticalAxisTitleToModelAndViewInvalidated(string newTitle) { // Setup using (var form = new Form()) { var chart = new StackChartControl(); CategoryPlotView view = chart.Controls.OfType <CategoryPlotView>().Single(); form.Controls.Add(chart); form.Show(); var invalidated = 0; view.Invalidated += (sender, args) => invalidated++; // Call chart.VerticalAxisTitle = newTitle; // Assert Assert.AreEqual(newTitle, view.VerticalAxisTitle); Assert.AreEqual(1, invalidated); } }
public void GivenChartControlWithData_WhenDataSetToNull_ThenChartControlUpdated() { // Given using (var chart = new StackChartControl()) { var data = new StackChartData(); data.AddColumn("Column 1"); data.AddColumn("Column 2"); data.AddRow("Row 1", new[] { 0.4, 0.2 }); data.AddRow("Row 2", new[] { 0.6, 0.8 }); chart.Data = data; // Precondition CategoryPlotView plotView = chart.Controls.OfType <CategoryPlotView>().Single(); AssertColumns(data.Columns.ToList(), plotView); AssertSeries(data.Rows.Select(r => r.Name).ToList(), plotView); // When chart.Data = null; // Then ElementCollection <Series> series = plotView.Model.Series; CollectionAssert.IsEmpty(series); CategoryAxis axis = plotView.Model.Axes.OfType <CategoryAxis>().Single(); CollectionAssert.IsEmpty(axis.Labels); } }
public void VerticalAxisTitle_AlwaysSetsNewVerticalAxisTitleToModelAndInvalidatesView(string newTitle) { // Setup using (var form = new Form()) using (var view = new CategoryPlotView()) { form.Controls.Add(view); var invalidated = 0; view.Invalidated += (sender, args) => invalidated++; form.Show(); // Call view.VerticalAxisTitle = newTitle; // Assert PlotModel plotModel = view.Model; ElementCollection <Axis> axes = plotModel.Axes; var categoryAxis = (LinearAxis)axes.First(ax => ax.GetType() == typeof(LinearAxis)); Assert.AreEqual(newTitle, categoryAxis.Title); Assert.AreEqual(1, invalidated); } }