public void It_should_pass_empty_validator()
 {
     var provider = new ValidationProvider();
     var textBox = new TextBox();
     provider.SetValidationRule(textBox, new ValidationRule());
     provider.Validate().Should().Be.True();
 }
Exemplo n.º 2
0
        public ConnectionForm(ConnectionFormController controller)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            this.InitializeComponent();

            this.parentConnectionComboBox.DisplayMember = "DisplayText";
            this.proxyComboBox.DisplayMember = "DisplayText";
            this.navigationList.SelectedIndex = 0;

            this.Controller = controller;
            this.Controller.Register(this);

            this.connectionValidator = new ValidationProvider();
            this.tunnelValidator = new ValidationProvider();

            this.connectionValidator.ErrorProvider = this.myErrorProvider;
            this.tunnelValidator.ErrorProvider = this.myErrorProvider;

            this.connectionValidator.SetValidationRule(this.hostNameTextBox, new HostNameValidationRule());
            this.connectionValidator.SetValidationRule(this.portTextBox, new PortNumberValidationRule());
            this.connectionValidator.SetValidationRule(this.userNameTextBox, new UserNameValidationRule());
            this.connectionValidator.SetValidationRule(
                this.passwordTextBox,
                new DelegatedValidationRule<string>(this.ValidatePassword));
            this.connectionValidator.SetValidationRule(
                this.privateKeyFileNameLabel,
                new DelegatedValidationRule<string>(this.ValidatePrivateKeyData));

            this.tunnelValidator.SetValidationRule(
                this.tunnelSrcPortTextBox,
                new DelegatedValidationRule<string>(this.ValidateTunnelSourcePort));
            this.tunnelValidator.SetValidationRule(
                this.tunnelDstHostTextBox,
                new DelegatedValidationRule<string>(this.ValidateTunnelDestinationHost));
            this.tunnelValidator.SetValidationRule(
                this.tunnelDstPortTextBox,
                new DelegatedValidationRule<string>(this.ValidateTunnelDestinationPort));
            this.tunnelValidator.SetValidationRule(
                this.tunnelNameTextBox,
                new DelegatedValidationRule<string>(this.ValidateTunnelName));

            EventHandler changeHandler = delegate { this.Modified = true; };
            this.connectionNameTextBox.TextChanged += changeHandler;
            this.hostNameTextBox.TextChanged += changeHandler;
            this.portTextBox.TextChanged += changeHandler;
            this.userNameTextBox.TextChanged += changeHandler;
            this.passwordTextBox.TextChanged += changeHandler;
            this.passphraseTextBox.TextChanged += changeHandler;
            this.remoteCommandTextBox.TextChanged += changeHandler;
            this.usePasswordRadioButton.CheckedChanged += changeHandler;
            this.loadPrivateKeyButton.Click += changeHandler;
            this.parentConnectionComboBox.SelectedIndexChanged += changeHandler;
            this.proxyComboBox.SelectedIndexChanged += changeHandler;
        }