public void ValidateTest() { CardFieldValueValidator validator = new CardFieldValueValidator(); CardField field = new CardField { CardFieldDefinition = new CardFieldDefinition() { IsRequired = false } }; string error = validator.Validate(field, null); Assert.IsTrue(string.IsNullOrEmpty(error)); error = validator.Validate(field, ""); Assert.IsTrue(string.IsNullOrEmpty(error)); field.CardFieldDefinition.IsRequired = true; error = validator.Validate(field, null); Assert.IsFalse(string.IsNullOrEmpty(error)); error = validator.Validate(field, ""); Assert.IsFalse(string.IsNullOrEmpty(error)); error = validator.Validate(field, "test"); Assert.IsTrue(string.IsNullOrEmpty(error)); }
///<inheritdoc/> public override string Validate(Card entity) { string error = new CardCardTemplateIdValidator().Validate(entity, entity.CardTemplateId); if (!string.IsNullOrEmpty(error)) { return(error); } error = new CardDeckIdValidator().Validate(entity, entity.DeckId); if (!string.IsNullOrEmpty(error)) { return(error); } CardFieldValueValidator fieldValidator = new CardFieldValueValidator(); foreach (CardField field in entity.Fields) { error = fieldValidator.Validate(field, field.Value); if (!string.IsNullOrEmpty(error)) { return(error); } } return(null); }