public async Task With_Taken_Id_Is_Unsuccessful() { //Arrange var id = "1"; var data = new PostRadioRequest { alias = "radio100", allowedLocations = new List <string> { "CPH-1", "CPH-2", "CPH-3" } }; using (var client = new TestClientProvider().Client) { //Act var res = await client .PostAsync(GetURI() + id, GetEncoder().JsonEncode(data)); //Assert res.IsSuccessStatusCode.ShouldBe(false); } }
public async Task With_Valid_Data_Is_OK() { //Arrange var id = "100"; var data = new PostRadioRequest { alias = "radio100", allowedLocations = new List <string> { "CPH-1", "CPH-2", "CPH-3" } }; using (var client = new TestClientProvider().Client) { //Act var res = await client .PostAsync(GetURI() + id, GetEncoder().JsonEncode(data)); //Assert res.StatusCode.ShouldBe(HttpStatusCode.OK); } }
public async Task <ActionResult <int> > PostRadio([FromRoute] int id, [FromBody] PostRadioRequest radioBody) { List <Location> locations = new List <Location>(); try { if (radioBody.allowedLocations != null) { locations = radioBody.allowedLocations.Select(s => new Location() { Id = s }).ToList(); } var radio = new Radio() { Id = id, Alias = radioBody.alias, AllowedLocations = locations }; var result = await _radioGod.CreateRadio(radio, new CancellationToken()); return(Ok(result)); } catch (Exception e) { return(Conflict(e)); } }