示例#1
0
        public void ValidateIdUsingExpression_InvalidValue_HasError(string id)
        {
            var fixture = new Fixture();
            var datum   = fixture.Build <PatchDTO.Datum>().With(x => x.Id, id).Create();
            var dto     = fixture.Build <PatchDTO>().With(x => x.Data, new List <PatchDTO.Datum> {
                datum
            }).Create();

            var validator = new PatchDTOValidator();

            var validationResult = validator.TestValidate(dto);

            validationResult.ShouldHaveValidationErrorFor(x => x.Data[0].Id)
            .WithErrorMessage("Invalid 'Data.Id' value");
        }
示例#2
0
        public void ValidateIdUsingString_InvalidValue_HasError(string id)
        {
            var fixture = new Fixture();
            var datum   = fixture.Build <PatchDTO.Datum>().With(x => x.Id, id).Create();
            var dto     = fixture.Build <PatchDTO>().With(x => x.Data, new List <PatchDTO.Datum> {
                datum
            }).Create();

            var validator = new PatchDTOValidator();

            var validationResult = validator.TestValidate(dto);

            validationResult.ShouldHaveValidationErrorFor("Data[0].Id")
            .WithErrorMessage("Invalid 'Data.Id' value");

            Console.WriteLine(string.Join(Environment.NewLine, validationResult.Errors.Select(JsonConvert.SerializeObject)));
        }