public async Task VerifyMessageReturnedWhenMultipleGroupsNotFound()
        {
            var group1        = "Fake Group";
            var group2        = "Fake Group2";
            var groupListName = String.Join(Constant.ViolationDelimiter, new List <String> {
                group1, group2
            });

            var mockGroupRepo = new Mock <IGenericRepository <Group> >();
            FieldValueList <Group> resultingGroupList;
            var groupValidation = new ValidationGroup(new APIOptions(), mockGroupRepo.Object, x => resultingGroupList = x);

            var mockResult = new QueryResultSet <Group>
            {
                Success = true,
                Results = new List <Result <Group> >()
            };

            mockGroupRepo.Setup(x => x.Query(It.IsAny <Query <Group> >(), It.IsAny <Int32>())).Returns(mockResult);

            var expectedMessage = String.Format(Constant.Messages.Violations.GroupDoesNotExist, groupListName);
            var result          = await groupValidation.ValidateAsync(groupListName);

            Assert.AreEqual(expectedMessage, result);
        }
        public async Task VerifyCallbackPopulatesResultingGroup()
        {
            var groupArtifactID = 1234;
            var groupName       = "Existing Group";

            var mockGroupRepo = new Mock <IGenericRepository <Group> >();
            FieldValueList <Group> resultingGroupList = null;
            var groupValidation = new ValidationGroup(new APIOptions(), mockGroupRepo.Object, x => resultingGroupList = x);

            var mockResult = new QueryResultSet <Group>
            {
                Success = true,
                Results = new List <Result <Group> >
                {
                    new Result <Group>
                    {
                        Artifact = new Group(groupArtifactID)
                        {
                            Name = groupName
                        }
                    }
                }
            };

            mockGroupRepo.Setup(x => x.Query(It.IsAny <Query <Group> >(), It.IsAny <Int32>())).Returns(mockResult);

            await groupValidation.ValidateAsync(groupName);

            Assert.IsTrue(resultingGroupList != null);
            Assert.IsTrue(resultingGroupList.Count == mockResult.Results.Count);
            Assert.IsTrue(resultingGroupList[0].ArtifactID == groupArtifactID);
        }
        public async Task VerifyNullReturnWhenGroupExists()
        {
            var groupName = "Existing Group";

            var mockGroupRepo = new Mock <IGenericRepository <Group> >();
            FieldValueList <Group> resultingGroupList;
            var groupValidation = new ValidationGroup(new APIOptions(), mockGroupRepo.Object, x => resultingGroupList = x);

            var mockResult = new QueryResultSet <Group>
            {
                Success = true,
                Results = new List <Result <Group> >
                {
                    new Result <Group>
                    {
                        Artifact = new Group()
                        {
                            Name = groupName
                        }
                    }
                }
            };

            mockGroupRepo.Setup(x => x.Query(It.IsAny <Query <Group> >(), It.IsAny <Int32>())).Returns(mockResult);

            var result = await groupValidation.ValidateAsync(groupName);

            Assert.AreEqual(null, result);
        }
        public void Validate_NoProperties_ValidationSuccess()
        {
            // Arrange
            var group = new ValidationGroup();

            // Act
            var result = group.Validate();

            // Assert
            result.Should().BeTrue();
        }
