public void TestActionWhenContextIsATableButHasBadRuleProcessesActions()
        {
            var action = new Mock <IAction>(MockBehavior.Strict);
            var items = new List <IValidationComparer> {
                new StartsWithComparer(), new EqualsComparer()
            }.AsReadOnly();

            var actionRepository = new Mock <IActionRepository>(MockBehavior.Strict);

            actionRepository.Setup(a => a.GetComparisonTypes()).Returns(items);

            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);

            var preAction = new ValidationTablePreAction(actionRepository.Object, tokenManager.Object);

            var table = new ValidationTable();

            table.AddValidation("My Field", "bad rule", "foo");

            var context = new TableContext(table);

            try
            {
                preAction.PerformPreAction(action.Object, context);
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(ElementExecuteException));
                Assert.AreEqual("Vaidation Rule could not be found for rule name: bad rule", e.Message);
            }

            action.VerifyAll();
            actionRepository.VerifyAll();
            tokenManager.VerifyAll();
        }
        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 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 TestExecuteWhenFieldExistsButIsNotValidReturnsFailure()
        {
            var table = new ValidationTable();

            table.AddValidation("name", "equals", "wrong");
            table.Process();

            var    propData = new Mock <IPropertyData>(MockBehavior.Strict);
            string actualValue;

            propData.Setup(p => p.ValidateItem(table.Validations.First(), out actualValue)).Returns(false);

            // 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(false, result.Success);
            Assert.IsNotNull(result.Exception);
            StringAssert.Contains(result.Exception.Message, "wrong");

            locator.VerifyAll();
        }
        public void TestExecuteWhenPropertyContainsMatchingItemReturnsSuccessful()
        {
            var table = new ValidationTable();

            table.AddValidation("name", "Hello", "equals");

            var page = new Mock <IPage>();

            var propData = new Mock <IPropertyData>(MockBehavior.Strict);

            propData.SetupGet(p => p.IsList).Returns(true);
            propData.Setup(p => p.FindItemInList(It.IsAny <ICollection <ItemValidation> >()))
            .Returns(new Tuple <IPage, ValidationResult>(page.Object, null));

            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(true, result.Success);
            Assert.AreSame(page.Object, result.Result);

            locator.VerifyAll();
            propData.VerifyAll();
        }
Esempio n. 6
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ValidateTokenActionContext" /> class.
            /// </summary>
            /// <param name="tokenName">Name of the token.</param>
            /// <param name="comparisonType">Type of the comparison.</param>
            /// <param name="comparisonValue">The comparison value.</param>
            public ValidateTokenActionContext(string tokenName, string comparisonType, string comparisonValue)
                : base(null)
            {
                var table = new ValidationTable();

                table.AddValidation(tokenName, comparisonType, comparisonValue);

                this.ValidationTable = table;
            }
