Ejemplo n.º 1
0
        /// <summary>
        /// Performs the validation.
        /// </summary>
        /// <param name="validations">The validations.</param>
        /// <param name="validationProcess">The validation process for an item.</param>
        /// <returns>The result of the action.</returns>
        public static ActionResult PerformValidation(IReadOnlyCollection<ItemValidation> validations, Func<ItemValidation, ValidationItemResult, bool> validationProcess)
        {
            var itemResult = new ValidationItemResult();
            var result = new ValidationResult(validations) { IsValid = true };
            result.CheckedItems.Add(itemResult);

            foreach (var validation in validations)
            {
                var successful = validationProcess(validation, itemResult);
                if (!successful)
                {
                    result.IsValid = false;
                }
            }

            if (!result.IsValid)
            {
                return ActionResult.Failure(new ElementExecuteException(
                    "Value comparison(s) failed. See details for validation results.{0}{1}",
                    Environment.NewLine,
                    result.GetComparisonTableByRule()));
            }

            return ActionResult.Successful();
        }
Ejemplo n.º 2
0
		public void TestGetComparisonTableByRuleWithInvalidFieldValue()
		{
            var validation = ItemValidationHelper.Create("MyField", "Something");
			var validationResult = new ValidationResult(new[] { validation });

			var itemResult = new ValidationItemResult();
			itemResult.NoteValidationResult(validation, false, "Nothing");

			validationResult.CheckedItems.Add(itemResult);

			var result = validationResult.GetComparisonTableByRule();

			var expectedTable = new StringBuilder()
										.AppendLine("| Field   | Rule   | Value               |")
											.Append("| MyField | equals | Something [Nothing] |");

			Assert.AreEqual(expectedTable.ToString(), result);
		}
Ejemplo n.º 3
0
		public void TestGetComparisonTableWithMissingFields()
		{
            var validation = ItemValidationHelper.Create("MyField", "Something");
			var validationResult = new ValidationResult(new[] { validation });

			var itemResult = new ValidationItemResult();
			itemResult.NoteMissingProperty(validation);

			validationResult.CheckedItems.Add(itemResult);

			var result = validationResult.GetComparisonTable();

			var expectedTable = new StringBuilder()
										.AppendLine("| MyField equals Something |")
											.Append("| <NOT FOUND>              |");

			Assert.AreEqual(expectedTable.ToString(), result);
		}
        public void TestExecuteWhenPropertyValidationReturnsErrorsReturnsFailureResult()
        {
            var table = new ValidationTable();
            table.AddValidation("name", "Hello", "equals");
            
            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.FindItemInList(It.IsAny<ICollection<ItemValidation>>()))
                    .Returns(new Tuple<IPage, ValidationResult>(null, validationResult));

            var locator = new Mock<IElementLocator>(MockBehavior.Strict);
            locator.Setup(p => p.GetProperty("myproperty")).Returns(propData.Object);

            var buttonClickAction = new GetListItemByCriteriaAction
            {
                ElementLocator = locator.Object
            };

            var context = new GetListItemByCriteriaAction.ListItemByCriteriaContext("myproperty", table);
            var result = buttonClickAction.Execute(context);

            Assert.AreEqual(false, result.Success);
            Assert.IsNotNull(result.Exception);

            locator.VerifyAll();
            propData.VerifyAll();
        }
Ejemplo n.º 5
0
        public void TestExecuteWhenPropertyValidationReturnsSuccessReturnsASuccess()
        {
            var table = new ValidationTable();
            table.AddValidation("name", "Hello", "equals");
            table.Process();

            var itemResult = new ValidationItemResult();
            itemResult.NoteValidationResult(table.Validations.First(), true, "World");

            var validationResult = new ValidationResult(table.Validations) { IsValid = true, ItemCount = 1 };
            validationResult.CheckedItems.Add(itemResult);

            var propData = new Mock<IPropertyData>(MockBehavior.Strict);
            propData.SetupGet(p => p.IsList).Returns(true);
            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(true, result.Success);

            locator.VerifyAll();
            propData.VerifyAll();
        }
Ejemplo n.º 6
0
		/// <summary>
		/// Checks the field exists.
		/// </summary>
		/// <param name="propertyResult">The property result.</param>
		/// <returns>The validation result.</returns>
		private static Tuple<bool, string> CheckFieldExists(ValidationItemResult.PropertyResult propertyResult)
		{
			return propertyResult.FieldExists ? null : new Tuple<bool, string>(false, "Not Found");
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Checks the field value.
		/// </summary>
		/// <param name="propertyResult">The property result.</param>
		/// <returns>The validation result.</returns>
		private static Tuple<bool, string> CheckFieldValue(ValidationItemResult.PropertyResult propertyResult)
		{
			return propertyResult.FieldExists ? new Tuple<bool, string>(propertyResult.IsValid, propertyResult.ActualValue) : null;
		}