public void ValidatesDeckIdTest() { using DbContext context = CreateContext(); CardCommitValidator validator = new CardCommitValidator(context); Card card = new Card() { CardTemplateId = 1, CardId = 1 }; card.Fields.Add(new CardField() { CardId = 1, FieldName = "TestField", Value = "test" }); //not successful string error = validator.Validate(card); Assert.IsFalse(string.IsNullOrEmpty(error)); //successful card.DeckId = 1; error = validator.Validate(card); Assert.IsTrue(string.IsNullOrEmpty(error)); }
public void ValidatesFieldValueTest() { using DbContext context = CreateContext(); CardCommitValidator validator = new CardCommitValidator(context); Card card = new Card() { CardTemplateId = 1, CardId = 1, DeckId = 1 }; card.Fields.Add(new CardField() { CardId = 1, FieldName = "TestField1", CardFieldDefinition = new CardFieldDefinition() { IsRequired = true } }); card.Fields.Add(new CardField() { CardId = 1, FieldName = "TestField2", CardFieldDefinition = new CardFieldDefinition() { IsRequired = false } }); //not successful string error = validator.Validate(card); Assert.IsFalse(string.IsNullOrEmpty(error)); //successful card.Fields[0].Value = "test"; error = validator.Validate(card); Assert.IsTrue(string.IsNullOrEmpty(error)); }