public void TestExecuteWhenPropertyIsNotAListReturnsFailureResult() { var propData = new Mock <IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.IsList).Returns(false); propData.SetupGet(p => p.Name).Returns("MyProperty"); var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("myproperty")).Returns(propData.Object); var buttonClickAction = new ValidateListAction { ElementLocator = locator.Object }; var context = new ValidateListAction.ValidateListContext("myproperty", ComparisonType.Equals, new ValidationTable()); var result = buttonClickAction.Execute(context); Assert.AreEqual(false, result.Success); Assert.AreEqual("Property 'MyProperty' was found but is not a list element.", result.Exception.Message); locator.VerifyAll(); propData.VerifyAll(); }
public void TestExecuteWhenFieldDoesNotExistThrowsAnException() { var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("doesnotexist")).Throws(new ElementExecuteException("Cannot find item")); var buttonClickAction = new ValidateListAction { ElementLocator = locator.Object }; var context = new ValidateListAction.ValidateListContext("doesnotexist", ComparisonType.Equals, new ValidationTable()); ExceptionHelper.SetupForException<ElementExecuteException>( () => buttonClickAction.Execute(context), e => locator.VerifyAll()); }
public void TestExecuteWhenFieldDoesNotExistThrowsAnException() { var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("doesnotexist")).Throws(new ElementExecuteException("Cannot find item")); var buttonClickAction = new ValidateListAction { ElementLocator = locator.Object }; var context = new ValidateListAction.ValidateListContext("doesnotexist", ComparisonType.Equals, new ValidationTable()); ExceptionHelper.SetupForException <ElementExecuteException>( () => buttonClickAction.Execute(context), e => locator.VerifyAll()); }
public void TestExecuteWhenPropertyValidationReturnsErrorsReturnsFailureResult() { var table = new ValidationTable(); table.AddValidation("name", "Hello", "equals"); table.Process(); var itemResult = new ValidationItemResult(); itemResult.NoteValidationResult(table.Validations.First(), false, "World"); var validationResult = new ValidationResult(table.Validations) { IsValid = false, ItemCount = 1 }; validationResult.CheckedItems.Add(itemResult); var propData = new Mock <IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.IsList).Returns(true); propData.SetupGet(p => p.Name).Returns("MyProperty"); propData.Setup(p => p.ValidateList(ComparisonType.Equals, It.Is <ICollection <ItemValidation> >(c => c.Count == 1))).Returns(validationResult); var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("myproperty")).Returns(propData.Object); var buttonClickAction = new ValidateListAction { ElementLocator = locator.Object }; var context = new ValidateListAction.ValidateListContext("myproperty", ComparisonType.Equals, table); var result = buttonClickAction.Execute(context); Assert.AreEqual(false, result.Success); Assert.IsNotNull(result.Exception); locator.VerifyAll(); propData.VerifyAll(); }
public void TestExecuteWhenPropertyIsNotAListReturnsFailureResult() { var propData = new Mock<IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.IsList).Returns(false); propData.SetupGet(p => p.Name).Returns("MyProperty"); var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("myproperty")).Returns(propData.Object); var buttonClickAction = new ValidateListAction { ElementLocator = locator.Object }; var context = new ValidateListAction.ValidateListContext("myproperty", ComparisonType.Equals, new ValidationTable()); var result = buttonClickAction.Execute(context); Assert.AreEqual(false, result.Success); Assert.AreEqual("Property 'MyProperty' was found but is not a list element.", result.Exception.Message); locator.VerifyAll(); propData.VerifyAll(); }
public void TestGetActionName() { var buttonClickAction = new ValidateListAction(); Assert.AreEqual("ValidateListAction", buttonClickAction.Name); }
public void TestExecuteWhenPropertyValidationReturnsErrorsReturnsFailureResult() { var table = new ValidationTable(); table.AddValidation("name", "Hello", "equals"); table.Process(); var itemResult = new ValidationItemResult(); itemResult.NoteValidationResult(table.Validations.First(), false, "World"); var validationResult = new ValidationResult(table.Validations) { IsValid = false, ItemCount = 1 }; validationResult.CheckedItems.Add(itemResult); var propData = new Mock<IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.IsList).Returns(true); propData.SetupGet(p => p.Name).Returns("MyProperty"); propData.Setup(p => p.ValidateList(ComparisonType.Equals, It.Is<ICollection<ItemValidation>>(c => c.Count == 1))).Returns(validationResult); var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetProperty("myproperty")).Returns(propData.Object); var buttonClickAction = new ValidateListAction { ElementLocator = locator.Object }; var context = new ValidateListAction.ValidateListContext("myproperty", ComparisonType.Equals, table); var result = buttonClickAction.Execute(context); Assert.AreEqual(false, result.Success); Assert.IsNotNull(result.Exception); locator.VerifyAll(); propData.VerifyAll(); }
public void TestGetActionName() { var buttonClickAction = new ValidateListAction(); Assert.AreEqual("ValidateListAction", buttonClickAction.Name); }