public void TestIsValidChar_WithDecimal_ReturnsFalseForMultipleDots() { //---------------Set up test pack------------------- TextBoxMapperStrategyWin strategy = (TextBoxMapperStrategyWin)GetControlFactory().CreateTextBoxMapperStrategy(); BOProp boProp = CreateBOPropForType(typeof(decimal)); strategy.AddKeyPressEventHandler(_mapper, boProp); _mapper.Control.Text = "12.3"; //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.IsFalse(strategy.IsValidCharacter('.')); //---------------Tear down ------------------------- }
public void TestIsValidChar_ReturnsTrueIfTextBoxNotSet() { //---------------Set up test pack------------------- TextBoxMapperStrategyWin strategy = (TextBoxMapperStrategyWin)GetControlFactory().CreateTextBoxMapperStrategy(); //---------------Assert pre-condition--------------- //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.IsTrue(strategy.IsValidCharacter('a')); Assert.IsTrue(strategy.IsValidCharacter(' ')); Assert.IsTrue(strategy.IsValidCharacter('.')); Assert.IsTrue(strategy.IsValidCharacter('-')); //---------------Tear down ------------------------- }
public void TestIsValidChar_WithDecimal_ReturnsTrueForDotNotAtStart() { //---------------Set up test pack------------------- TextBoxMapperStrategyWin strategy = (TextBoxMapperStrategyWin)GetControlFactory().CreateTextBoxMapperStrategy(); BOProp boProp = CreateBOPropForType(typeof(decimal)); strategy.AddKeyPressEventHandler(_mapper, boProp); _mapper.Control.Text = "123"; ((TextBoxWin)_mapper.Control).SelectionStart = 3; //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.IsTrue(strategy.IsValidCharacter('.')); //---------------Tear down ------------------------- }
public void TestIsValidChar_WithInt_ReturnsFalseForNegativeAfterStart() { //---------------Set up test pack------------------- TextBoxMapperStrategyWin strategy = (TextBoxMapperStrategyWin)GetControlFactory().CreateTextBoxMapperStrategy(); BOProp boProp = CreateBOPropForType(typeof(int)); strategy.AddKeyPressEventHandler(_mapper, boProp); _mapper.Control.Text = "123"; ((TextBoxWin)_mapper.Control).SelectionStart = 2; //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.IsFalse(strategy.IsValidCharacter('-')); //---------------Tear down ------------------------- }
public void Test_AddUpdateBoPropOnValueChangedHandler_WhenMapperUsingControlAdapter_ShouldAddBehaviours() { //---------------Set up test pack------------------- var txt = GetWinFormsControlAdapter(); var textBoxMapper = new TextBoxMapperStub(txt); //---------------Assert textBoxMapperStub---------------- Assert.IsInstanceOf <TextBox>(textBoxMapper.Control.GetControl()); Assert.IsInstanceOf <TextBox>(textBoxMapper.GetControl()); //---------------Execute Test ---------------------- var comboBoxStrategyWin = new TextBoxMapperStrategyWin(); comboBoxStrategyWin.AddUpdateBoPropOnTextChangedHandler(textBoxMapper, GenerateStub <IBOProp>()); //---------------Assert Result---------------------- Assert.IsTrue(true, "If an error was not thrown then we are OK"); }
public void TestIsValidChar_WithInt_ReturnsTrueForNumber() { //---------------Set up test pack------------------- TextBoxMapperStrategyWin strategy = (TextBoxMapperStrategyWin)GetControlFactory().CreateTextBoxMapperStrategy(); BOProp boProp = CreateBOPropForType(typeof(int)); strategy.AddKeyPressEventHandler(_mapper, boProp); //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.IsTrue(strategy.IsValidCharacter('0')); Assert.IsTrue(strategy.IsValidCharacter('9')); Assert.IsTrue(strategy.IsValidCharacter('-')); Assert.IsTrue(strategy.IsValidCharacter(Convert.ToChar(8))); //---------------Tear down ------------------------- }
public void TestIsValidChar_WithString_ReturnsTrueForNonNumericTypes() { //---------------Set up test pack------------------- TextBoxMapperStrategyWin strategy = (TextBoxMapperStrategyWin)GetControlFactory().CreateTextBoxMapperStrategy(); BOProp boProp = CreateBOPropForType(typeof(string)); strategy.AddKeyPressEventHandler(_mapper, boProp); //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.IsTrue(strategy.IsValidCharacter('a')); Assert.IsTrue(strategy.IsValidCharacter(' ')); Assert.IsTrue(strategy.IsValidCharacter('.')); Assert.IsTrue(strategy.IsValidCharacter('-')); //---------------Tear down ------------------------- }
public void TestBoProp_ChangesWhen_TextBoxTextChanges() { //---------------Set up test pack------------------- _mapper.BusinessObject = _shape; TextBoxMapperStrategyWin strategy = (TextBoxMapperStrategyWin)GetControlFactory().CreateTextBoxMapperStrategy(); IBOProp boProp = _shape.Props["ShapeName"]; strategy.AddKeyPressEventHandler(_mapper, boProp); strategy.AddUpdateBoPropOnTextChangedHandler(_mapper, boProp); _mapper.Control.Text = "TestString"; //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.AreEqual("TestString", boProp.Value); //---------------Tear down ------------------------- }
public void TestIsValidChar_WithDecimal_ReturnsFalseForNonNumber() { //---------------Set up test pack------------------- TextBoxMapperStrategyWin strategy = (TextBoxMapperStrategyWin)GetControlFactory().CreateTextBoxMapperStrategy(); BOProp boProp = CreateBOPropForType(typeof(decimal)); strategy.AddKeyPressEventHandler(_mapper, boProp); //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.IsFalse(strategy.IsValidCharacter('a')); Assert.IsFalse(strategy.IsValidCharacter('A')); Assert.IsFalse(strategy.IsValidCharacter('+')); Assert.IsFalse(strategy.IsValidCharacter(Convert.ToChar(7))); //---------------Tear down ------------------------- }
public void Test_AddUpdateBoPropOnValueChangedHandler_WhenMapperUsingHabaneroControl_ShouldAddBehaviours() { //---------------Set up test pack------------------- var txt = new TextBoxWin { Name = "TestTextBox", Enabled = true }; var textBoxMapper = new TextBoxMapperStub(txt); //---------------Assert Precondition---------------- Assert.IsInstanceOf <ITextBox>(textBoxMapper.Control); //---------------Execute Test ---------------------- var comboBoxStrategyWin = new TextBoxMapperStrategyWin(); comboBoxStrategyWin.AddUpdateBoPropOnTextChangedHandler(textBoxMapper, GenerateStub <IBOProp>()); //---------------Assert Result---------------------- Assert.IsTrue(true, "If an error was not thrown then we are OK"); }
public void TestIsValidChar_WithDecimal_AddsZeroForDotAtStart() { //---------------Set up test pack------------------- TextBoxMapperStrategyWin strategy = (TextBoxMapperStrategyWin)GetControlFactory().CreateTextBoxMapperStrategy(); BOProp boProp = CreateBOPropForType(typeof(decimal)); strategy.AddKeyPressEventHandler(_mapper, boProp); _mapper.Control.Text = ""; TextBoxWin textBox = ((TextBoxWin)_mapper.Control); textBox.SelectionStart = 0; //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.IsFalse(strategy.IsValidCharacter('.')); Assert.AreEqual("0.", textBox.Text); Assert.AreEqual(2, textBox.SelectionStart); Assert.AreEqual(0, textBox.SelectionLength); //---------------Tear down ------------------------- }