public async Task Update_Category_response_ok_status_code_should_replace_file_in_directory() { using (var server = CreateServer()) { var ctx = server.Host.Services.GetRequiredService <CatalogContext>(); var categoryToUpdate = await ctx.Categories.FirstOrDefaultAsync(); categoryToUpdate.Description = "Test"; categoryToUpdate.ImageName = "test.png"; categoryToUpdate.ImageUrl = GetTestCategory().ImageUrl; var content = new StringContent(JsonConvert.SerializeObject(categoryToUpdate), Encoding.UTF8, "application/json"); var response = await server.CreateClient() .PutAsync(Put.UpdateCategory(categoryToUpdate.Id), content); response.EnsureSuccessStatusCode(); var hostingEnvironment = server.Host.Services.GetRequiredService <IHostingEnvironment>(); var insertedCategory = await ctx.Categories.SingleOrDefaultAsync(x => x.Name == categoryToUpdate.Name); var targetDir = hostingEnvironment.WebRootPath + "/Category/" + insertedCategory.Id + "/" + insertedCategory.ImageName; Assert.True(File.Exists(targetDir)); } }
public async Task Update_Category_response_ok_status_code_should_persisted_in_db() { using (var server = CreateServer()) { var ctx = server.Host.Services.GetRequiredService <CatalogContext>(); var categoryToUpdate = await ctx.Categories.FirstOrDefaultAsync(); categoryToUpdate.Name = "Test"; categoryToUpdate.Description = "Test1"; categoryToUpdate.ImageName = "test1.png"; categoryToUpdate.ImageUrl = GetTestCategory().ImageUrl; var content = new StringContent(JsonConvert.SerializeObject(categoryToUpdate), Encoding.UTF8, "application/json"); var response = await server.CreateClient() .PutAsync(Put.UpdateCategory(categoryToUpdate.Id), content); response.EnsureSuccessStatusCode(); var insertedCategory = await ctx.Categories.SingleOrDefaultAsync(x => x.Name == categoryToUpdate.Name); Assert.NotNull(insertedCategory); } }