public async void PUT_classtours_idsMatchAndValidData_ShouldReturn200() { var tourId = 1; var client = _factory.CreateClient(); var tour = new ClassTour() { DayVisited = DateTime.Now, Name = "Wahama High School", NumberOfStudents = 23, Id = tourId }; var user = await Utils.Login(client); var request = new HttpRequestMessage(HttpMethod.Put, $"api/classtours/{tourId}"); request.Headers.Add("Authorization", $"Bearer {user.Token}"); request.Content = new StringContent(JsonConvert.SerializeObject(tour)); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.SendAsync(request); Assert.Equal(HttpStatusCode.OK, response.StatusCode); var updatedTour = await response.Content.ReadAsAsync <ClassTour>(); Assert.Equal("Wahama High School", updatedTour.Name); }
public async void PUT_classtours_idsDoNotMatch_ShouldReturn500WithMessage() { var tourId = 1; var wrongTourId = 5; var client = _factory.CreateClient(); var tour = new ClassTour() { DayVisited = DateTime.Now, Name = "Tour Name", NumberOfStudents = 23, Id = wrongTourId }; var user = await Utils.Login(client); var request = new HttpRequestMessage(HttpMethod.Put, $"api/classtours/{tourId}"); request.Headers.Add("Authorization", $"Bearer {user.Token}"); request.Content = new StringContent(JsonConvert.SerializeObject(tour)); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.SendAsync(request); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); var errorMessage = await response.Content.ReadAsAsync <ErrorMessage>(); Assert.Equal("Class Tour does not exist", errorMessage.Message); }
public async void ClassTour_DeletedIsTrue_TourNotReturnedByOverloadedGetAll() { var tour = new ClassTour() { DayVisited = DateTime.Now, Name = "Some High School", NumberOfStudents = 23, Deleted = true }; await classTourRepo.Create(tour); var results = classTourRepo.GetAll(x => x.Name == "Some High School"); Assert.Empty(results); }
public async void ClassTour_DeletedIsFalse_TourIsReturnedByOverloadedGetAll() { var tour = new ClassTour() { DayVisited = DateTime.Now, Name = "Some High School", NumberOfStudents = 23, Deleted = false }; await classTourRepo.Create(tour); var results = classTourRepo.GetAll(x => x.Name == "Some High School"); Assert.Equal(tour.DayVisited, results.FirstOrDefault().DayVisited); }
public async void ClassTour_DeletedIsFalse_DeletedSetToTrueAfterCallingRemove() { var tour = new ClassTour() { DayVisited = DateTime.Now, Name = "Some High School", NumberOfStudents = 23, Deleted = false }; await classTourRepo.Create(tour); var deletedTour = await classTourRepo.Remove(x => x.Id == tour.Id); Assert.True(deletedTour.Deleted); }
public async Task <IActionResult> PutClassTour([FromRoute] int id, [FromBody] ClassTour classTour) { if (id != classTour.Id) { throw new TCSException("Class Tour does not exist"); } try { await _iRepo.Update(classTour); return(Ok(classTour)); } catch (DbUpdateConcurrencyException) { return(NotFound(new { message = "Something went wrong" })); } }
public async void POST_classtour_invalidData_ShouldReturn400() { var tour = new ClassTour() { DayVisited = DateTime.Now, Name = "", NumberOfStudents = 23 }; var client = _factory.CreateClient(); var user = await Utils.Login(client); var request = new HttpRequestMessage(HttpMethod.Post, "api/classtours"); request.Headers.Add("Authorization", $"Bearer {user.Token}"); request.Content = new StringContent(JsonConvert.SerializeObject(tour)); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.SendAsync(request); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); }
public async Task <IActionResult> PostClassTour([FromBody] ClassTour classTour) { await _iRepo.Create(classTour); return(Created($"classtours/{classTour.Id}", classTour)); }