private async Task <HttpResponseMessage> RegisterAnimalAsync(CreateAnimal request) { var payload = GetPayload(request); var response = await _client.PostAsync("users/[email protected]/animals", payload); return(response); }
public async Task <IActionResult> Post(string email, [FromBody] CreateAnimal request) { if (email != await GetLoggedUserEmail()) { throw new ServiceException(ErrorCodes.AnimalNotAvailable, "You can only add animals to your account."); } await _animalService.AddAsync(email, request.Name, request.YearOfBirth); return(NoContent()); }
public CreateAnimalViewModel(EFDbContext context) { _context = context; _animalKinds = new EFRepository <AnimalKind>(_context); _animalRations = new EFRepository <Ration>(_context); _animals = new EFRepository <Animal>(_context); CreateAnimal window = new CreateAnimal(this); window.ShowDialog(); }
public async Task given_existing_user_email_and_animal_name_animal_should_be_created() { var newAnimal = new CreateAnimal { Name = "Goldi", YearOfBirth = 2004 }; //TODO: Why does it return 302 status code instead of 204 ? var response = await RegisterAnimalAsync(newAnimal); response.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.NoContent); }
public AnimalControllerTests() { // Initializate data on start _existingAnimal = new CreateAnimal { Name = "Tajger", YearOfBirth = 2015 }; _existingAnimalForDelete = new CreateAnimal { Name = "AnimalToDelete", YearOfBirth = 2017 }; _nonExistingAnimal = new UpdateAnimal { Name = "NonExistingAnimal", YearOfBirth = 1920 }; RegisterAnimalAsync(_existingAnimal); RegisterAnimalAsync(_existingAnimalForDelete); }