public void ValidateOpenCardDto_InValidCard_Errors()
        {
            // Arrange
            var dto = TestDataGenerator.GenerateFakeValidityCardDto();

            // Act
            var errors = _dtoValidationService.ValidateOpenCardDto(dto);

            // Assert
            Assert.Equal(2, errors.Count());
            Assert.Equal(1, errors.Count(a => a.FieldName == "type"));
            Assert.Equal(1, errors.Count(a => a.FieldName == "currency"));
            Assert.Equal("Card type is invalid", errors.First(a => a.FieldName == "type").Message);
            Assert.Equal("Currency is invalid", errors.First(a => a.FieldName == "currency").Message);
        }
        public ActionResult <CardGetDto> Post([FromBody] CardPostDto value)
        {
            // Validate
            var validateResult = _dtoValidationService.ValidateOpenCardDto(value);

            if (validateResult.HasErrors())
            {
                ModelState.AddErrors(validateResult);
            }

            if (!ModelState.IsValid)
            {
                _logger.LogStateWarning("This model is invalid.", ModelState);
                return(BadRequest(ModelState));
            }

            // Select
            var user = _userRepository.GetUser(User.Identity.Name, false);

            if (user == null)
            {
                return(Forbid());
            }

            var(card, openResult) = _bankService.TryOpenNewCard(
                user,
                value.Name,
                (Currency)value.Currency,
                (CardType)value.Type);

            if (openResult.HasErrors())
            {
                ModelState.AddErrors(openResult);
                _logger.LogStateError("Opening card was unsuccessfully.", ModelState);
                return(BadRequest(ModelState));
            }

            // Mapping
            var dto = _dtoFactory.Map(card, TryValidateModel);

            switch (dto)
            {
            // Validate
            case null:
                _logger.LogError("Opening card was unsuccessfully.");
                return(BadRequest("Не удалось выпустить карту"));

            default:
                return(Created($"/api/cards/{dto.Number}", dto));
            }
        }