public void CreateOwnerNullOwnerThrowsException() { var ownerRepo = new Mock <IOwnerRepository>(); var petRepo = new Mock <IPetRepository>(); var service = new OwnerService(ownerRepo.Object, petRepo.Object); var ex = Assert.Throws <NullReferenceException>(() => service.CreateOwner(null)); Assert.Equal("Cannot create null owner", ex.Message); }
public void CreateOwnerEmptyFirstNameThrowsException() { var ownerRepo = new Mock <IOwnerRepository>(); var petRepo = new Mock <IPetRepository>(); var service = new OwnerService(ownerRepo.Object, petRepo.Object); var owner = new Owner { }; var ex = Assert.Throws <InvalidDataException>(() => service.CreateOwner(owner)); Assert.Equal("Owner needs a FirstName to be created", ex.Message); }
public IActionResult Create(CreateOwnerModel model) { var validationResult = _service.ValidateCreateOwner(User, model); if (!validationResult.Valid) { return(BadRequest(validationResult.Result)); } var entity = _service.CreateOwner(model); context.SaveChanges(); return(Created($"/{ApiEndpoint.OWNER_API}?id={entity.Id}", new AppResultBuilder().Success(entity.Id))); }
public void CreateOwnerRepositoryCalls() { var ownerRepo = new Mock <IOwnerRepository>(); var petRepo = new Mock <IPetRepository>(); var service = new OwnerService(ownerRepo.Object, petRepo.Object); var owner = new Owner { FirstName = "fname", LastName = "lname" }; service.CreateOwner(owner); ownerRepo.Verify(repo => repo.Create(It.IsAny <Owner>()), Times.Once()); petRepo.Verify(repo => repo.Create(It.IsAny <Pet>()), Times.Never()); }