public void IsEnabled_ReferenceLineWithoutGeometry_ReturnFalse()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine());
            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            var context = new HeightStructuresContext(failureMechanism.HeightStructures,
                                                      failureMechanism, assessmentSection);

            using (var plugin = new HeightStructuresPlugin())
            {
                ImportInfo importInfo = GetImportInfo(plugin);

                // Call
                bool isEnabled = importInfo.IsEnabled(context);

                // Assert
                Assert.IsFalse(isEnabled);
            }

            mocks.VerifyAll();
        }
        public void CreateFileImporter_Always_ReturnFileImporter()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine());
            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();
            var importTarget     = new HeightStructuresContext(failureMechanism.HeightStructures,
                                                               failureMechanism, assessmentSection);

            using (var plugin = new HeightStructuresPlugin())
            {
                ImportInfo importInfo = GetImportInfo(plugin);

                // Call
                IFileImporter importer = importInfo.CreateFileImporter(importTarget, "test");

                // Assert
                Assert.IsInstanceOf <HeightStructuresImporter>(importer);
            }

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

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            using (var plugin = new HeightStructuresPlugin())
            {
                plugin.Gui = gui;

                var failureMechanism = new HeightStructuresFailureMechanism();
                failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation <HeightStructuresInput>());

                var structures = new StructureCollection <HeightStructure>();
                var context    = new HeightStructuresContext(structures, failureMechanism, assessmentSection);

                ImportInfo importInfo = GetImportInfo(plugin);

                // Call
                bool updatesVerified = importInfo.VerifyUpdates(context);

                // Assert
                Assert.IsTrue(updatesVerified);
                mocks.VerifyAll();
            }
        }
Example #4
0
        public void ForeColor_CollectionHasElementsEmpty_ReturnControlText()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            failureMechanism.HeightStructures.AddRange(new[]
            {
                new TestHeightStructure("id", "TestHeightStructure")
            }, "some path");

            // Precondition
            CollectionAssert.IsNotEmpty(failureMechanism.HeightStructures);

            var heightStructuresContext = new HeightStructuresContext(failureMechanism.HeightStructures,
                                                                      failureMechanism, assessmentSection);

            // Call
            Color color = info.ForeColor(heightStructuresContext);

            // Assert
            Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color);
            mocks.VerifyAll();
        }
Example #5
0
        public void ChildNodeObjects_Always_ReturnHeightStructures()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            failureMechanism.HeightStructures.AddRange(new[]
            {
                new TestHeightStructure("first id", "TestHeightStructure 1"),
                new TestHeightStructure("second id", "TestHeightStructure 2")
            }, "some path");

            var heightStructuresContext = new HeightStructuresContext(failureMechanism.HeightStructures,
                                                                      failureMechanism, assessmentSection);

            // Call
            object[] children = info.ChildNodeObjects(heightStructuresContext);

            // Assert
            CollectionAssert.AreEqual(failureMechanism.HeightStructures, children);
            mocks.VerifyAll();
        }
        public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var mainWindow        = mocks.Stub <IMainWindow>();
            var gui = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            using (var plugin = new HeightStructuresPlugin())
            {
                plugin.Gui = gui;

                var failureMechanism = new HeightStructuresFailureMechanism();
                failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation <HeightStructuresInput>
                {
                    Output = new TestStructuresOutput()
                });

                var structures = new StructureCollection <HeightStructure>();
                var context    = new HeightStructuresContext(structures, failureMechanism, assessmentSection);

                ImportInfo importInfo = GetImportInfo(plugin);

                string textBoxMessage = null;
                DialogBoxHandler = (name, wnd) =>
                {
                    var helper = new MessageBoxTester(wnd);
                    textBoxMessage = helper.Text;

                    if (isActionConfirmed)
                    {
                        helper.ClickOk();
                    }
                    else
                    {
                        helper.ClickCancel();
                    }
                };

                // Call
                bool updatesVerified = importInfo.VerifyUpdates(context);

                // Assert
                string expectedInquiryMessage = "Als u kunstwerken importeert, dan worden alle rekenresultaten van dit faalmechanisme verwijderd." +
                                                $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";
                Assert.AreEqual(expectedInquiryMessage, textBoxMessage);
                Assert.AreEqual(isActionConfirmed, updatesVerified);
                mocks.VerifyAll();
            }
        }
Example #7
0
        public void IsEnabled_SourcePathNull_ReturnFalse()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();
            var structures       = new StructureCollection <HeightStructure>();

            var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection);

            // Call
            bool isEnabled = updateInfo.IsEnabled(context);

            // Assert
            Assert.IsFalse(isEnabled);
            mocks.VerifyAll();
        }
