89 lines
2.5 KiB
C#
89 lines
2.5 KiB
C#
using System.Net;
|
|
using System.Net.Http;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.TestHost;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace H_Plus_Sports.Tests
|
|
{
|
|
[TestClass]
|
|
public class ProductIntegrationTests
|
|
{
|
|
private readonly HttpClient _client;
|
|
|
|
public ProductIntegrationTests()
|
|
{
|
|
var server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
|
|
_client = server.CreateClient();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ProductGetAllTest()
|
|
{
|
|
// Arrange
|
|
var request = new HttpRequestMessage(new HttpMethod("GET"), "/api/Products/");
|
|
|
|
// Act
|
|
var response = _client.SendAsync(request).Result;
|
|
|
|
// Assert
|
|
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow("MWBLU32")]
|
|
public void ProductGetOneTest(string id)
|
|
{
|
|
// Arrange
|
|
var request = new HttpRequestMessage(new HttpMethod("GET"), $"/api/Products/{id}");
|
|
|
|
// Act
|
|
var response = _client.SendAsync(request).Result;
|
|
|
|
// Assert
|
|
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ProductPostTest()
|
|
{
|
|
// Arrange
|
|
var request = new HttpRequestMessage(new HttpMethod("POST"), $"/api/Products/");
|
|
|
|
// Act
|
|
var response = _client.SendAsync(request).Result;
|
|
|
|
// Assert
|
|
Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode);
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow("MWORA32")]
|
|
public void ProductPutTest(string id)
|
|
{
|
|
// Arrange
|
|
var request = new HttpRequestMessage(new HttpMethod("PUT"), $"/api/Products/{id}");
|
|
|
|
// Act
|
|
var response = _client.SendAsync(request).Result;
|
|
|
|
// Assert
|
|
Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode);
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow("MWORA32")]
|
|
public void ProductDeleteTest(string id)
|
|
{
|
|
// Arrange
|
|
var request = new HttpRequestMessage(new HttpMethod("DELETE"), $"/api/Products/{id}");
|
|
|
|
// Act
|
|
var response = _client.SendAsync(request).Result;
|
|
|
|
// Assert
|
|
Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
|
|
}
|
|
}
|
|
}
|