Files
eShopOnWeb/tests/PublicApiIntegrationTests/CatalogItemEndpoints/DeleteCatalogItemEndpointTest.cs
Cédric Michel 1e13733d3d Feature/migrate to minimal api (#662)
* migrate from classic controller to minimal api

* fix all PublicApi integration test

* update all nuget package add forget project

* fix pay now

* Adapt readme use in memory database

* undo AuthenticateEndpoint to use EndpointBaseAsync

* Update README.md

Co-authored-by: Steve Smith <steve@kentsmiths.com>

Co-authored-by: Steve Smith <steve@kentsmiths.com>
2022-01-21 10:13:31 -05:00

39 lines
1.5 KiB
C#

using BlazorShared.Models;
using Microsoft.eShopWeb;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace PublicApiIntegrationTests.CatalogItemEndpoints
{
[TestClass]
public class DeleteCatalogItemEndpointTest
{
[TestMethod]
public async Task ReturnsSuccessGivenValidIdAndAdminUserToken()
{
var adminToken = ApiTokenHelper.GetAdminUserToken();
var client = ProgramTest.NewClient;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", adminToken);
var response = await client.DeleteAsync("api/catalog-items/12");
response.EnsureSuccessStatusCode();
var stringResponse = await response.Content.ReadAsStringAsync();
var model = stringResponse.FromJson<DeleteCatalogItemResponse>();
Assert.AreEqual("Deleted", model.Status);
}
[TestMethod]
public async Task ReturnsNotFoundGivenInvalidIdAndAdminUserToken()
{
var adminToken = ApiTokenHelper.GetAdminUserToken();
var client = ProgramTest.NewClient;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", adminToken);
var response = await client.DeleteAsync("api/catalog-items/0");
Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
}
}
}