Beispiel #1
0
        public void BookCommandTest()
        {
            var cmd = new CreateBookCmd()
            {
                Name          = "Уход за крысами",
                Genres        = new int[] { 2 },
                Authors       = new int[] { 2 },
                HasElectronic = false,
                Published     = 5018
            };

            var res = cmd.Validate(out IEnumerable <ValidationResult> errors);

            Assert.IsFalse(res);
            Assert.AreEqual(3, errors.Count());

            cmd.Published = DateTime.Now.Year - 1;

            Result result;

            result = _cqService.Process(cmd);
            Assert.IsTrue(result.IsSuccess);
            //Console.WriteLine(result.Return(r => r.ToString(), r => r.ToString()));

            result = _cqService.Process(cmd);
            Assert.IsFalse(result.IsSuccess);
            //Console.WriteLine(result.Return(r => r.ToString(), r => r.ToString()));
        }
Beispiel #2
0
        public void AttrValidatorTest()
        {
            CreateBookCmd cmd = new CreateBookCmd()
            {
                Name          = "   ",
                Genres        = new int[] { 4 },
                HasElectronic = true,
                Published     = DateTime.Now.Year + 10,
                Authors       = new int[] { 4 }
            };
            var res = cmd.Validate(out IEnumerable <ValidationResult> errors);

            foreach (var e in errors)
            {
                Debug.WriteLine(e.ErrorMessage);
            }
            Assert.IsFalse(res);
            Assert.AreEqual(2, errors.Count());
        }
Beispiel #3
0
 //public IActionResult CreatePost([FromForm] BibliotecaAdmApp.Application.Books.Dto.BookDto bookDto)
 public async Task <ActionResult <int> > CreatePost(CreateBookCmd cmd)
 {
     //return RedirectToAction(nameof(FindAll));
     return(await Mediator.Send(cmd));
 }