public async Task MakeComplete() { var todo = new TodoDisplayVm { Description = "MakeComplete" }; var url = "http://localhost:8888/"; var server = WebHost.CreateDefaultBuilder() .UseStartup <Startup>() .UseUrls(url) .Build(); Task.Run(() => { server.Start(); }); var connection = new HubConnectionBuilder() .WithUrl("http://localhost:8888/hub") .WithConsoleLogger() .Build(); connection.On <string>("Notify", data => { Assert.Equal(todo.Description + " is complete", data); }); await connection.StartAsync(); var client = new HttpClient(); client.BaseAddress = new Uri(url); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); var create = await client.PostAsync(_root, CreateContent(todo)); create.EnsureSuccessStatusCode(); var id = (await FromContent(create.Content)).Id; var response = await client.PostAsync(_root + id + "/MakeComplete", new StringContent("")); response.EnsureSuccessStatusCode(); var result = await Get(id, client); Assert.Equal(id, result.Id); Assert.Equal(todo.Description, result.Description); Assert.Equal(true, result.IsComplete); await client.DeleteAsync(_root + id); }
public async Task Not_Create_Too_Short_Description() { var todo = new TodoDisplayVm { Description = "O" }; var response = await _client.PostAsync(_root, CreateContent(todo)); Assert.NotEqual(true, response.IsSuccessStatusCode); }
public TodoControllerShould() { SetupRepo(); _server = CreateServer(); _client = CreateClient(_server); _todo = new TodoDisplayVm { Description = "Bla bla bla" }; _root = "api/v1/todo/"; }
public async Task Not_Create_Duplicate_Description() { var todo = new TodoDisplayVm { Description = "Ololosh" }; _mementoes.Clear(); _mementoes.Add(new Todo(todo.Id, todo.Description, todo.IsComplete)); var result = await _client.PostAsync(_root, CreateContent(todo)); Assert.NotEqual(true, result.IsSuccessStatusCode); }
private StringContent CreateContent(TodoDisplayVm todo) { return(new StringContent(ToJson(todo), Encoding.UTF8, "application/json")); }
private string ToJson(TodoDisplayVm todo) { return(JsonConvert.SerializeObject(todo)); }
public IActionResult Post([FromBody] TodoCreateVm todo) { var result = new Todo(todo.Description); _repository.Add(result); return(CreatedAtAction(nameof(TodoController.Get), new { id = result.Id }, TodoDisplayVm.FromTodo(result))); }
public IActionResult Get([FromRoute] TodoSearchVm todo) { return(Ok(TodoDisplayVm.FromTodo(_repository[todo.Id]))); }