Esempio n. 1
1
        public void ThenISeeStep(Table data)
        {
            var validations = data.ToValidationTable();
            var page = this.GetPageFromContext();

            var context = new ValidateItemAction.ValidateItemContext(validations);
            this.actionPipelineService.PerformAction<ValidateItemAction>(page, context).CheckResult();
        }
        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 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 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 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();
        }
Esempio n. 6
0
        public void ThenISeeStep(Table data)
        {
            var validations = data.ToValidationTable();
            var page        = this.GetPageFromContext();

            var context = new ValidateItemAction.ValidateItemContext(validations);

            this.actionPipelineService.PerformAction <ValidateItemAction>(page, context).CheckResult();
        }
        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 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 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 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);
			}
		}