Ejemplo n.º 1
0
        private static IView CreateViewForData(object data, ViewInfo viewInfo)
        {
            IView view = viewInfo.CreateInstance(data);

            view.Data = viewInfo.GetViewData(data);

            viewInfo.AfterCreate(view, data);

            return(view);
        }
Ejemplo n.º 2
0
        public void AfterCreate_WithGuiSet_SetsSpecificPropertiesToView()
        {
            // Setup
            var  mocks = new MockRepository();
            IGui gui   = StubFactory.CreateGuiStub(mocks);

            gui.Stub(g => g.ViewCommands).Return(mocks.Stub <IViewCommands>());
            gui.Stub(g => g.MainWindow).Return(mocks.Stub <IMainWindow>());
            gui.Stub(g => g.DocumentViewController).Return(mocks.Stub <IDocumentViewController>());
            gui.Stub(g => g.ProjectStore).Return(mocks.Stub <IStoreProject>());
            mocks.ReplayAll();

            double GetNormFunc() => 0.01;

            var assessmentSection = new AssessmentSectionStub();
            var calculations      = new ObservableList <HydraulicBoundaryLocationCalculation>();

            var context = new WaterLevelCalculationsForNormTargetProbabilityContext(calculations,
                                                                                    assessmentSection,
                                                                                    GetNormFunc);

            using (var view = new DesignWaterLevelCalculationsView(new ObservableList <HydraulicBoundaryLocationCalculation>(),
                                                                   new AssessmentSectionStub(),
                                                                   GetNormFunc,
                                                                   () => "1/100"))

                using (var plugin = new RiskeerPlugin())
                {
                    ViewInfo info = GetViewInfo(plugin);
                    plugin.Gui = gui;
                    plugin.Activate();

                    // Call
                    info.AfterCreate(view, context);

                    // Assert
                    Assert.IsInstanceOf <IHydraulicBoundaryLocationCalculationGuiService>(view.CalculationGuiService);
                }

            mocks.VerifyAll();
        }
        public void AfterCreate_Always_SetsExpectedProperties()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var window            = mocks.Stub <IMainWindow>();
            var gui = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(window);
            gui.Stub(g => g.ViewHost).Return(mocks.Stub <IViewHost>());
            mocks.ReplayAll();

            var failureMechanism = new DuneErosionFailureMechanism();
            var data             = new DuneLocationCalculationsForUserDefinedTargetProbabilityContext(new DuneLocationCalculationsForTargetProbability(0.1),
                                                                                                      failureMechanism,
                                                                                                      assessmentSection);

            using (var plugin = new DuneErosionPlugin())
            {
                ViewInfo info = GetInfo(plugin);

                plugin.Gui = gui;
                plugin.Activate();

                using (var view = new DuneLocationCalculationsView(new ObservableList <DuneLocationCalculation>(),
                                                                   failureMechanism,
                                                                   assessmentSection,
                                                                   () => 0.01,
                                                                   () => "1/100"))
                {
                    // Call
                    info.AfterCreate(view, data);

                    // Assert
                    Assert.IsInstanceOf <DuneLocationCalculationGuiService>(view.CalculationGuiService);
                }
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 4
0
        public void ImplicitOperator_WithAllMethodsSet_InfoFullyConverted()
        {
            // Setup
            var viewInfo = new ViewInfo <int, string, StringView>();

            var       stringView = new StringView();
            const int dataObject = 11;

            const string newDescription = "<text>";
            const string newViewName    = "<view name>";
            const string symbol         = "<symbol>";
            var          fontFamily     = new FontFamily();

            string GetViewName(IView view, int o)
            {
                Assert.AreSame(stringView, view);
                Assert.AreEqual(dataObject, o);
                return(newViewName);
            }

            string GetSymbol() => symbol;
            FontFamily GetFontFamily() => fontFamily;

            bool AdditionalDataCheck(int o)
            {
                Assert.AreEqual(dataObject, o);
                return(true);
            }

            string GetViewData(int o)
            {
                Assert.AreEqual(dataObject, o);
                return(o.ToString());
            }

            var afterCreateCalled = false;

            void AfterCreate(IView view, int o)
            {
                Assert.AreSame(stringView, view);
                Assert.AreEqual(dataObject, o);
                afterCreateCalled = true;
            }

            bool CloseForData(IView view, object o)
            {
                Assert.AreSame(stringView, view);
                Assert.AreEqual(dataObject, o);
                return(true);
            }

            viewInfo.Description         = newDescription;
            viewInfo.GetViewName         = (Func <IView, int, string>)GetViewName;
            viewInfo.GetSymbol           = GetSymbol;
            viewInfo.GetFontFamily       = GetFontFamily;
            viewInfo.AdditionalDataCheck = AdditionalDataCheck;
            viewInfo.GetViewData         = GetViewData;
            viewInfo.AfterCreate         = (Action <IView, int>)AfterCreate;
            viewInfo.CloseForData        = (Func <IView, object, bool>)CloseForData;
            viewInfo.CreateInstance      = o => new StringView
            {
                Text = "A"
            };

            // Precondition
            Assert.IsInstanceOf <ViewInfo <int, string, StringView> >(viewInfo);

            // Call
            ViewInfo info = viewInfo;

            // Assert
            Assert.IsInstanceOf <ViewInfo>(info);
            Assert.AreEqual(typeof(int), info.DataType);
            Assert.AreEqual(typeof(string), info.ViewDataType);
            Assert.AreEqual(typeof(StringView), info.ViewType);
            Assert.AreEqual(newDescription, info.Description);
            Assert.AreEqual(newViewName, info.GetViewName(stringView, dataObject));
            Assert.AreEqual(symbol, info.GetSymbol());
            Assert.AreSame(fontFamily, info.GetFontFamily());
            Assert.IsTrue(viewInfo.AdditionalDataCheck(dataObject));
            Assert.AreEqual(dataObject.ToString(), viewInfo.GetViewData(dataObject));
            Assert.AreEqual("A", viewInfo.CreateInstance(dataObject).Text);

            viewInfo.AfterCreate(stringView, dataObject);
            Assert.IsTrue(afterCreateCalled);
        }