public async Task AddAsync_Should_AddEntity() { // Arrange var entity = Builder <ToDoTask> .CreateNew() .With(x => x.Id = 0) .With(x => x.IsDone = false) .With(x => x.IsDeleted = false) .With(x => x.Text = "Test todo text") .Build(); var newEntity = Builder <ToDoTask> .CreateNew() .With(x => x.Id = 1) .With(x => x.IsDone = false) .With(x => x.IsDeleted = false) .With(x => x.Text = "Test todo text") .Build(); todoTaskRepositoryMock.Setup(mock => mock.AddAsync(entity)) .ReturnsAsync(newEntity); // Act var result = await toDoTaskService.AddAsync(entity).ConfigureAwait(false); // Assert Assert.NotNull(result); Assert.Equal(1, result.Id); Assert.Equal("Test todo text", entity.Text); }
public async Task <IActionResult> PostAsync([FromBody] ToDoTask entity) { try { var addedEntity = await toDoTaskService.AddAsync(entity).ConfigureAwait(false); return(Ok(addedEntity)); } catch (Exception) { return(BadRequest("Error occured at data saving.")); } }
public async Task Post([FromBody] ToDoTask model) { await _toDoTaskService.AddAsync(model); }