Esempio n. 7
0
        /// <summary>
        /// Processes the specified validation.
        /// </summary>
        /// <param name="table">The validation table.</param>
        /// <param name="comparer">The optional comparer, uses equals by default.</param>
        /// <returns>The configured table, same object reference.</returns>
        public static ValidationTable Process(this ValidationTable table, IValidationComparer comparer = null)
        {
            foreach (var validation in table.Validations)
            {
                validation.Process(comparer);
            }

            return(table);
        }
        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);
            }
        }
        public void TestActionWhenContextIsATableProcessesActions()
        {
            var action = new Mock <IAction>(MockBehavior.Strict);
            var items = new List <IValidationComparer> {
                new StartsWithComparer()
            }.AsReadOnly();

            var actionRepository = new Mock <IActionRepository>(MockBehavior.Strict);

            actionRepository.Setup(a => a.GetComparisonTypes()).Returns(items);

            var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict);

            tokenManager.Setup(t => t.GetToken("foo")).Returns("foo");

            var preAction = new ValidationTablePreAction(actionRepository.Object, tokenManager.Object);

            var table = new ValidationTable();

            table.AddValidation("My Field", "starts with", "foo");

            var context = new TableContext(table);

            preAction.PerformPreAction(action.Object, context);

            var validation = table.Validations.First();

            Assert.AreEqual("myfield", validation.FieldName);
            Assert.AreEqual("foo", validation.ComparisonValue);
            Assert.IsNotNull(validation.Comparer);
            Assert.IsInstanceOfType(validation.Comparer, typeof(StartsWithComparer));

            action.VerifyAll();
            actionRepository.VerifyAll();
            tokenManager.VerifyAll();
        }
        /// <summary>
        /// Converts the SpecFlow table to a validation table. This expects a field, rule, and value column.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <returns>The created validation table.</returns>
        /// <exception cref="ElementExecuteException">A table must be specified for this step with the columns 'Field', 'Rule' and 'Value'</exception>
        public static ValidationTable ToValidationTable(this Table table)
        {
            string fieldHeader = null;
            string valueHeader = null;
            string ruleHeader  = null;

            if (table != null)
            {
                fieldHeader = table.Header.FirstOrDefault(h => h.NormalizedEquals("Field"));
                valueHeader = table.Header.FirstOrDefault(h => h.NormalizedEquals("Value"));
                ruleHeader  = table.Header.FirstOrDefault(h => h.NormalizedEquals("Rule"));
            }

            if (fieldHeader == null || valueHeader == null || ruleHeader == null)
            {
                throw new ElementExecuteException("A table must be specified for this step with the columns 'Field', 'Rule' and 'Value'");
            }

            if (table.RowCount == 0)
            {
                throw new ElementExecuteException("The validation table must contain at least one validation row.");
            }

            var validationTable = new ValidationTable();

            foreach (var tableRow in table.Rows)
            {
                var fieldName       = tableRow[fieldHeader];
                var comparisonValue = tableRow[valueHeader];
                var ruleValue       = tableRow[ruleHeader];

                validationTable.AddValidation(fieldName, ruleValue, comparisonValue);
            }

            return(validationTable);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TableContext"/> class.
 /// </summary>
 /// <param name="table">The validation table.</param>
 public TableContext(ValidationTable table)
     : base(null)
 {
     this.ValidationTable = table;
 }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidateListContext"/> class.
 /// </summary>
 /// <param name="propertyName">Name of the property.</param>
 /// <param name="compareType">Type of the compare.</param>
 /// <param name="validations">The validations.</param>
 public ValidateListContext(string propertyName, ComparisonType compareType, ValidationTable validations)
     : base(propertyName)
 {
     this.CompareType     = compareType;
     this.ValidationTable = validations;
 }
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidateItemContext" /> class.
 /// </summary>
 /// <param name="validationTable">The validation table.</param>
 public ValidateItemContext(ValidationTable validationTable)
     : base(null)
 {
     this.ValidationTable = validationTable;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ActionContext" /> class.
 /// </summary>
 /// <param name="listName">Name of the list.</param>
 /// <param name="validationTable">The validation table.</param>
 public ListItemByCriteriaContext(string listName, ValidationTable validationTable)
     : base(listName)
 {
     this.ValidationTable = validationTable;
 }
Esempio n. 16
0
        }//End

        public static string SendScriptMailUtility(ValidationTable validationtable)
        {
            string msg = string.Empty;

            string UserName              = validationtable.username;
            string IPAddress             = validationtable.ipaddress;
            string Contractorclose_idVal = validationtable.contractorclose_id;
            string Contractor_idVal      = validationtable.contractor_id;
            string LocationVal           = validationtable.location;
            string MarketVal             = validationtable.market;
            string SitenameVal           = validationtable.sitename;
            string ProjecttypeVal        = validationtable.projecttype;
            string ContractorVal         = validationtable.contractor;
            string ProjectstatusVal      = validationtable.projectstatus;
            string StatusTypeVal         = validationtable.statustype;
            string scripttype            = validationtable.scripttype;

            int action_id = 0;

            if (StatusTypeVal == "Start")
            {
                action_id = 15;
            }
            else
            {
                action_id = 16;
            }

            string       strQuery = "SELECT * FROM `emailutilityformattbl` WHERE `action_id`=" + action_id;
            MySqlCommand cmd1     = new MySqlCommand(strQuery);
            DataTable    actionDt = IncludeDataTables.DataTables.GetData(cmd1);
            string       subject  = string.Empty;

            foreach (DataRow dr in actionDt.Rows)
            {
                subject = dr["subject"].ToString();
            }

            string start_time = DateTime.Now.ToString("yyyy-MM-dd H:mm:ss");

            string body = "Find the below details of " + StatusTypeVal.ToLower() + " script :- <br/><br/>";

            body = body + "<table border='0'>" +
                   "<tr>" +
                   "<td>Script Type</td>" +
                   "<td> : " + scripttype + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>User By</td>" +
                   "<td> : " + UserName + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>IP Address</td>" +
                   "<td> : " + IPAddress + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>Start Time</td>" +
                   "<td> : " + start_time + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>Contractorclose_id</td>" +
                   "<td> : " + Contractorclose_idVal + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>Contractor_id</td>" +
                   "<td> : " + Contractor_idVal + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>Location</td>" +
                   "<td> : " + LocationVal + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>Market</td>" +
                   "<td> : " + MarketVal + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>Sitename</td>" +
                   "<td> : " + SitenameVal + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>Projecttype</td>" +
                   "<td> : " + ProjecttypeVal + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>Contractor</td>" +
                   "<td> : " + ContractorVal + "</td>" +
                   "</tr>" +
                   "<tr>" +
                   "<td>Project status</td>" +
                   "<td> : " + ProjectstatusVal + "</td>" +
                   "</tr>" +
                   "</tr>" +
                   "</table>";

            SendStatusMail(body, subject);

            return(msg);
        }