Ejemplo n.º 1
0
        public void CanRemove_Always_ReturnsTrue()
        {
            // Call
            bool canRemove = info.CanRemove(null, null);

            // Assert
            Assert.IsTrue(canRemove);
        }
        public void CanRemove_WithRemovableDataAndCollection_ReturnTrue()
        {
            // Setup
            var removable = mocks.StrictMultiMock <FeatureBasedMapData>(new[]
            {
                typeof(IRemovable)
            }, "name");

            mocks.ReplayAll();

            FeatureBasedMapDataContext context = GetContext(removable);

            // Call
            bool canRemove = info.CanRemove(context, context.ParentMapData);

            // Assert
            Assert.IsTrue(canRemove);
        }
        public void CanRemove_Always_ReturnsFalse()
        {
            // Setup
            using (var plugin = new RiskeerPlugin())
            {
                TreeNodeInfo info = GetInfo(plugin);
                // Call
                bool canRemove = info.CanRemove(null, null);

                // Assert
                Assert.IsFalse(canRemove);
            }
        }
        public void OnNodeRemoved_ParentIsCalculationGroupContext_RemoveCalculationFromGroup()
        {
            // Setup
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());

            var elementToBeRemoved = new MacroStabilityInwardsCalculationScenario();

            var group = new CalculationGroup();

            group.Children.Add(elementToBeRemoved);
            group.Children.Add(new MacroStabilityInwardsCalculationScenario());
            group.Attach(observer);

            var failureMechanism  = new MacroStabilityInwardsFailureMechanism();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var calculationContext = new MacroStabilityInwardsCalculationScenarioContext(elementToBeRemoved,
                                                                                         group,
                                                                                         Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(),
                                                                                         Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(),
                                                                                         failureMechanism,
                                                                                         assessmentSection);
            var groupContext = new MacroStabilityInwardsCalculationGroupContext(group,
                                                                                null,
                                                                                Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(),
                                                                                Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(),
                                                                                failureMechanism,
                                                                                assessmentSection);

            // Precondition
            Assert.IsTrue(info.CanRemove(calculationContext, groupContext));
            Assert.AreEqual(2, group.Children.Count);

            // Call
            info.OnNodeRemoved(calculationContext, groupContext);

            // Assert
            Assert.AreEqual(1, group.Children.Count);
            CollectionAssert.DoesNotContain(group.Children, elementToBeRemoved);
        }
Ejemplo n.º 5
0
        public void ImplicitOperator_WithAllMethodsSet_InfoFullyConverted()
        {
            // Setup
            var onDropCounter        = 0;
            var onNodeRenamedCounter = 0;
            var onNodeRemovedCounter = 0;
            var onNodeCheckedCounter = 0;

            var genericTreeNodeInfo = new TreeNodeInfo <int>
            {
                Text             = o => "text",
                ForeColor        = o => Color.Azure,
                Image            = o => new Bitmap(16, 16),
                ContextMenuStrip = (o1, o2, tvc) => new ContextMenuStrip
                {
                    Items =
                    {
                        new ToolStripButton()
                    }
                },
                EnsureVisibleOnCreate = (o, p) => true,
                ExpandOnCreate        = o => true,
                ChildNodeObjects      = o => new[]
                {
                    new object()
                },
                CanRename     = (o1, o2) => true,
                OnNodeRenamed = (o, newName) =>
                {
                    onNodeRenamedCounter++;
                },
                CanRemove     = (o1, o2) => true,
                OnNodeRemoved = (o1, o2) =>
                {
                    onNodeRemovedCounter++;
                },
                OnRemoveConfirmationText           = o => "Confirmation message",
                OnRemoveChildNodesConfirmationText = o => "Confirmation message 2",
                CanCheck      = o => true,
                CheckedState  = o => TreeNodeCheckedState.Checked,
                OnNodeChecked = (o1, o2) =>
                {
                    onNodeCheckedCounter++;
                },
                CanDrag   = (o1, o2) => true,
                CanDrop   = (o1, o2) => true,
                CanInsert = (o1, o2) => true,
                OnDrop    = (o1, o2, o3, index, tvc) =>
                {
                    onDropCounter++;
                }
            };

            // Precondition
            Assert.IsInstanceOf <TreeNodeInfo <int> >(genericTreeNodeInfo);

            // Call
            TreeNodeInfo treeNodeInfo = genericTreeNodeInfo;

            // Assert
            using (var treeViewControl = new TreeViewControl())
                using (ContextMenuStrip contextMenuStrip = treeNodeInfo.ContextMenuStrip(0, 1, treeViewControl))
                {
                    Assert.AreEqual(1, contextMenuStrip.Items.Count);
                    treeNodeInfo.OnDrop(0, 1, 2, 3, treeViewControl);
                    Assert.AreEqual(1, onDropCounter);
                }

            Assert.AreEqual(typeof(int), treeNodeInfo.TagType);
            Assert.AreEqual("text", treeNodeInfo.Text(0));
            Assert.AreEqual(Color.Azure, treeNodeInfo.ForeColor(0));
            Assert.AreEqual(16, treeNodeInfo.Image(0).Height);
            Assert.IsTrue(treeNodeInfo.EnsureVisibleOnCreate(0, 1));
            Assert.IsTrue(treeNodeInfo.ExpandOnCreate(0));
            Assert.AreEqual(1, treeNodeInfo.ChildNodeObjects(0).Length);
            Assert.IsTrue(treeNodeInfo.CanRename(0, 1));
            Assert.IsTrue(treeNodeInfo.CanRemove(0, 1));
            Assert.AreEqual("Confirmation message", treeNodeInfo.OnRemoveConfirmationText(0));
            Assert.AreEqual("Confirmation message 2", treeNodeInfo.OnRemoveChildNodesConfirmationText(0));
            Assert.IsTrue(treeNodeInfo.CanCheck(0));
            Assert.AreEqual(TreeNodeCheckedState.Checked, treeNodeInfo.CheckedState(0));
            Assert.IsTrue(treeNodeInfo.CanDrag(0, 1));
            Assert.IsTrue(treeNodeInfo.CanDrop(0, 1));
            Assert.IsTrue(treeNodeInfo.CanInsert(0, 1));

            treeNodeInfo.OnNodeRenamed(0, "newName");
            Assert.AreEqual(1, onNodeRenamedCounter);

            treeNodeInfo.OnNodeRemoved(0, 1);
            Assert.AreEqual(1, onNodeRemovedCounter);

            treeNodeInfo.OnNodeChecked(0, 1);
            Assert.AreEqual(1, onNodeCheckedCounter);
        }