Beispiel #5
0
        public void Add(string configID, DataType fieldType, string displayTab, ValidationGroup validationGroup = null, string accordionGroup = null, string uniqueId = "")
        {
            var mConfig = new ModuleConfiguration();

            mConfig.ConfigID          = configID;
            mConfig.FieldType         = fieldType;
            mConfig.TabHeader         = displayTab;
            mConfig.ValidationGroup   = validationGroup;
            mConfig.AccordionGroup    = accordionGroup;
            mConfig.ConfigurationItem = null;
            mConfig.UniqueId          = uniqueId;
            base.Add(mConfig);
        }
        protected override void Render(HtmlTextWriter writer)
        {
            if (DefaultButtonID.IsNotEmpty())
            {
                writer.AddAttribute("onkeyup", string.Format("defaultButtonClick('{0}', event)", DefaultButtonID));
            }

            writer.AddAttribute(HtmlTextWriterAttribute.Class, string.Format("{0}{1}{2}",
                                                                             CssClass.IsNotEmpty() ? CssClass : string.Empty,
                                                                             ValidationType != eValidationType.None ? " valid-" + ValidationType.ToString().ToLower() : string.Empty,
                                                                             ValidationGroup.IsNotEmpty() ? " group-" + ValidationGroup : string.Empty));
            base.Render(writer);
        }
        public PackageDimmsViewModel(IPackageService packageService, IPopupService popupService)
        {
            _packageService = packageService;
            _popupService   = popupService;

            SaveCommand  = new MvxCommand(SaveAction);
            ResetCommand = new MvxCommand(ResetAction);

            Barcode = new ValidatedProperty <string>().IsRequired();
            Width   = new ValidatedProperty <string>().IsRequired().IsDouble();
            Height  = new ValidatedProperty <string>().IsRequired().IsDouble();
            Depth   = new ValidatedProperty <string>().IsRequired().IsDouble();

            _validationGroup = new ValidationGroup(Barcode, Width, Height, Depth);
        }
Beispiel #8
0
        protected override void Render(HtmlTextWriter writer)
        {
            List <Control> iconAndTextControls = new List <Control>();

            if (this.Icon != null && this.IconPosition == Position.Left)
            {
                iconAndTextControls.Add(Icon);
            }

            iconAndTextControls.Add(new LiteralControl(this.Text));

            if (this.Icon != null && this.IconPosition == Position.Right)
            {
                iconAndTextControls.Add(Icon);
            }

            string onClick = "";

            if (Page != null)
            {
                if (CausesValidation || ValidationGroup.IsSet())
                {
                    PostBackOptions options = new PostBackOptions(this);
                    options.ValidationGroup   = this.ValidationGroup;
                    options.PerformValidation = true;
                    onClick = Page.ClientScript.GetPostBackEventReference(options, true);
                }
                else
                {
                    onClick = Page.ClientScript.GetPostBackClientHyperlink(this, "");
                }
            }

            writer.WriteHtmlElement(new HtmlElement(
                                        type: Type,
                                        attributes: new HtmlAttribute[] {
                new HtmlClassAttribute(CssClass, Size.ToRender(), CssStyle.ToRender()),
                new HtmlTypeAttribute("submit"),
                new HtmlNameAttribute(this.UniqueID),
                new HtmlAttribute("disabled", "disabled", !IsEnabled),
                new HtmlAttribute("data-toggle", "button", IsToggleable),
                new HtmlAttribute("onclick", onClick, !UseSubmitBehavior)
            },
                                        controls: iconAndTextControls.ToArray()
                                        ));
        }
        public void Validate_AllPropertiesValid_ValidationSuccess()
        {
            // Arrange
            var propertyOne = new ValidatedProperty <string>("5")
                              .IsRequired()
                              .IsDouble();

            var propertyTwo = new ValidatedProperty <string>("12")
                              .IsRequired()
                              .IsDouble();

            var group = new ValidationGroup(propertyOne, propertyTwo);

            // Act
            var result = group.Validate();

            // Assert
            result.Should().BeTrue();
        }
        public void Validate_AllPropertyInvalid_ValidationFailed()
        {
            // Arrange
            var propertyOne = new ValidatedProperty <string>().IsRequired();

            var propertyTwo = new ValidatedProperty <string>("qwerty")
                              .IsRequired()
                              .IsDouble();

            var group = new ValidationGroup(propertyOne, propertyTwo);

            // Act
            var result = group.Validate();

            // Assert
            using (new AssertionScope())
            {
                result.Should().BeFalse();
                propertyOne.Error.Should().Be(Strings.ValueIsMandatory);
                propertyTwo.Error.Should().Be(Strings.ValueHasIncorrectFormat);
            }
        }
