public async Task TestCreateTodoOk() { //SETUP var options = SqliteInMemory.CreateOptions <ExampleDbContext>(); using (var context = new ExampleDbContext(options)) { context.Database.EnsureCreated(); context.SeedDatabase(); var controller = new ToDoHybridController(); var utData = context.SetupSingleDtoAndEntities <CreateTodoHybridDto>(_genericServiceConfig); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT var dto = new CreateTodoHybridDto() { Name = "Test", Difficulty = 3, }; var response = await controller.PostAsync(dto, service); //VERIFY response.GetStatusCode().ShouldEqual(201); var rStatus = response.CheckCreateResponse("GetSingleHybridTodo", new { id = 7 }, dto); rStatus.IsValid.ShouldBeTrue(rStatus.GetAllErrors()); rStatus.Message.ShouldEqual("Success"); } }
public async Task <ActionResult <CreateTodoHybridDto> > PostAsync(CreateTodoHybridDto item, [FromServices] ICrudServicesAsync service) { var result = await service.CreateAndSaveAsync(item); //NOTE: to get this to work you MUST set the name of the HttpGet, e.g. [HttpGet("{id}", Name= "GetSingleTodo")], //on the Get you want to call, then then use the Name value in the Response. //Otherwise you get a "No route matches the supplied values" error. //see https://stackoverflow.com/questions/36560239/asp-net-core-createdatroute-failure for more on this return(service.Response(this, "GetSingleHybridTodo", new { id = result.Id }, item)); }