* Adding tests for GetById endpoint * Updating tests and messages * Adding paged endpoint and also AutoMapper * Authenticate endpoint works as bool with tests * Got JWT token security working with Create and Delete endpoints and Swashbuckle. * Working on getting cookie and jwt token auth working in the same app All tests are passing * Creating new project and moving APIs Build succeeds; tests need updated. * all tests passing after moving services to PublicApi project * Fix authorize attributes * Uncomment and update ApiCatalogControllerLists tests Co-authored-by: Eric Fleming <eric-fleming18@hotmail.com>
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using Microsoft.eShopWeb.FunctionalTests.PublicApi;
|
|
using Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers
|
|
{
|
|
[Collection("Sequential")]
|
|
public class GetByIdEndpoint : IClassFixture<ApiTestFixture>
|
|
{
|
|
JsonSerializerOptions _jsonOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
|
|
public GetByIdEndpoint(ApiTestFixture factory)
|
|
{
|
|
Client = factory.CreateClient();
|
|
}
|
|
|
|
public HttpClient Client { get; }
|
|
|
|
[Fact]
|
|
public async Task ReturnsItemGivenValidId()
|
|
{
|
|
var response = await Client.GetAsync("api/catalog-items/5");
|
|
response.EnsureSuccessStatusCode();
|
|
var stringResponse = await response.Content.ReadAsStringAsync();
|
|
var model = stringResponse.FromJson<GetByIdCatalogItemResponse>();
|
|
|
|
Assert.Equal(5, model.CatalogItem.Id);
|
|
Assert.Equal("Roslyn Red Sheet", model.CatalogItem.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ReturnsNotFoundGivenInvalidId()
|
|
{
|
|
var response = await Client.GetAsync("api/catalog-items/0");
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
}
|
|
}
|
|
}
|