public async Task AddAsync_ShouldAddPersonWithoutIdentifier() { var person = new Person { FirstName = "SANJU", LastName = "B." }; await _sut.AddAsync(person); await _sut.SaveChangesAsync(); var personAdded = _sut.GetAll().Last(); Assert.Equal(person.FirstName, personAdded.FirstName); }
public async Task <IActionResult> AddPerson([FromBody] Person person) { person.Id = Guid.NewGuid(); var added = await PersonRepository.AddAsync(person); return(CreatedAtRoute("GetPerson", new { id = added.Id }, added)); }
public async Task AddAsync_NullPerson_ThrowsArgumentNullException() { //Arrange PersonContext personContext = CreatePersonContext(); PersonRepository personRepository = new PersonRepository(personContext); //Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { //Act await personRepository.AddAsync(null); }); }
public async Task <IActionResult> Post([FromBody] DTOs.Person person, ApiVersion version = null) { if (version == null) { version = ApiVersion.Default; } var newEntity = new v1.Person(person.Firstname, person.LastName, person.Email, person.Phone); await _repository.AddAsync(newEntity); await _repository.SaveChangesAsync(); return(CreatedAtAction(nameof(GetById), new { id = newEntity.Id, version = $"{version}" }, _mapper.Map <DTOs.Person>(newEntity))); }
public async Task AddAsync_NewPersonWithNoExistingPeople_ReturnsIdAndAddsToContext() { //Arrange Person expected = PersonGenerator.Generate(); PersonContext personContext = CreatePersonContext(); PersonRepository personRepository = new PersonRepository(personContext); //Act int result = await personRepository.AddAsync(expected); //Assert Assert.Equal(expected.Id, result); Person actual = personContext.People.Find(result); Assert.Equal(expected, actual, PersonEqualityComparer.Default); }
public async Task AddAsync_ExistingPersonWithIdAddingDuplicate_DuplicateNotAddedAndReturnsExistingId() { //Arrange const int Id = 1; Person expected = PersonGenerator.Generate(); PersonContext personContext = await CreatePersonContextWithPeople(expected); PersonRepository personRepository = new PersonRepository(personContext); //Act int result = await personRepository.AddAsync(expected); //Assert Assert.Equal(Id, result); Person actual = Assert.Single(personContext.People); Assert.Equal(expected, actual, PersonEqualityComparer.Default); }