public async Task Update_product_response_ok_status_code_should_replace_file_in_directory() { using (var server = CreateServer()) { var ctx = server.Host.Services.GetRequiredService <CatalogContext>(); var productViewModel = await GetTestProductVIewModelAsync(ctx); var productNameToUpdate = "zzz"; #region Verify Product Tests case var testProduct = await ctx.Products .Include(x => x.ProductImages) .Include(x => x.ProductColors) .Include(x => x.ProductRatings) .Where(x => x.Name == productNameToUpdate) .ToListAsync(); if (testProduct.Count() > 0) { ctx.Products.RemoveRange(testProduct); await ctx.SaveChangesAsync(); } #endregion #region Verify Product To Edit var verifyProduct = await ctx.Products .Include(x => x.ProductImages) .Include(x => x.ProductColors) .SingleOrDefaultAsync(x => x.Name == productViewModel.Name); string id; if (verifyProduct == null) { var contentToAdd = new StringContent(JsonConvert.SerializeObject(productViewModel), Encoding.UTF8, "application/json"); var res = await server.CreateClient() .PostAsync(Post.AddProduct, contentToAdd); id = res.Headers.Location.Query.Split('=')[1]; } else { id = verifyProduct.Id; } #endregion productViewModel.Name = productNameToUpdate; productViewModel.Description = "Test"; productViewModel.ProductImages = new[] { new ProductImage { ImageName = "test1.png", ImageUrl = productViewModel.ProductImages.First().ImageUrl } }; productViewModel.ProductColors = new ProductColor[0]; var content = new StringContent(JsonConvert.SerializeObject(productViewModel), Encoding.UTF8, "application/json"); var response = await server.CreateClient() .PutAsync(Put.UpdateProduct(id), content); response.EnsureSuccessStatusCode(); var insertedId = response.Headers.Location.Segments[4]; var hostingEnvironment = server.Host.Services.GetRequiredService <IHostingEnvironment>(); var insertedProduct = await ctx.Products .Include(x => x.ProductImages) .FirstOrDefaultAsync(x => x.Id == insertedId); foreach (var productImage in insertedProduct.ProductImages) { var targetDir = hostingEnvironment.WebRootPath + "/ProductImage/" + insertedId + "/" + productImage.ImageName; Assert.True(File.Exists(targetDir)); } } }