public void CreatePersonShouldCallRepository() { var person = this.GetDefaultPerson(); var personRepository = Substitute.For <PersonRepository>(); var personService = new PersonServiceImpl(personRepository); personService.CreatePerson(person); personRepository.Received().Create(person); }
public override async Task <IEnumerable <ValidationResult> > ValidateAsync(ValidationContext validationContext, CancellationToken cancellation) { var errors = new List <ValidationResult>(); if (FirstName.Length < 3) { errors.Add(new ValidationResult("None length cannot be less than 3", new[] { nameof(FirstName) })); } if (FirstName.Length > 50) { errors.Add(new ValidationResult($"Name: {FirstName} not allowed to work. Max name length is 30 ", new[] { nameof(FirstName) })); } // Database call through service for validation var dbContext = new PersonServiceImpl(); bool isExists = false; try { isExists = await dbContext.IsPersonExist(FirstName); } catch { isExists = false; } if (isExists) { errors.Add(new ValidationResult("Genre exist", new[] { nameof(Person) })); } return(errors); }