public void Validate_Fails_When_The_Name_Is_Missing()
        {
            var model = new ProviderViewModel
            {
                ApiKey = "key",
                ApiUrl = "https://no.where"
            };

            var results = _validator.Validate(model);

            Assert.False(results.IsValid);
            Assert.Contains(results.Errors, e => e.ErrorMessage == "Provider name cannot be blank.");
        }
Exemple #2
0
        public async Task <string> AddProviders(ProviderDTO provider)
        {
            var x = _mapper.Map <ProviderDTO, Provider>(provider);

            ProviderValidator validator = new ProviderValidator();

            ValidationResult results = validator.Validate(x);

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    string error = ("Property " + failure.PropertyName + " failed validation. Error was: " + failure.ErrorMessage);
                    return(error);
                }
                return("Error");
            }
            else
            {
                await _eFUnitOfWork.EFProviderRepository.Add(x);

                return("Постачальника успішно добавлено!");
            }
        }