Fix Null Warnings (#874)
* Fixing null warnings * Fix null warnings Fix other compiler warnings
This commit is contained in:
@@ -8,62 +8,61 @@ using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PublicApiIntegrationTests.AuthEndpoints
|
||||
namespace PublicApiIntegrationTests.AuthEndpoints;
|
||||
|
||||
[TestClass]
|
||||
public class CreateCatalogItemEndpointTest
|
||||
{
|
||||
[TestClass]
|
||||
public class CreateCatalogItemEndpointTest
|
||||
private int _testBrandId = 1;
|
||||
private int _testTypeId = 2;
|
||||
private string _testDescription = "test description";
|
||||
private string _testName = "test name";
|
||||
private decimal _testPrice = 1.23m;
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public async Task ReturnsNotAuthorizedGivenNormalUserToken()
|
||||
{
|
||||
private int _testBrandId = 1;
|
||||
private int _testTypeId = 2;
|
||||
private string _testDescription = "test description";
|
||||
private string _testName = "test name";
|
||||
private decimal _testPrice = 1.23m;
|
||||
var jsonContent = GetValidNewItemJson();
|
||||
var token = ApiTokenHelper.GetNormalUserToken();
|
||||
var client = ProgramTest.NewClient;
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
var response = await client.PostAsync("api/catalog-items", jsonContent);
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ReturnsNotAuthorizedGivenNormalUserToken()
|
||||
[TestMethod]
|
||||
public async Task ReturnsSuccessGivenValidNewItemAndAdminUserToken()
|
||||
{
|
||||
var jsonContent = GetValidNewItemJson();
|
||||
var adminToken = ApiTokenHelper.GetAdminUserToken();
|
||||
var client = ProgramTest.NewClient;
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", adminToken);
|
||||
var response = await client.PostAsync("api/catalog-items", jsonContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var model = stringResponse.FromJson<CreateCatalogItemResponse>();
|
||||
|
||||
Assert.AreEqual(_testBrandId, model!.CatalogItem.CatalogBrandId);
|
||||
Assert.AreEqual(_testTypeId, model.CatalogItem.CatalogTypeId);
|
||||
Assert.AreEqual(_testDescription, model.CatalogItem.Description);
|
||||
Assert.AreEqual(_testName, model.CatalogItem.Name);
|
||||
Assert.AreEqual(_testPrice, model.CatalogItem.Price);
|
||||
}
|
||||
|
||||
private StringContent GetValidNewItemJson()
|
||||
{
|
||||
var request = new CreateCatalogItemRequest()
|
||||
{
|
||||
var jsonContent = GetValidNewItemJson();
|
||||
var token = ApiTokenHelper.GetNormalUserToken();
|
||||
var client = ProgramTest.NewClient;
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
var response = await client.PostAsync("api/catalog-items", jsonContent);
|
||||
CatalogBrandId = _testBrandId,
|
||||
CatalogTypeId = _testTypeId,
|
||||
Description = _testDescription,
|
||||
Name = _testName,
|
||||
Price = _testPrice
|
||||
};
|
||||
var jsonContent = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json");
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ReturnsSuccessGivenValidNewItemAndAdminUserToken()
|
||||
{
|
||||
var jsonContent = GetValidNewItemJson();
|
||||
var adminToken = ApiTokenHelper.GetAdminUserToken();
|
||||
var client = ProgramTest.NewClient;
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", adminToken);
|
||||
var response = await client.PostAsync("api/catalog-items", jsonContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var model = stringResponse.FromJson<CreateCatalogItemResponse>();
|
||||
|
||||
Assert.AreEqual(_testBrandId, model.CatalogItem.CatalogBrandId);
|
||||
Assert.AreEqual(_testTypeId, model.CatalogItem.CatalogTypeId);
|
||||
Assert.AreEqual(_testDescription, model.CatalogItem.Description);
|
||||
Assert.AreEqual(_testName, model.CatalogItem.Name);
|
||||
Assert.AreEqual(_testPrice, model.CatalogItem.Price);
|
||||
}
|
||||
|
||||
private StringContent GetValidNewItemJson()
|
||||
{
|
||||
var request = new CreateCatalogItemRequest()
|
||||
{
|
||||
CatalogBrandId = _testBrandId,
|
||||
CatalogTypeId = _testTypeId,
|
||||
Description = _testDescription,
|
||||
Name = _testName,
|
||||
Price = _testPrice
|
||||
};
|
||||
var jsonContent = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json");
|
||||
|
||||
return jsonContent;
|
||||
}
|
||||
return jsonContent;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user