public void TestExecuteWhenPropertyValidationReturnsContainsErrorsReturnsFailureResult() { var propData = new Mock <IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.Name).Returns("MyProperty"); propData.Setup(p => p.GetComboBoxItems()).Returns(new List <ComboBoxItem>()); var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetElement("myproperty")).Returns(propData.Object); var comboBoxAction = new ValidateComboBoxAction { ElementLocator = locator.Object }; var expectedItems = new List <ComboBoxItem> { new ComboBoxItem { Text = "Item 1", Value = "1" } }; var context = new ValidateComboBoxAction.ValidateComboBoxContext("myproperty", ComboComparisonType.Contains, expectedItems, true, true); var result = comboBoxAction.Execute(context); Assert.AreEqual(false, result.Success); Assert.AreEqual("Combo box validation of field 'MyProperty' failed. Expected items that do not exist: Item 1", result.Exception.Message); locator.VerifyAll(); propData.VerifyAll(); }
public void TestExecuteWhenPropertyIsNotAComboBoxReturnsFailureResult() { var propData = new Mock <IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.Name).Returns("MyProperty"); propData.Setup(p => p.GetComboBoxItems()).Returns((List <ComboBoxItem>)null); var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetElement("myproperty")).Returns(propData.Object); var comboBoxAction = new ValidateComboBoxAction { ElementLocator = locator.Object }; var context = new ValidateComboBoxAction.ValidateComboBoxContext("myproperty", ComboComparisonType.Contains, new List <ComboBoxItem>(), true, true); var result = comboBoxAction.Execute(context); Assert.AreEqual(false, result.Success); Assert.AreEqual("Property 'MyProperty' was found but is not a combo box element.", result.Exception.Message); locator.VerifyAll(); propData.VerifyAll(); }
public void TestExecuteWhenPropertyValidationIgnoresTextReturnsASuccess() { var mockItem = new ComboBoxItem { Text = "Item", Value = "1" }; var propData = new Mock <IPropertyData>(MockBehavior.Strict); propData.Setup(p => p.GetComboBoxItems()).Returns(new List <ComboBoxItem> { mockItem }); var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetElement("myproperty")).Returns(propData.Object); var comboBoxAction = new ValidateComboBoxAction { ElementLocator = locator.Object }; var mockExpectedItem = new ComboBoxItem { Text = "Item 1", Value = "1" }; var context = new ValidateComboBoxAction.ValidateComboBoxContext("myproperty", ComboComparisonType.Contains, new List <ComboBoxItem> { mockExpectedItem }, false, true); var result = comboBoxAction.Execute(context); Assert.AreEqual(true, result.Success); locator.VerifyAll(); propData.VerifyAll(); }
public void TestExecuteWhenFieldDoesNotExistThrowsAnException() { var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetElement("doesnotexist")).Throws(new ElementExecuteException("Cannot find item")); var comboBoxAction = new ValidateComboBoxAction { ElementLocator = locator.Object }; var context = new ValidateComboBoxAction.ValidateComboBoxContext("doesnotexist", ComboComparisonType.Contains, new List <ComboBoxItem>(), true, true); ExceptionHelper.SetupForException <ElementExecuteException>( () => comboBoxAction.Execute(context), e => locator.VerifyAll()); }
public void TestGetActionName() { var comboBoxAction = new ValidateComboBoxAction(); Assert.AreEqual("ValidateComboBoxAction", comboBoxAction.Name); }