public async Task Create_Success() { // Arrange var client = _factory.CreateAuthenticatedClient(); var command = _fixture.Build <CreateProductCommand>() .Without(s => s.ImageFile) .Create(); var multipart = new MultipartFormDataContent { { new StringContent(command.Name), nameof(command.Name) }, { new StringContent(command.Price.ToString(CultureInfo.InvariantCulture)), nameof(command.Price) }, { new StringContent(command.Description), nameof(command.Description) }, { new StringContent(command.StockQuantity.ToString()), nameof(command.StockQuantity) }, { new ByteArrayContent(Encoding.UTF8.GetBytes("This is a dummy file")), nameof(command.ImageFile), "image.jpg" }, }; // Act var response = await client.PostAsync(BaseUrl, multipart); // Assert response.Should().Be200Ok().And .Satisfy <ProductDto>(s => s.Should().NotBeNull()); }
public async Task Create_Authenticated_Success() { // Arrange var client = _factory.CreateAuthenticatedClient(); var command = new CreateCategoryCommand { Name = "Created" }; // Act var response = await client.PostAsJsonAsync(Uri, command); // Assert response.StatusCode.Should().Be(HttpStatusCode.Created); var result = await response.Content.ReadAsAsync <CategoryDto>(); result.Should().BeEquivalentTo(new CategoryDto { Name = "Created" }, s => s.Excluding(p => p.Id)); }
public async Task Create_Authenticated_Success() { // Arrange var client = _factory.CreateAuthenticatedClient(); await using var file = new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")); var command = new CreateProductCommand { Name = "Created", Price = 100, Description = "Short description", CartMaxQuantity = 10, StockQuantity = 100, SellQuantity = 50 }; var content = new MultipartFormDataContent { { new ByteArrayContent(file.ToArray()), nameof(command.Image), "dummy.jpg" }, { new StringContent(command.Name), nameof(command.Name) }, { new StringContent(command.Price.ToString()), nameof(command.Price) }, { new StringContent(command.Description), nameof(command.Description) }, { new StringContent(command.CartMaxQuantity.ToString()), nameof(command.CartMaxQuantity) }, { new StringContent(command.StockQuantity.ToString()), nameof(command.StockQuantity) }, { new StringContent(command.SellQuantity.ToString()), nameof(command.SellQuantity) }, }; // Act var response = await client.PostAsync(Uri, content); // Assert response.StatusCode.Should().Be(HttpStatusCode.Created); var result = await response.Content.ReadAsAsync <ProductDto>(); result.Should().BeEquivalentTo(new ProductDto { Name = "Created" }, s => s.Including(p => p.Name)); }
public async Task Find_Success() { // Arrange var client = _factory.CreateAuthenticatedClient(); // Act var response = await client.GetAsync(Uri); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); var result = await response.Content.ReadAsAsync <List <RoleDto> >(); result.Should().NotBeNullOrEmpty(); }
public async Task Update_Authenticated_Success() { // Arrange var client = _factory.CreateAuthenticatedClient(); var command = new ChangeReviewStatusCommand { ReviewStatus = ReviewStatus.Approved }; // Act var response = await client.PostAsJsonAsync($"{Uri}/1/change-review-status", command); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); }