public void EditExistingChannel_ShouldReturn200OK_Modify() { // Arrange -> create a new channel TestingEngine.CleanDatabase(); var channelName = "channel" + DateTime.Now.Ticks; var httpPostResponse = TestingEngine.CreateChannelHttpPost(channelName); Assert.AreEqual(HttpStatusCode.Created, httpPostResponse.StatusCode); var postedChannel = httpPostResponse.Content.ReadAsAsync <ChannelModel>().Result; // Act -> edit the above created channel var channelNewName = "Edited " + channelName; var httpPutResponse = TestingEngine.EditChannelHttpPut(postedChannel.Id, channelNewName); // Assert -> the PUT result is 200 OK Assert.AreEqual(HttpStatusCode.OK, httpPutResponse.StatusCode); // Assert the service holds the modified channel var httpGetResponse = TestingEngine.HttpClient.GetAsync("/api/channels").Result; var channelsFromService = httpGetResponse.Content.ReadAsAsync <List <ChannelModel> >().Result; Assert.AreEqual(HttpStatusCode.OK, httpGetResponse.StatusCode); Assert.AreEqual(1, channelsFromService.Count); Assert.AreEqual(postedChannel.Id, channelsFromService.First().Id); Assert.AreEqual(channelNewName, channelsFromService.First().Name); }
public void EditNotExistingChannel_ShouldReturn404NotFond() { // Arrange -> clear the database TestingEngine.CleanDatabase(); // Act -> try to edit non-existing channel var httpPutResponse = TestingEngine.EditChannelHttpPut(1, "new name"); // Assert -> the PUT result is 404 Not Found Assert.AreEqual(HttpStatusCode.NotFound, httpPutResponse.StatusCode); }
public void EditChannel_LeaveSameName_ShouldReturn200OK() { // Arrange -> create a channel TestingEngine.CleanDatabase(); var channelName = "channel" + DateTime.Now.Ticks; var httpPostResponse = TestingEngine.CreateChannelHttpPost(channelName); Assert.AreEqual(HttpStatusCode.Created, httpPostResponse.StatusCode); var channel = httpPostResponse.Content.ReadAsAsync <ChannelModel>().Result; // Act -> try to edit the channel and leave its name the same var httpPutResponse = TestingEngine.EditChannelHttpPut(channel.Id, channelName); // Assert -> HTTP status code is 200 (OK) Assert.AreEqual(HttpStatusCode.OK, httpPutResponse.StatusCode); }
public void EditChannel_InvalidData_ShouldReturn400BadRequest() { // Arrange -> create a new channel TestingEngine.CleanDatabase(); var channelName = "channel" + DateTime.Now.Ticks; var httpPostResponse = TestingEngine.CreateChannelHttpPost(channelName); Assert.AreEqual(HttpStatusCode.Created, httpPostResponse.StatusCode); var postedChannel = httpPostResponse.Content.ReadAsAsync <ChannelModel>().Result; // Act -> try to edit the above created channel var channelNewName = String.Empty; var httpPutResponse = TestingEngine.EditChannelHttpPut(postedChannel.Id, channelNewName); // Assert -> the PUT result is 400 Bad Request Assert.AreEqual(HttpStatusCode.BadRequest, httpPutResponse.StatusCode); }
public void EditChannel_DuplicatedName_ShouldReturn409Conflict() { // Arrange -> create two channels TestingEngine.CleanDatabase(); var channelNameFirst = "channel" + DateTime.Now.Ticks; var firstChannelHttpResponse = TestingEngine.CreateChannelHttpPost(channelNameFirst); Assert.AreEqual(HttpStatusCode.Created, firstChannelHttpResponse.StatusCode); var firstChannel = firstChannelHttpResponse.Content.ReadAsAsync <ChannelModel>().Result; var channelNameSecond = "channel" + DateTime.Now.Ticks + 1; var secondChannelHttpResponse = TestingEngine.CreateChannelHttpPost(channelNameSecond); Assert.AreEqual(HttpStatusCode.Created, secondChannelHttpResponse.StatusCode); // Act -> try to edit the first channel and duplicate its name with the second channel var httpPutResponseFirst = TestingEngine.EditChannelHttpPut(firstChannel.Id, channelNameSecond); // Assert -> HTTP status code is 409 (Conflict) Assert.AreEqual(HttpStatusCode.Conflict, httpPutResponseFirst.StatusCode); }