From 583f57f062f6631f8951872916753d32a125d2bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Thu, 19 Dec 2019 22:16:43 +0100 Subject: [PATCH] Test classes implemented --- H_PLUS_Sports.sln | 6 ++ .../CustomerIntegrationTests.cs | 87 ++++++++++++++++++ .../H_Plus_Sports.Tests.csproj | 21 +++++ H_Plus_Sports.Tests/OrderIntegrationTests.cs | 87 ++++++++++++++++++ .../OrderItemIntegrationTests.cs | 87 ++++++++++++++++++ .../ProductIntegrationTests.cs | 88 +++++++++++++++++++ .../SalespersonIntegrationTests.cs | 88 +++++++++++++++++++ 7 files changed, 464 insertions(+) create mode 100644 H_Plus_Sports.Tests/CustomerIntegrationTests.cs create mode 100644 H_Plus_Sports.Tests/H_Plus_Sports.Tests.csproj create mode 100644 H_Plus_Sports.Tests/OrderIntegrationTests.cs create mode 100644 H_Plus_Sports.Tests/OrderItemIntegrationTests.cs create mode 100644 H_Plus_Sports.Tests/ProductIntegrationTests.cs create mode 100644 H_Plus_Sports.Tests/SalespersonIntegrationTests.cs diff --git a/H_PLUS_Sports.sln b/H_PLUS_Sports.sln index f65d066..e536641 100644 --- a/H_PLUS_Sports.sln +++ b/H_PLUS_Sports.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29609.76 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "H_Plus_Sports", "H_PLUS_Sports\H_Plus_Sports.csproj", "{A5EEAD5D-227A-482E-AD66-F17D87C1E187}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "H_Plus_Sports.Tests", "H_Plus_Sports.Tests\H_Plus_Sports.Tests.csproj", "{8389C563-63EF-4ECA-9AE8-93FCE94E0BB7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {A5EEAD5D-227A-482E-AD66-F17D87C1E187}.Debug|Any CPU.Build.0 = Debug|Any CPU {A5EEAD5D-227A-482E-AD66-F17D87C1E187}.Release|Any CPU.ActiveCfg = Release|Any CPU {A5EEAD5D-227A-482E-AD66-F17D87C1E187}.Release|Any CPU.Build.0 = Release|Any CPU + {8389C563-63EF-4ECA-9AE8-93FCE94E0BB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8389C563-63EF-4ECA-9AE8-93FCE94E0BB7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8389C563-63EF-4ECA-9AE8-93FCE94E0BB7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8389C563-63EF-4ECA-9AE8-93FCE94E0BB7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/H_Plus_Sports.Tests/CustomerIntegrationTests.cs b/H_Plus_Sports.Tests/CustomerIntegrationTests.cs new file mode 100644 index 0000000..b1c39b9 --- /dev/null +++ b/H_Plus_Sports.Tests/CustomerIntegrationTests.cs @@ -0,0 +1,87 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.TestHost; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Text; + +namespace H_Plus_Sports.Tests +{ + [TestClass] + public class CustomerIntegrationTests + { + private readonly HttpClient _client; + + public CustomerIntegrationTests() + { + var server = new TestServer(new WebHostBuilder().UseStartup()); + _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); + } + } +} diff --git a/H_Plus_Sports.Tests/H_Plus_Sports.Tests.csproj b/H_Plus_Sports.Tests/H_Plus_Sports.Tests.csproj new file mode 100644 index 0000000..e094cc7 --- /dev/null +++ b/H_Plus_Sports.Tests/H_Plus_Sports.Tests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + + diff --git a/H_Plus_Sports.Tests/OrderIntegrationTests.cs b/H_Plus_Sports.Tests/OrderIntegrationTests.cs new file mode 100644 index 0000000..f7509f6 --- /dev/null +++ b/H_Plus_Sports.Tests/OrderIntegrationTests.cs @@ -0,0 +1,87 @@ +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 OrderIntegrationTests + { + private readonly HttpClient _client; + + public OrderIntegrationTests() + { + var server = new TestServer(new WebHostBuilder().UseStartup()); + _client = server.CreateClient(); + } + + [TestMethod] + public void OrderGetAllTest() + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("GET"), "/api/Orders/"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + } + + [TestMethod] + [DataRow(1001)] + public void OrderGetOneTest(int id) + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("GET"), $"/api/Orders/{id}"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + } + + [TestMethod] + public void OrderPostTest() + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("POST"), $"/api/Orders/"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode); + } + + [TestMethod] + [DataRow(1)] + public void OrderPutTest(int id) + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("PUT"), $"/api/Orders/{id}"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode); + } + + [TestMethod] + [DataRow(1)] + public void OrderDeleteTest(int id) + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("DELETE"), $"/api/Orders/{id}"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); + } + } +} diff --git a/H_Plus_Sports.Tests/OrderItemIntegrationTests.cs b/H_Plus_Sports.Tests/OrderItemIntegrationTests.cs new file mode 100644 index 0000000..b493ab4 --- /dev/null +++ b/H_Plus_Sports.Tests/OrderItemIntegrationTests.cs @@ -0,0 +1,87 @@ +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 OrderItemIntegrationTests + { + private readonly HttpClient _client; + + public OrderItemIntegrationTests() + { + var server = new TestServer(new WebHostBuilder().UseStartup()); + _client = server.CreateClient(); + } + + [TestMethod] + public void OrderItemGetAllTest() + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("GET"), "/api/OrderItems/"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + } + + [TestMethod] + [DataRow(1001)] + public void OrderItemGetOneTest(int id) + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("GET"), $"/api/OrderItems/{id}"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + } + + [TestMethod] + public void OrderItemPostTest() + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("POST"), $"/api/OrderItems/"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode); + } + + [TestMethod] + [DataRow(1)] + public void OrderItemPutTest(int id) + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("PUT"), $"/api/OrderItems/{id}"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode); + } + + [TestMethod] + [DataRow(1)] + public void OrderItemDeleteTest(int id) + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("DELETE"), $"/api/OrderItems/{id}"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); + } + } +} diff --git a/H_Plus_Sports.Tests/ProductIntegrationTests.cs b/H_Plus_Sports.Tests/ProductIntegrationTests.cs new file mode 100644 index 0000000..24756f5 --- /dev/null +++ b/H_Plus_Sports.Tests/ProductIntegrationTests.cs @@ -0,0 +1,88 @@ +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()); + _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); + } + } +} diff --git a/H_Plus_Sports.Tests/SalespersonIntegrationTests.cs b/H_Plus_Sports.Tests/SalespersonIntegrationTests.cs new file mode 100644 index 0000000..4c82081 --- /dev/null +++ b/H_Plus_Sports.Tests/SalespersonIntegrationTests.cs @@ -0,0 +1,88 @@ +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 SalespersonIntegrationTests + { + private readonly HttpClient _client; + + public SalespersonIntegrationTests() + { + var server = new TestServer(new WebHostBuilder().UseStartup()); + _client = server.CreateClient(); + } + + [TestMethod] + public void SalespersonGetAllTest() + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("GET"), "/api/Salespersons/"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + } + + [TestMethod] + [DataRow(101)] + public void SalespersonGetOneTest(int id) + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("GET"), $"/api/Salespersons/{id}"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + } + + [TestMethod] + public void SalespersonPostTest() + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("POST"), $"/api/Salespersons/"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode); + } + + [TestMethod] + [DataRow(1)] + public void SalespersonPutTest(int id) + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("PUT"), $"/api/Salespersons/{id}"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode); + } + + [TestMethod] + [DataRow(1)] + public void SalespersonDeleteTest(int id) + { + // Arrange + var request = new HttpRequestMessage(new HttpMethod("DELETE"), $"/api/Salespersons/{id}"); + + // Act + var response = _client.SendAsync(request).Result; + + // Assert + Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); + } + } +}