// X Y private void ConstructXY() { //@Focus TextBoxExtensions.SetDefault(this.XTextBox, $"{0}"); this.XTextBox.Text = $"{0}"; this.XTextBox.KeyDown += (s, e) => { if (e.Key == VirtualKey.Enter) { this.Focus(FocusState.Programmatic); } }; this.XTextBox.GotFocus += (s, e) => this.SettingViewModel.UnregisteKey(); this.XTextBox.LostFocus += (s, e) => { this.SettingViewModel.RegisteKey(); if (this.XTextBox.Text is string value) { if (string.IsNullOrEmpty(value)) { return; } float x = float.Parse(value); Transformer transformer = this.SelectionTransformer; Vector2 vector = transformer.TransformX((float)x, this.IndicatorMode); // Method this.MethodViewModel.MethodTransformAdd(vector); } }; //@Focus TextBoxExtensions.SetDefault(this.YTextBox, $"{0}"); this.YTextBox.Text = $"{0}"; this.YTextBox.KeyDown += (s, e) => { if (e.Key == VirtualKey.Enter) { this.Focus(FocusState.Programmatic); } }; this.YTextBox.GotFocus += (s, e) => this.SettingViewModel.UnregisteKey(); this.YTextBox.LostFocus += (s, e) => { this.SettingViewModel.RegisteKey(); if (this.YTextBox.Text is string value) { if (string.IsNullOrEmpty(value)) { return; } float y = float.Parse(value); Transformer transformer = this.SelectionTransformer; Vector2 vector = transformer.TransformY((float)y, this.IndicatorMode); // Method this.MethodViewModel.MethodTransformAdd(vector); } }; }
public void TextBoxFor_creates_number_and_required_data_attributes_for_decimal() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new DecimalModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.Number, true); // Assert Assert.AreEqual(HTMLRequiredNumber, result.ToHtmlString()); }
public void TextBoxFor_creates_number_data_attributes_for_nullable_double() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new NullableDoubleModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.Number, true); // Assert Assert.AreEqual(HTMLNumber, result.ToHtmlString()); }
public void TextBoxFor_creates_range_and_number_data_attributes_for_nullable_byte_with_Range_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new NullableByteRangeModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.Number, true); // Assert Assert.AreEqual(HTMLRangeNumber.Replace("-20", "20"), result.ToHtmlString()); }
public void TextBoxFor_creates_required_and_date_data_attributes_for_nullable_DateTime_with_Required_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new RequiredNullableDateTimeModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.Date, true); // Assert Assert.AreEqual(HTMLRequiredDate, result.ToHtmlString()); }
public void TextBoxFor_creates_range_and_number_data_attributes_for_float_with_Range_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new NullableSingleRangeModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.Number, true); // Assert Assert.AreEqual(HTMLRangeNumberWithFraction, result.ToHtmlString()); }
public void TextBoxFor_creates_custom_data_attributes() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new StringModel()); // used this model as it has few generated metadata attributes // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.String, true, htmlAttributes: new { data_test_attribute = "I am a test" }); // Assert Assert.AreEqual("<input " + "data-test-attribute=\"I am a test\" " + "id=\"String\" name=\"String\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_overrides_generated_data_attributes_with_custom_data_attributes() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new RequiredStringThatWillBeOverriddenModel()); // used this model as it has few generated metadata attributes // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.String, true, htmlAttributes: new { data_rule_required = "Yup", data_msg_required = "Uh-huh" }); // Assert Assert.AreEqual("<input " + "data-msg-required=\"Uh-huh\" data-rule-required=\"Yup\" " + "id=\"String\" name=\"String\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_url_data_attributes_for_string_with_Url_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new UrlModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.Url, true); // Assert Assert.AreEqual("<input " + "data-msg-url=\"The Url field is not a valid fully-qualified http, https, or ftp URL.\" " + "data-rule-url=\"true\" " + "id=\"Url\" name=\"Url\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_pattern_data_attributes_for_string_with_RegularExpression_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new ExtensionModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.FileExtension, true); // Assert Assert.AreEqual("<input " + "data-msg-extension=\"The FileExtension field only accepts files with the following extensions: .doc, .pdf, .txt\" " + "data-rule-extension=\"doc,pdf,txt\" " + "id=\"FileExtension\" name=\"FileExtension\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_email_data_attributes_for_string_with_EmailAddress_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new EmailModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.Email, true); // Assert Assert.AreEqual("<input " + "data-msg-email=\"The Email field is not a valid e-mail address.\" " + "data-rule-email=\"true\"" + " id=\"Email\" name=\"Email\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_equalto_data_attributes_for_string_with_Compare_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new EqualToModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.ConfirmField, true); // Assert Assert.AreEqual("<input " + "data-msg-equalto=\"'ConfirmField' and 'MainField' do not match.\" " + "data-rule-equalto=\"#MainField\" " + "id=\"ConfirmField\" name=\"ConfirmField\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_required_data_attributes_for_string_with_Required_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new RequiredStringModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.String, true); // Assert Assert.AreEqual("<input " + "data-msg-required=\"The String field is required.\" " + "data-rule-required=\"true\" " + "id=\"String\" name=\"String\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_pattern_data_attributes_for_string_with_RegularExpression_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new RegexModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.RegularExpression, true); // Assert Assert.AreEqual("<input " + "data-msg-pattern=\"The field RegularExpression must match the regular expression '.*'.\" " + "data-rule-pattern=\".*\" " + "id=\"RegularExpression\" name=\"RegularExpression\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_custom_validation_data_attributes_for_string_with_custom_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new CustomValidationModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.DifferentProperty, true); // Assert Assert.AreEqual("<input " + "data-msg-notequalto=\"These fields cannot match\" " + "data-rule-notequalto=\"{"other":"#Property"}\" " + "id=\"DifferentProperty\" name=\"DifferentProperty\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_creditcard_data_attributes_for_string_with_CreditCard_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new CreditCardModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.CreditCard, true); // Assert Assert.AreEqual("<input " + "data-msg-creditcard=\"The CreditCard field is not a valid credit card number.\" " + "data-rule-creditcard=\"true\" " + "id=\"CreditCard\" name=\"CreditCard\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_minlength_data_attributes_for_string_with_MinLength_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new MinLengthModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.MinLength, true); // Assert Assert.AreEqual("<input " + "data-msg-minlength=\"The field MinLength must be a string or array type with a minimum length of '6'.\" " + "data-rule-minlength=\"6\" " + "id=\"MinLength\" name=\"MinLength\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_maxlength_data_attributes_for_string_with_StringLength_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new StringLengthOnlyMaxModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.MaxLength, true); // Assert Assert.AreEqual("<input " + "data-msg-maxlength=\"The field MaxLength must be a string with a maximum length of 7.\" " + "data-rule-maxlength=\"7\" " + "id=\"MaxLength\" name=\"MaxLength\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
public void TextBoxFor_creates_remote_data_attributes_for_string_with_Remote_attribute() { // Arrange var htmlHelper = HtmlHelperFactory.Create(new RemoteModel()); // Act var result = TextBoxExtensions.TextBoxFor(htmlHelper, exampleModel => exampleModel.Remote, true); // Assert Assert.AreEqual("<input " + "data-msg-remote=\"'Remote' is invalid.\" " + "data-rule-remote=\"{" + ""url":"Fake Url"," + ""additionalfields":"*.Remote"" + "}\" " + "id=\"Remote\" name=\"Remote\" type=\"text\" value=\"\" />", result.ToHtmlString()); }
// Width Height private void ConstructWidthHeight() { //@Focus TextBoxExtensions.SetDefault(this.WidthTextBox, $"{1}"); this.WidthTextBox.Text = $"{1}"; this.WidthTextBox.KeyDown += (s, e) => { if (e.Key == VirtualKey.Enter) { this.Focus(FocusState.Programmatic); } }; this.WidthTextBox.GotFocus += (s, e) => this.SettingViewModel.UnregisteKey(); this.WidthTextBox.LostFocus += (s, e) => { this.SettingViewModel.RegisteKey(); if (this.WidthTextBox.Text is string value) { if (string.IsNullOrEmpty(value)) { return; } float width = float.Parse(value); if (width < 1) { width = 1; this.WidthTextBox.Text = $"{1}"; } Transformer transformer = this.SelectionTransformer; Matrix3x2 matrix = transformer.TransformWidth((float)width, this.IndicatorMode, this.IsRatio); // Method this.MethodViewModel.MethodTransformMultiplies(matrix); } }; //@Focus TextBoxExtensions.SetDefault(this.HeightTextBox, $"{1}"); this.HeightTextBox.Text = $"{1}"; this.HeightTextBox.KeyDown += (s, e) => { if (e.Key == VirtualKey.Enter) { this.Focus(FocusState.Programmatic); } }; this.HeightTextBox.GotFocus += (s, e) => this.SettingViewModel.UnregisteKey(); this.HeightTextBox.LostFocus += (s, e) => { this.SettingViewModel.RegisteKey(); if (this.HeightTextBox.Text is string value) { if (string.IsNullOrEmpty(value)) { return; } float height = float.Parse(value); if (height < 1) { height = 1; this.HeightTextBox.Text = $"{1}"; } Transformer transformer = this.SelectionTransformer; Matrix3x2 matrix = transformer.TransformHeight((float)height, this.IndicatorMode, this.IsRatio); // Method this.MethodViewModel.MethodTransformMultiplies(matrix); } }; }
// Radian Skew private void ConstructRadianSkew() { //@Focus TextBoxExtensions.SetDefault(this.RotateTextBox, $"{0} º"); this.RotateTextBox.Text = $"{0} º"; this.RotateTextBox.KeyDown += (s, e) => { if (e.Key == VirtualKey.Enter) { this.Focus(FocusState.Programmatic); } }; this.RotateTextBox.GotFocus += (s, e) => this.SettingViewModel.UnregisteKey(); this.RotateTextBox.LostFocus += (s, e) => { this.SettingViewModel.RegisteKey(); if (this.RotateTextBox.Text is string value) { if (string.IsNullOrEmpty(value)) { return; } value = value.Replace("º", string.Empty); float angle = float.Parse(value); if (angle < -180) { angle = -180; this.RotateTextBox.Text = $"{180} º"; } else if (angle > 180) { angle = 180; this.RotateTextBox.Text = $"{-180} º"; } Transformer transformer = this.SelectionTransformer; Matrix3x2 matrix = transformer.TransformRotate((float)angle, this.IndicatorMode); // Method this.MethodViewModel.MethodTransformMultiplies(matrix); } }; //@Focus TextBoxExtensions.SetDefault(this.SkewTextBox, $"{0} º"); this.SkewTextBox.Text = $"{0} º"; this.SkewTextBox.KeyDown += (s, e) => { if (e.Key == VirtualKey.Enter) { this.Focus(FocusState.Programmatic); } }; this.SkewTextBox.GotFocus += (s, e) => this.SettingViewModel.UnregisteKey(); this.SkewTextBox.LostFocus += (s, e) => { this.SettingViewModel.RegisteKey(); if (this.SkewTextBox.Text is string value) { if (string.IsNullOrEmpty(value)) { return; } value = value.Replace("º", string.Empty); float angle = float.Parse(value); if (angle < -90) { angle = -90; this.SkewTextBox.Text = $"{90} º"; } else if (angle > 90) { angle = 90; this.SkewTextBox.Text = $"{-90} º"; } Transformer transformer = this.SelectionTransformer; Matrix3x2 matrix = transformer.TransformSkew((float)angle, this.IndicatorMode); // Method this.MethodViewModel.MethodTransformMultiplies(matrix); } }; }