public IActionResult AddPerson(Person person) { // Let db assign id person.Id = Guid.Empty; _context.Add(person); _context.SaveChanges(); return Ok(); }
public void Add_person_saves_to_db_with_generated_id() { // Arrange Guid personId = Guid.NewGuid(); Person person = new Person() { Id = personId, FirstName = "Billy", LastName = "McBill" }; var beforePersonCount = _context.People.Count(); // Act var result = _controller.AddPerson(person) as HttpStatusCodeResult; // Assert Assert.Equal(200, result.StatusCode); Person savedPerson = _context.People.Single(x => x.FirstName == "Billy" && x.LastName == "McBill"); Assert.NotEqual(personId, savedPerson.Id); Assert.Equal(beforePersonCount + 1, _context.People.Count()); }