|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Linq; |
| 3 | +using FakeItEasy; |
| 4 | +using MoBi.Core.Domain.Extensions; |
| 5 | +using MoBi.Core.Domain.Model; |
| 6 | +using MoBi.HelpersForTests; |
| 7 | +using MoBi.Presentation.Nodes; |
| 8 | +using MoBi.Presentation.Presenter; |
| 9 | +using MoBi.Presentation.Settings; |
| 10 | +using MoBi.Presentation.Views; |
| 11 | +using OSPSuite.BDDHelper; |
| 12 | +using OSPSuite.BDDHelper.Extensions; |
| 13 | +using OSPSuite.Core.Chart; |
| 14 | +using OSPSuite.Core.Chart.Mappers; |
| 15 | +using OSPSuite.Core.Domain.Data; |
| 16 | +using OSPSuite.Core.Domain.Mappers; |
| 17 | +using OSPSuite.Core.Services; |
| 18 | +using OSPSuite.Presentation.Core; |
| 19 | +using OSPSuite.Presentation.Nodes; |
| 20 | +using OSPSuite.Presentation.Presenters.Charts; |
| 21 | +using OSPSuite.Presentation.Presenters.ContextMenus; |
| 22 | +using OSPSuite.Presentation.Services.Charts; |
| 23 | +using OSPSuite.Presentation.Views.Charts; |
| 24 | +using IApplicationSettings = OSPSuite.Core.IApplicationSettings; |
| 25 | +using IChartTemplatingTask = MoBi.Presentation.Tasks.IChartTemplatingTask; |
| 26 | + |
| 27 | +namespace MoBi.Presentation; |
| 28 | + |
| 29 | +public class concern_for_ComparisonChartPresenter : ContextSpecification<ComparisonChartPresenter> |
| 30 | +{ |
| 31 | + protected IChartView _chartView; |
| 32 | + protected IMoBiContext _context; |
| 33 | + protected IUserSettings _userSettings; |
| 34 | + protected IChartTemplatingTask _chartTemplatingTask; |
| 35 | + protected IQuantityPathToQuantityDisplayPathMapper _quantityDisplayPathMapper; |
| 36 | + protected IChartUpdater _chartUpdater; |
| 37 | + protected ChartPresenterContext _chartPresenterContext; |
| 38 | + protected IOutputMappingMatchingTask _outputMappingMatchingTask; |
| 39 | + protected IChartDisplayPresenter _chartDisplayPresenter; |
| 40 | + protected IDragEvent _dragEvent; |
| 41 | + private IChartDisplayView _chartDisplayView; |
| 42 | + private ICurveBinderFactory _curveBinderFactory; |
| 43 | + private IViewItemContextMenuFactory _contextMenuFactoryForProjectItem; |
| 44 | + private IAxisBinderFactory _axisBinderFactory; |
| 45 | + private ICurveToDataModeMapper _dataModeMapper; |
| 46 | + private ICurveChartExportTask _chartExportTask; |
| 47 | + private IApplicationSettings _applicationSettings; |
| 48 | + private IApplicationController _applicationController; |
| 49 | + private IDialogCreator _dialogCreator; |
| 50 | + |
| 51 | + protected override void Context() |
| 52 | + { |
| 53 | + _chartView = A.Fake<IChartView>(); |
| 54 | + _context = A.Fake<IMoBiContext>(); |
| 55 | + _userSettings = A.Fake<IUserSettings>(); |
| 56 | + _chartTemplatingTask = A.Fake<IChartTemplatingTask>(); |
| 57 | + _quantityDisplayPathMapper = A.Fake<IQuantityPathToQuantityDisplayPathMapper>(); |
| 58 | + _chartUpdater = A.Fake<IChartUpdater>(); |
| 59 | + _chartPresenterContext = A.Fake<ChartPresenterContext>(); |
| 60 | + _outputMappingMatchingTask = A.Fake<IOutputMappingMatchingTask>(); |
| 61 | + _dragEvent = A.Fake<IDragEvent>(); |
| 62 | + _dialogCreator = A.Fake<IDialogCreator>(); |
| 63 | + |
| 64 | + _chartDisplayView = A.Fake<IChartDisplayView>(); |
| 65 | + _curveBinderFactory = A.Fake<ICurveBinderFactory>(); |
| 66 | + _contextMenuFactoryForProjectItem = A.Fake<IViewItemContextMenuFactory>(); |
| 67 | + _axisBinderFactory = A.Fake<IAxisBinderFactory>(); |
| 68 | + _dataModeMapper = A.Fake<ICurveToDataModeMapper>(); |
| 69 | + _chartExportTask = A.Fake<ICurveChartExportTask>(); |
| 70 | + _applicationSettings = A.Fake<IApplicationSettings>(); |
| 71 | + _applicationController = A.Fake<IApplicationController>(); |
| 72 | + |
| 73 | + A.CallTo(() => _context.CurrentProject).Returns(new MoBiProject()); |
| 74 | + |
| 75 | + _chartDisplayPresenter = CreateDisplayPresenter(); |
| 76 | + A.CallTo(() => _chartPresenterContext.DisplayPresenter).Returns(_chartDisplayPresenter); |
| 77 | + |
| 78 | + sut = new ComparisonChartPresenter(_chartView, _context, _userSettings, _chartTemplatingTask, |
| 79 | + _quantityDisplayPathMapper, _chartUpdater, _chartPresenterContext, _outputMappingMatchingTask); |
| 80 | + _chartDisplayPresenter.Edit(new CurveChart()); |
| 81 | + } |
| 82 | + |
| 83 | + protected virtual IChartDisplayPresenter CreateDisplayPresenter() |
| 84 | + { |
| 85 | + return new ChartDisplayPresenter(_chartDisplayView, _curveBinderFactory, _contextMenuFactoryForProjectItem, |
| 86 | + _axisBinderFactory, _dataModeMapper, _chartExportTask, _applicationSettings, _applicationController, _dialogCreator); |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +public class When_dropping_historical_results_on_the_comparison_chart : concern_for_ComparisonChartPresenter |
| 91 | +{ |
| 92 | + private DataRepository _historicalResults; |
| 93 | + private DataColumn _outputColumn; |
| 94 | + |
| 95 | + protected override void Context() |
| 96 | + { |
| 97 | + base.Context(); |
| 98 | + _historicalResults = DomainHelperForSpecs.IndividualSimulationDataRepositoryFor("Sim2"); |
| 99 | + _outputColumn = _historicalResults.AllButBaseGrid().Single(); |
| 100 | + var nodes = new List<ITreeNode> { new HistoricalResultsNode(_historicalResults) }; |
| 101 | + A.CallTo(() => _dragEvent.Data<IList<ITreeNode>>()).Returns(nodes); |
| 102 | + } |
| 103 | + |
| 104 | + protected override void Because() |
| 105 | + { |
| 106 | + _chartDisplayPresenter.OnDragDrop(_dragEvent); |
| 107 | + } |
| 108 | + |
| 109 | + [Observation] |
| 110 | + public void a_curve_is_added_for_each_output_column_of_the_dropped_historical_results() |
| 111 | + { |
| 112 | + A.CallTo(() => _chartPresenterContext.EditorPresenter.AddCurveForColumn(_outputColumn, A<CurveOptions>._, A<bool>._)).MustHaveHappened(); |
| 113 | + } |
| 114 | + |
| 115 | + [Observation] |
| 116 | + public void the_dropped_repository_is_added_to_the_data_browser() |
| 117 | + { |
| 118 | + A.CallTo(() => _chartPresenterContext.EditorPresenter.AddDataRepositories(A<IReadOnlyList<DataRepository>>.That.Contains(_historicalResults))).MustHaveHappened(); |
| 119 | + } |
| 120 | + |
| 121 | + [Observation] |
| 122 | + public void the_dropped_repository_is_marked_as_persistable() |
| 123 | + { |
| 124 | + _historicalResults.IsPersistable().ShouldBeTrue(); |
| 125 | + } |
| 126 | + |
| 127 | + [Observation] |
| 128 | + public void the_chart_is_refreshed_so_the_newly_added_curves_are_painted() |
| 129 | + { |
| 130 | + // ChartPresenterContext.Refresh() is non-virtual so we can't intercept it directly; |
| 131 | + // assert on its underlying EditorPresenter.Refresh() delegate call instead. |
| 132 | + A.CallTo(() => _chartPresenterContext.EditorPresenter.Refresh()).MustHaveHappened(); |
| 133 | + } |
| 134 | +} |
0 commit comments