public async Task CategoryDeleteOperationsTest() { var unauthorizedResponse = await DefaultClient.DeleteAsync($"api/Categories/{Guid.NewGuid()}"); Assert.Equal(HttpStatusCode.Unauthorized, unauthorizedResponse.StatusCode); var notExistingResponse = await AuthorizedClient.DeleteAsync($"api/Categories/{Guid.NewGuid()}"); Assert.Equal(HttpStatusCode.NoContent, notExistingResponse.StatusCode); var badResponse = await AuthorizedClient.DeleteAsync($"api/Categories/{Guid.Empty}"); Assert.Equal(HttpStatusCode.BadRequest, badResponse.StatusCode); var category = new Models.Category() { Name = "IsDeletePossible" }; category = await categoryRepository.Create(category); var response = await AuthorizedClient.DeleteAsync($"api/Categories/{category.Id}"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public async Task CategoryPutOperationsTest() { var category = new Models.Category() { Name = "PutTest" }; category = await categoryRepository.Create(category); Models.Eager.Category[] categroyUpdateModel = { new Models.Eager.Category() { Id = category.Id, Name = "updateContent" } }; var updateContent = new StringContent(JsonConvert.SerializeObject(categroyUpdateModel), Encoding.UTF8, "application/json"); Models.Eager.Category[] categoryWithEmptyId = { new Models.Eager.Category() { Name = "contentNoId" } }; var contentNoId = new StringContent(JsonConvert.SerializeObject(categoryWithEmptyId), Encoding.UTF8, "application/json"); Models.Eager.Category[] categoryWithWrongId = { new Models.Eager.Category() { Id = Guid.NewGuid(), Name = "contentWrongId" } }; var contentWrongId = new StringContent(JsonConvert.SerializeObject(categoryWithWrongId), Encoding.UTF8, "application/json"); var unauthorizedResponse = await DefaultClient.PutAsync($"api/Categories", updateContent); Assert.Equal(HttpStatusCode.Unauthorized, unauthorizedResponse.StatusCode); // When no Id create new record var createResponse = await AuthorizedClient.PutAsync($"api/Categories", contentNoId); Assert.Equal(HttpStatusCode.OK, createResponse.StatusCode); // When Id is invalid (e.g not found in db) var badRequestResponse = await AuthorizedClient.PutAsync($"api/Categories", contentWrongId); Assert.Equal(HttpStatusCode.BadRequest, badRequestResponse.StatusCode); }
public async Task GetAllCategories() { // Add sample category var category = new Models.Category() { Name = "Test" }; await categoryRepository.Create(category); // Response should return var getAllResponse = await DefaultClient.GetAsync("api/Categories"); Assert.Equal(HttpStatusCode.OK, getAllResponse.StatusCode); }
public async Task GetOneCategory() { // If we pass empty guid the should be bad request response var badResponse = await DefaultClient.GetAsync($"api/Categories/{Guid.Empty}"); Assert.Equal(HttpStatusCode.BadRequest, badResponse.StatusCode); // Add sample category var category = new Models.Category() { Name = "Test" }; category = await categoryRepository.Create(category); // After category added check if record can be returned var response = await DefaultClient.GetAsync($"api/Categories/{category.Id}"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); }