コード例 #1
0
        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();
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        public void ThenISeeListStep(string fieldName, string rule, Table data)
        {
            if (data == null || data.RowCount == 0)
            {
                return;
            }

            ComparisonType comparisonType;

            switch (rule.ToLookupKey())
            {
            case "exists":
            case "contains":
                comparisonType = ComparisonType.Contains;
                break;

            case "doesnotexist":
            case "doesnotcontain":
                comparisonType = ComparisonType.DoesNotContain;
                break;

            case "startswith":
                comparisonType = ComparisonType.StartsWith;
                break;

            case "endswith":
                comparisonType = ComparisonType.EndsWith;
                break;

            case "equals":
                comparisonType = ComparisonType.Equals;
                break;

            default:
                throw new InvalidOperationException(string.Format("Rule type '{0}' is not supported.", rule));
            }

            var page        = this.GetPageFromContext();
            var validations = data.ToValidationTable();

            var context = new ValidateListAction.ValidateListContext(fieldName.ToLookupKey(), comparisonType, validations);

            this.actionPipelineService.PerformAction <ValidateListAction>(page, context).CheckResult();
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
        }
コード例 #8
0
ファイル: DataSteps.cs プロジェクト: DavidPx/specbind
        public void ThenISeeListStep(string fieldName, string rule, Table data)
        {
            if (data == null || data.RowCount == 0)
            {
                return;
            }

            ComparisonType comparisonType;
            switch (rule.ToLookupKey())
            {
                case "exists":
                case "contains":
                    comparisonType = ComparisonType.Contains;
                    break;

                case "doesnotexist":
                case "doesnotcontain":
                    comparisonType = ComparisonType.DoesNotContain;
                    break;

                case "startswith":
                    comparisonType = ComparisonType.StartsWith;
                    break;

                case "endswith":
                    comparisonType = ComparisonType.EndsWith;
                    break;
                case "equals":
                    comparisonType = ComparisonType.Equals;
                    break;
                default:
                    throw new InvalidOperationException(string.Format("Rule type '{0}' is not supported.", rule));
            }

            var page = this.GetPageFromContext();
            var validations = data.ToValidationTable();

            var context = new ValidateListAction.ValidateListContext(fieldName.ToLookupKey(), comparisonType, validations);
            this.actionPipelineService.PerformAction<ValidateListAction>(page, context).CheckResult();
        }