using System; using System.ComponentModel; using System.Drawing; using Core.Common.Controls.Charting; using Core.Common.Gui; using Core.Common.Gui.PropertyBag; using Core.Plugins.Charting.Property; using NUnit.Framework; using Rhino.Mocks; namespace Core.Plugins.Charting.Test.Property { [TestFixture] public class ChartPropertiesTest { [Test] public void DefaultConstructor_ExpectedValues() { // Call var properties = new ChartProperties(); // Assert Assert.IsInstanceOf>(properties); Assert.IsNull(properties.Data); } [Test] public void GetProperties_WithData_ReturnExpectedValues() { // Setup var mocks = new MockRepository(); var chartAxis = mocks.StrictMock(); var chart = mocks.StrictMock(); var legend = mocks.StrictMock(); var backgroundColor = Color.AliceBlue; var showLegend = false; var legendAlignment = LegendAlignment.Top; var legendFont = new Font(FontFamily.GenericSansSerif, 12); var title = "some title"; var titleFont = new Font(FontFamily.GenericSansSerif, 12); var titleVisible = false; chart.Expect(a => a.BackGroundColor).Return(backgroundColor); chart.Expect(a => a.Title).Return(title); chart.Expect(a => a.Font).Return(titleFont); chart.Expect(a => a.TitleVisible).Return(titleVisible); chart.Expect(a => a.LeftAxis).Return(chartAxis).Repeat.Twice(); chart.Expect(a => a.BottomAxis).Return(chartAxis).Repeat.Twice(); chart.Expect(a => a.RightAxis).Return(chartAxis).Repeat.Twice(); chart.Expect(a => a.Legend).Return(legend).Repeat.Times(3); legend.Expect(a => a.Visible).Return(showLegend); legend.Expect(a => a.Alignment).Return(legendAlignment); legend.Expect(a => a.Font).Return(legendFont); chartAxis.Expect(a => a.IsDateTime).Return(false).Repeat.Times(3); mocks.ReplayAll(); var properties = new ChartProperties { Data = chart }; // Call & Assert Assert.AreEqual(backgroundColor, properties.BackgroundColor); Assert.AreEqual(showLegend, properties.ShowLegend); Assert.AreEqual(legendAlignment, properties.LegendAlignment); Assert.AreEqual(legendFont, properties.LegendFont); Assert.AreEqual(title, properties.Title); Assert.AreEqual(titleFont, properties.TitleFont); Assert.AreEqual(titleVisible, properties.TitleVisibile); Assert.IsInstanceOf(properties.LeftAxis); Assert.IsInstanceOf(properties.BottomAxis); Assert.IsInstanceOf(properties.RightAxis); mocks.VerifyAll(); } [Test] public void GetProperties_Always_ReturnsTenProperties() { // Setup var mocks = new MockRepository(); var data = mocks.Stub(); var chartAxis = mocks.Stub(); var legend = mocks.Stub(); data.Expect(a => a.Legend).Return(legend).Repeat.AtLeastOnce(); data.Expect(a => a.LeftAxis).Return(chartAxis).Repeat.AtLeastOnce(); data.Expect(a => a.BottomAxis).Return(chartAxis).Repeat.AtLeastOnce(); data.Expect(a => a.RightAxis).Return(chartAxis).Repeat.AtLeastOnce(); mocks.ReplayAll(); var bag = new DynamicPropertyBag(new ChartProperties { Data = data }); // Call var properties = bag.GetProperties(new Attribute[] { new BrowsableAttribute(true) }); // Assert Assert.AreEqual(10, properties.Count); } } }