Example #8
0
        public void Image_Always_ReturnExpectedImage()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            var heightStructuresContext = new HeightStructuresContext(failureMechanism.HeightStructures,
                                                                      failureMechanism, assessmentSection);

            // Call
            Image image = info.Image(heightStructuresContext);

            // Assert
            TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.GeneralFolderIcon, image);
            mocks.VerifyAll();
        }
Example #9
0
        public void ParameteredConstructor_ExpectedValues()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            // Call
            var context = new HeightStructuresContext(failureMechanism.HeightStructures,
                                                      failureMechanism, assessmentSection);

            // Assert
            Assert.IsInstanceOf <ObservableWrappedObjectContextBase <StructureCollection <HeightStructure> > >(context);
            Assert.AreSame(failureMechanism, context.FailureMechanism);
            Assert.AreSame(failureMechanism.HeightStructures, context.WrappedData);
            Assert.AreSame(assessmentSection, context.AssessmentSection);
            mocks.VerifyAll();
        }
Example #10
0
        public void CreateFileImporter_ValidInput_ReturnFileImporter()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine());
            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();
            var structures       = new StructureCollection <HeightStructure>();

            var importTarget = new HeightStructuresContext(structures, failureMechanism, assessmentSection);

            // Call
            IFileImporter importer = updateInfo.CreateFileImporter(importTarget, "This is valid");

            // Assert
            Assert.IsInstanceOf <HeightStructuresImporter>(importer);
            mocks.VerifyAll();
        }
Example #11
0
        public void Text_Always_ReturnExpectedText()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            var heightStructuresContext = new HeightStructuresContext(failureMechanism.HeightStructures,
                                                                      failureMechanism, assessmentSection);

            // Call
            string text = info.Text(heightStructuresContext);

            // Assert
            const string expectedText = "Kunstwerken";

            Assert.AreEqual(expectedText, text);
            mocks.VerifyAll();
        }
Example #12
0
        public void IsEnabled_SourcePathSet_ReturnTrue()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();
            var structures       = new StructureCollection <HeightStructure>();

            structures.AddRange(Enumerable.Empty <HeightStructure>(), "some path");

            var context = new HeightStructuresContext(structures, failureMechanism, assessmentSection);

            // Call
            bool isEnabled = updateInfo.IsEnabled(context);

            // Assert
            Assert.IsTrue(isEnabled);
            mocks.VerifyAll();
        }
        public void CreateInstance_WithContext_NewPropertiesWithContextAsData()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            var collection = new StructureCollection <HeightStructure>();
            var context    = new HeightStructuresContext(collection, failureMechanism, assessmentSection);

            // Call
            IObjectProperties objectProperties = info.CreateInstance(context);

            // Assert
            Assert.IsInstanceOf <StructureCollectionProperties <HeightStructure> >(objectProperties);
            Assert.AreSame(collection, objectProperties.Data);

            mocks.VerifyAll();
        }
Example #14
0
        public void ForeColor_CollectionIsEmpty_ReturnGrayText()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();

            // Precondition
            CollectionAssert.IsEmpty(failureMechanism.HeightStructures);

            var heightStructuresContext = new HeightStructuresContext(failureMechanism.HeightStructures,
                                                                      failureMechanism, assessmentSection);

            // Call
            Color color = info.ForeColor(heightStructuresContext);

            // Assert
            Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color);
            mocks.VerifyAll();
        }
Example #15
0
        public void CurrentPath_StructureCollectionHasPathSet_ReturnsExpectedPath()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            const string expectedFilePath = "some/path";
            var          structures       = new StructureCollection <HeightStructure>();

            structures.AddRange(Enumerable.Empty <HeightStructure>(), expectedFilePath);

            var failureMechanism = new HeightStructuresFailureMechanism();
            var context          = new HeightStructuresContext(structures, failureMechanism, assessmentSection);

            // Call
            string currentPath = updateInfo.CurrentPath(context);

            // Assert
            Assert.AreEqual(expectedFilePath, currentPath);
            mocks.VerifyAll();
        }
Example #16
0
 private static IFileImporter CreateHeightStructuresImporter(HeightStructuresContext context, string filePath,
                                                             IImporterMessageProvider messageProvider, IStructureUpdateStrategy <HeightStructure> strategy)
 {
     return(new HeightStructuresImporter(context.WrappedData, context.AssessmentSection.ReferenceLine,
                                         filePath, messageProvider, strategy));
 }