25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

50 satır
1.6KB

  1. using System.Net;
  2. using Microsoft.AspNetCore.Mvc.Testing;
  3. namespace CartWise.Web.Tests;
  4. public class ProductAccessControlTests : IClassFixture<CartWiseWebApplicationFactory>
  5. {
  6. private readonly CartWiseWebApplicationFactory _factory;
  7. public ProductAccessControlTests(CartWiseWebApplicationFactory factory)
  8. {
  9. _factory = factory;
  10. }
  11. [Fact]
  12. public async Task AnonymousUser_IsRedirectedToLoginWhenSearchingProducts()
  13. {
  14. var client = _factory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false });
  15. var response = await client.GetAsync("/products/search?q=milk");
  16. Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
  17. Assert.Contains("/Account/Login", response.Headers.Location?.ToString());
  18. }
  19. [Fact]
  20. public async Task AuthenticatedUser_CanSearchWithNoResults()
  21. {
  22. var client = _factory.CreateClient();
  23. await WebTestHelpers.RegisterAsync(client, "productsearch1@example.com", "Product Searcher");
  24. var response = await client.GetAsync("/products/search?q=nonexistentitem");
  25. response.EnsureSuccessStatusCode();
  26. var body = await response.Content.ReadAsStringAsync();
  27. HtmlAssert.Contains("No products matched", body);
  28. }
  29. [Fact]
  30. public async Task Details_ReturnsNotFoundForUnknownProduct()
  31. {
  32. var client = _factory.CreateClient();
  33. await WebTestHelpers.RegisterAsync(client, "productdetails1@example.com", "Product Detailer");
  34. var response = await client.GetAsync($"/products/{Guid.NewGuid()}");
  35. Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
  36. }
  37. }

Powered by TurnKey Linux.