public async Task <IActionResult> Put(Guid id, [FromBody] TodoUpsertModel todoUpsertModel) { var todo = _mapper.Map <TodoUpsertModel, BusinessModels.Todo>(todoUpsertModel); await _todoService.UpdateTodo(id, todo); return(Ok()); }
public async Task <IActionResult> Post([FromBody] TodoUpsertModel todoUpsertModel) { var todo = _mapper.Map <TodoUpsertModel, BusinessModels.Todo>(todoUpsertModel); // Add newTodo var newTodoFromService = await _todoService.AddTodo(todo); // Map newTodo to apiModel var todoApiModel = _mapper.Map <BusinessModels.Todo, TodoModel>(newTodoFromService); // Return newTodo to client with the uri of the resource and created 201 result. return(CreatedAtAction(nameof(Get), new { todoApiModel.Id }, todoApiModel)); }
public void Name_ShouldPassValidation_WhenBetween1to100Characters() { // Arrange var testModel = new TodoUpsertModel() { Name = "Valid Name" }; // Act var validationResults = Validate(testModel); // Assert validationResults.Count.Should().Be(0); }
public void Name_ShouldFailValidation_WhenNullOrEmptyAndThusLessThan1Character(string name) { // Arrange var testModel = new TodoUpsertModel() { Name = name }; // Act var validationResults = Validate(testModel); // Assert validationResults.Count.Should().BeGreaterThan(0); validationResults[0].ErrorMessage.Should().BeEquivalentTo("The Name field is required."); }
public void Name_ShouldFailValidation_WhenMoreThan100Characters() { // Arrange var testModel = new TodoUpsertModel() { Name = new string('c', 101) }; // Act var validationResults = Validate(testModel); // Assert validationResults.Count.Should().BeGreaterThan(0); validationResults[0].ErrorMessage.Should() .BeEquivalentTo( "The field Name must be a string with a minimum length of 1 and a maximum length of 100."); }