public void TestExecuteWhenFieldDoesNotExistReturnsFailure() { IPropertyData propertyData; var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.TryGetProperty("doesnotexist", out propertyData)).Returns(false); var validateItemAction = new ValidateItemAction { ElementLocator = locator.Object }; var table = new ValidationTable(); table.AddValidation("doesnotexist", "My Data", "equals"); table.Process(); var context = new ValidateItemAction.ValidateItemContext(table); var result = validateItemAction.Execute(context); Assert.AreEqual(false, result.Success); Assert.IsNotNull(result.Exception); StringAssert.Contains(result.Exception.Message, "doesnotexist"); locator.VerifyAll(); }
public void TestExecuteWhenFieldExistsAndIsValidReturnsSuccess() { var table = new ValidationTable(); table.AddValidation("name", "My Data", "equals"); table.Process(); var propData = new Mock<IPropertyData>(MockBehavior.Strict); string actualValue; propData.Setup(p => p.ValidateItem(table.Validations.First(), out actualValue)).Returns(true); // ReSharper disable once RedundantAssignment var propertyData = propData.Object; var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.TryGetProperty("name", out propertyData)).Returns(true); var validateItemAction = new ValidateItemAction { ElementLocator = locator.Object }; var context = new ValidateItemAction.ValidateItemContext(table); var result = validateItemAction.Execute(context); Assert.AreEqual(true, result.Success); locator.VerifyAll(); }
public void TestExecuteWhenFieldDoesNotExistAndIsDoesNotExistComparerReturnsSuccess() { IPropertyData propertyData; var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.TryGetProperty("pdoesnotexist", out propertyData)).Returns(false); var validateItemAction = new ValidateItemAction { ElementLocator = locator.Object }; var table = new ValidationTable(); table.AddValidation("pdoesnotexist", "My Data", "doesnotexist"); table.Process(new DoesNotExistComparer()); var context = new ValidateItemAction.ValidateItemContext(table); var result = validateItemAction.Execute(context); Assert.AreEqual(true, result.Success); 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 TestRetryValidationUntilTimeoutWithNoSuccessBeforeTimeout() { try { ValidateItemAction.RetryValidationUntilTimeout = true; ActionBase.DefaultTimeout = System.TimeSpan.FromMilliseconds(300); // NOTE: interval between checks is 200ms var table = new ValidationTable(); table.AddValidation("name", "My Data", "equals"); table.Process(); var propData = new Mock<IPropertyData>(MockBehavior.Strict); string actualValue; propData.SetupSequence(p => p.ValidateItem(table.Validations.First(), out actualValue)) .Returns(false) .Returns(false) // after 200ms .Returns(true); // after 400ms -- too late var propertyData = propData.Object; var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.TryGetProperty("name", out propertyData)).Returns(true); var validateItemAction = new ValidateItemAction { ElementLocator = locator.Object }; var context = new ValidateItemAction.ValidateItemContext(table); var result = validateItemAction.Execute(context); Assert.IsFalse(result.Success); locator.VerifyAll(); } finally { ValidateItemAction.RetryValidationUntilTimeout = false; ActionBase.DefaultTimeout = System.TimeSpan.FromSeconds(5); } }