private async Task TestGet(TodoApiClient client, TodoApiModel model) { var single = await client.GetAsync(model.Id); Assert.Equal(model.Task, single.Task); var all = await client.GetAllAsync(); Assert.NotEmpty(all.Where(x => x.Id == model.Id && x.Task == model.Task)); }
private async Task TestDelete(TodoApiClient client, TodoApiModel model) { var deletedTodo = await client.DeleteAsync(model.Id); await Assert.ThrowsAsync <ApiException>(async() => await client.GetAsync(model.Id)); var all = await client.GetAllAsync(); Assert.Empty(all.Where(x => x.Id == model.Id)); }
public async Task Test_Todo_Crud_Workflow() { var client = new TodoApiClient(new HttpClient()); var newTodo = await TestCreate(client, "Task 123"); var updatedTodo = await TestUpdate(client, newTodo, "Updated Task 123!"); await TestDelete(client, updatedTodo); }
private async Task <TodoApiModel> TestUpdate(TodoApiClient client, TodoApiModel model, string task) { var updateRequest = new TodoRequestApiModel { Task = task }; var updatedTodo = await client.PutAsync(model.Id, updateRequest); await TestGet(client, updatedTodo); return(updatedTodo); }
private async Task <TodoApiModel> TestCreate(TodoApiClient client, string task) { var createRequest = new TodoRequestApiModel { Task = task }; var newTodo = await client.PostAsync(createRequest); await TestGet(client, newTodo); return(newTodo); }
public static async Task MainAsync(string[] args) { try { var sampleOptions = new IdentitySampleOptions(); // Create Clients UserCredentialsTokenAuthClient tokenAuthClient = new UserCredentialsTokenAuthClient(sampleOptions.AuthEndpoint, sampleOptions.ClientId, sampleOptions.ClientSecret); TokenResponse token = await tokenAuthClient.AuthAsync(sampleOptions.UserName, sampleOptions.UserPassword, sampleOptions.TodoApiId); if (token.IsError) { Console.WriteLine("Auth failed: " + token.Error); return; } TodoApiClient todoApiClient = new TodoApiClient(new BearerAuthorizedApiClient(token.AccessToken), sampleOptions.ApiEndpoint); IList <TaskApiModel> tasks = await todoApiClient.GetTasksAsync(); Console.WriteLine($"Received #{tasks.Count} from external API."); foreach (var task in tasks) { Console.WriteLine($"#{task.Id} | {task.Title}: {task.Description}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.ReadLine(); } }
public HomeController(TodoApiClient todoApiClient) { _todoApiClient = todoApiClient; }