Beispiel #11
0
        protected override void Render(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "btn-c" + (CssSpan.IsNotEmpty() ? " " + CssSpan : ""));
            writer.RenderBeginTag(HtmlTextWriterTag.Span);

            if (Href.IsNotEmpty() && Click != null)
            {
                throw new Exception("Href and Server Event can't be used together");
            }

            if (Click != null)
            {
                //Uncomment if POSTBACK is not rising
                //writer.AddAttribute(HtmlTextWriterAttribute.Name, ClientID);
                if (DisableValidation)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:" + Page.ClientScript.GetPostBackEventReference(this, ClientID));
                }
                else
                {
                    //Uncomment if POSTBACK is not rising
                    //writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:" + string.Format("__doPostBackJQ('{0}','{1}')", UniqueID, ClientID));
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:" + string.Format("__doPostBackJQ('{0}','')", UniqueID));
                }

                writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
            }
            else
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Href, Href.IsNotEmpty() ? Href : "javascript:void(0);");
            }

            if (OnClientClick.IsNotEmpty())
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, OnClientClick);
            }

            if (Rel.IsNotEmpty())
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Rel, Rel);
            }

            if (Target.IsNotEmpty())
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Target, Target);
            }

            if (CssStyle.IsNotEmpty())
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Style, CssStyle);
            }

            writer.AddAttribute(HtmlTextWriterAttribute.Class, string.Format("btn{0}{1}{2}{3}",
                                                                             Type != eType.None ? " btn-" + Type.ToString().ToLower() : string.Empty,
                                                                             Size != eSize.None ? " btn-" + Size.ToString().ToLower() : string.Empty,
                                                                             CssClass.IsNotEmpty() ? " " + CssClass : string.Empty,
                                                                             ValidationGroup.IsNotEmpty() ? " group-" + ValidationGroup : string.Empty));
            if (ID.IsNotEmpty())
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Id, ID);
            }

            IEnumerator keys = this.Attributes.Keys.GetEnumerator();

            while (keys.MoveNext())
            {
                var key = (String)keys.Current;
                writer.AddAttribute(key, this.Attributes[key]);
            }

            writer.RenderBeginTag(HtmlTextWriterTag.A);
            writer.Write(Text);
            writer.RenderEndTag(); // a

            writer.RenderEndTag(); // span
        }
Beispiel #12
0
        protected override void Render(HtmlTextWriter writer)
        {
            if (IsWrap)
            {
                var cssClassWrapDefault = TextMode == eTextMode.Multiline ? "textarea-wrap" : "input-wrap";
                writer.AddAttribute(HtmlTextWriterAttribute.Class, cssClassWrapDefault + (CssClassWrap.IsNotEmpty() ? " " + CssClassWrap : ""));
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
            }

            if (Placeholder.IsNotEmpty())
            {
                writer.AddAttribute("placeholder", Placeholder);
            }

            if (DefaultButtonID.IsNotEmpty())
            {
                writer.AddAttribute("onkeyup", string.Format("defaultButtonClick('{0}', event)", DefaultButtonID));
            }

            if (ReadOnly)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.ReadOnly, "readonly");
            }

            if (Disabled)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
            }

            if (MaxLength != 0)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Maxlength, MaxLength.ToString());
            }


            writer.AddAttribute(HtmlTextWriterAttribute.Id, ID);
            writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, string.Format("{0}{1}{2}",
                                                                             CssClass.IsNotEmpty() ? CssClass : string.Empty,
                                                                             ValidationType != eValidationType.None ? " valid-" + ValidationType.ToString().ToLower() : string.Empty,
                                                                             ValidationGroup.IsNotEmpty() ? " group-" + ValidationGroup : string.Empty));
            if (TextMode == eTextMode.Text || TextMode == eTextMode.Password)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Type, TextMode.ToString().ToLower());
            }

            if (TextMode == eTextMode.Multiline)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Textarea);
                writer.Write(Text);
            }
            else
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Value, Text ?? string.Empty);
                writer.RenderBeginTag(HtmlTextWriterTag.Input);
            }
            writer.RenderEndTag();


            if (IsWrap)
            {
                writer.RenderEndTag();
            }
        }