public static ValidationResult <CreateNewStickerSet> CreateValidation(this CreateNewStickerSet value) => new ValidationResult <CreateNewStickerSet>(value).IsTrue(x => x.UserId < 1, ValidationErrors.IdLowerThanOne) .IsTrue(x => x.PngSticker == null && x.TgsSticker == null && x.WebmSticker == null, ValidationErrors.NonePropertySet) .IsTrue(x => x.PngSticker != null && x.TgsSticker != null || x.PngSticker != null && x.WebmSticker != null || x.TgsSticker != null && x.WebmSticker != null, ValidationErrors.OnlyOnePropertyCanBeSet) .ValidateRequired(x => x.UserId) .ValidateRequired(x => x.Name) .ValidateRequired(x => x.Title) .ValidateRequired(x => x.Emojis) .IsFalse(x => x.Name != null && x.Name.Contains("_by_"), ValidationErrors.InvalidStickerName);
public void TestValid() { var obj = new CreateNewStickerSet { UserId = 2, Emojis = "❤", Name = "StickerSet_by_BlaBot", Title = "Title", PngSticker = new InputFile("Path") }; Assert.That(obj.IsValid()); Assert.That(obj.Errors.Count, Is.EqualTo(0)); }
public void TestInvalid() { var obj = new CreateNewStickerSet(); Assert.False(obj.IsValid()); Assert.That(obj.Errors.Count, Is.EqualTo(6)); var errors = obj.Errors.Select(x => x.GetMessage) .ToList(); CollectionAssert.Contains(errors, "(PngSticker, TgsSticker, WebmSticker): \"One of these properties need to be set\""); CollectionAssert.Contains(errors, "(Name): \"Field is not set, but required\""); CollectionAssert.Contains(errors, "(UserId): \"ID lower than 1 is not allowed.\""); CollectionAssert.Contains(errors, "(Title): \"Field is not set, but required\""); CollectionAssert.Contains(errors, "(Emojis): \"Field is not set, but required\""); CollectionAssert.Contains(errors, "(Name): \"Stickersets Created by bots need to end with _by_<botname> \""); }