Ejemplo n.º 1
0
        public void CanConnectTo_WhenConnectionValidatorIsUsed_Disallow()
        {
            var diagramViewModel = Mock.Create<IDiagramViewModel>();
            var sourceConnector = new ExpressionConnector(ConnectorType.Out, new ConnectorOut(Mock.Create<ExpressionObjectBase>()));
            sourceConnector.DataType = NodeDataType.CrossReference;
            Mock.Arrange(() => sourceConnector.Connector).Returns(Mock.Create<IConnectorOut>);

            var vm = new ExpressionConnectorViewModel(sourceConnector, diagramViewModel);

            var destinationItemMock = Mock.Create<IConnectorViewModel>();
            var destinationConnector = new ExpressionConnector(ConnectorType.In, new ConnectorIn(Mock.Create<ExpressionObjectBase>()));
            destinationConnector.DataType = NodeDataType.CrossReference;
            var connector = Mock.Create<IConnectorIn>();
            var validator = new CommonConnectionValidator();
            Mock.Arrange(() => validator.CanConnect(Arg.IsAny<IConnectorOut>(), Arg.IsAny<IConnectorIn>()))
                .Returns(ConnectivityState.Define(false, "Validation failed"));
            Mock.Arrange(() => connector.Validator).Returns(validator);
            Mock.Arrange(() => destinationConnector.Connector).Returns(connector);
            Mock.Arrange(() => destinationItemMock.Item).Returns(destinationConnector);

            var state = vm.CanConnectTo(destinationItemMock, Mock.Create<ICollection<IDiagramItemViewModel>>());

            Assert.IsFalse(state.CanConnect);
            Assert.AreEqual("Validation failed", state.JustificationMessage);
        }
Ejemplo n.º 2
0
        public void CanConnectTo_WhenTypeMismatch_Disallow()
        {
            var diagramViewModel = Mock.Create<IDiagramViewModel>();
            var sourceConnector = new ExpressionConnector(ConnectorType.Out, new ConnectorOut(Mock.Create<ExpressionObjectBase>()));
            sourceConnector.DataType = NodeDataType.Choice;

            var vm = new ExpressionConnectorViewModel(sourceConnector, diagramViewModel);

            var destinationItemMock = Mock.Create<IConnectorViewModel>();
            var destinationConnector = new ExpressionConnector(ConnectorType.In, new ConnectorIn(Mock.Create<ExpressionObjectBase>()));
            destinationConnector.DataType = NodeDataType.CrossReference;
            Mock.Arrange(() => destinationItemMock.Item).Returns(destinationConnector);

            var state = vm.CanConnectTo(destinationItemMock, Mock.Create<ICollection<IDiagramItemViewModel>>());

            Assert.IsFalse(state.CanConnect);
            Assert.AreEqual(
                string.Format(CultureInfo.InvariantCulture,
                    LanguageService.Translate("Warn_ExpressionBuilder_TypesAreIncompatible"),
                    sourceConnector.DataType, destinationConnector.DataType),
                state.JustificationMessage);
        }