85 lines
2.4 KiB
C#
85 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.TestHost;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
|
|
namespace H_Plus_Sports.Tests
|
|
{
|
|
[TestClass]
|
|
public class CustomerIntegrationTests
|
|
{
|
|
private readonly HttpClient _client;
|
|
|
|
public CustomerIntegrationTests()
|
|
{
|
|
var server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
|
|
_client = server.CreateClient();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CustomerGetAllTest()
|
|
{
|
|
//Arrange
|
|
var request = new HttpRequestMessage(new HttpMethod("GET"), "/api/Customers");
|
|
//Act
|
|
var response = _client.SendAsync(request).Result;
|
|
//Assert
|
|
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow(100)]
|
|
public void CustomerGetOneTest(int id)
|
|
{
|
|
//Arrange
|
|
var request = new HttpRequestMessage(new HttpMethod("GET"), $"/api/Customers/{id}");
|
|
//Act
|
|
var response = _client.SendAsync(request).Result;
|
|
//Assert
|
|
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CustomerPostTest()
|
|
{
|
|
// Arrange
|
|
var request = new HttpRequestMessage(new HttpMethod("POST"), $"/api/Customers/");
|
|
|
|
// Act
|
|
var response = _client.SendAsync(request).Result;
|
|
|
|
// Assert
|
|
Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode);
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow(1)]
|
|
public void CustomerPutTest(int id)
|
|
{
|
|
// Arrange
|
|
var request = new HttpRequestMessage(new HttpMethod("PUT"), $"/api/Customers/{id}");
|
|
|
|
// Act
|
|
var response = _client.SendAsync(request).Result;
|
|
|
|
// Assert
|
|
Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode);
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow(1)]
|
|
public void CustomerDeleteTest(int id)
|
|
{
|
|
// Arrange
|
|
var request = new HttpRequestMessage(new HttpMethod("DELETE"), $"/api/Customers/{id}");
|
|
|
|
// Act
|
|
var response = _client.SendAsync(request).Result;
|
|
|
|
// Assert
|
|
Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
|
|
}
|
|
}
|
|
}
|