Testing CREATE results

This commit is contained in:
2023-12-12 11:10:28 +01:00
parent 1e46e0bd67
commit 5ebfb7af41

View File

@@ -2,7 +2,7 @@ using NUnit.Framework;
using WD7UVN_HFT_2023241.Models; using WD7UVN_HFT_2023241.Models;
using WD7UVN_HFT_2023241.Logic; using WD7UVN_HFT_2023241.Logic;
using WD7UVN_HFT_2023241.Repository; using WD7UVN_HFT_2023241.Repository;
using Moq; //using Moq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -10,49 +10,218 @@ namespace WD7UVN_HFT_2023241.Test
{ {
public class CRUDTests public class CRUDTests
{ {
Mock<ICRUD> mockCRUD; //Mock<ICRUD> mockCRUD;
LogicServices logic; LogicServices logic;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
var data = new List<Customer>() //var customerData = new List<Customer>()
{ //{
new Customer //new Customer
{ //{
NAME = "Szemed Fénye Optika Kft.", //NAME = "Szemed Fénye Optika Kft.",
ID = 1, //ID = 1,
EMAIL = "info@szemedfenye.hu", //EMAIL = "info@szemedfenye.hu",
PHONE = "+36 30 123 4567", //PHONE = "+36 30 123 4567",
SERVICE_ID = 1 //SERVICE_ID = 1
}, //},
//
new Customer{ //new Customer{
NAME = "DoBox Logisztika Kft.", //NAME = "DoBox Logisztika Kft.",
ID = 2, //ID = 2,
EMAIL = "info@dobox.hu", //EMAIL = "info@dobox.hu",
PHONE = "+36 50 234 5678", //PHONE = "+36 50 234 5678",
SERVICE_ID = 2 //SERVICE_ID = 2
} //}
}.AsQueryable(); //}.AsQueryable();
//
mockCRUD = new Mock<ICRUD>(); //var maintainerTeamData = new List<MaintainerTeam>()
mockCRUD.Setup(p => p.ReadAllCustomers()).Returns(data); //{
logic = new LogicServices(mockCRUD.Object); //new MaintainerTeam{
//ID = 1,
//NAME = "Microsoft Team",
//EMAIL = "microsoft@ourcompany.hu",
//LEADER_ID = 2
//},
//
//new MaintainerTeam{
//ID = 2,
//NAME = "Linux Team",
//LEADER_ID = 4,
//EMAIL = "linux@ourcompany.hu"
//}
//}.AsQueryable();
//
//var serviceData = new List<Service>()
//{
//new Service{
//NAME = "Microsoft Exchange",
//ID = 1,
//ACCOUNT = "admin:password123",
//NOTES = "Currently migrating to EXOnline",
//SERVICE_DOMAIN = "admin.exchange.intranet.szemedfenye.hu",
//PORT = 443,
//IP = "10.42.567.3",
//MAINTAINER_ID = 1
//},
//
//new Service{
//NAME = "OpenLDAP",
//ID = 2,
//ACCOUNT = "ldapadmin:verystrongpassword",
//NOTES = "OpenLDAP directory access protocol on Linux, over SSL",
//SERVICE_DOMAIN = "conf.ldap.intranet.dobox.hu",
//PORT = 636,
//IP = "66.254.114.41",
//MAINTAINER_ID = 2
//}
//}.AsQueryable();
//
//var employeeData = new List<Employee>()
//{
//new Employee{
//ID = 1,
//NAME = "Gipsz Jakab",
//EMAIL = "gipsz.jakab@ourcompany.hu",
//PHONE = "+36 20 345 6789",
//MANAGER_ID = 2,
//MAINTAINER_ID = 1
//},
//
//new Employee{
//NAME = "Nagy Krisztina",
//ID = 2,
//MAINTAINER_ID = 1,
//EMAIL = "nagy.krisztina@ourcompany.hu",
//PHONE = "+36 30 987 6543"
//},
//
//new Employee{
//NAME = "Székely Csaba",
//ID = 3,
//PHONE = "+36 50 8766 5432",
//EMAIL = "szekely.csaba@ourcompany.hu",
//MANAGER_ID = 2,
//MAINTAINER_ID = 1
//},
//
//new Employee{
//NAME = "Marik Tamás",
//ID = 4,
//PHONE = "+36 20 345 6780",
//EMAIL = "marik.tamas@ourcompany.hu",
//MAINTAINER_ID = 2,
//},
//
//new Employee{
//NAME = "Dávid András",
//ID = 5,
//PHONE = "+36 51 865 2876",
//EMAIL = "david.andras@ourcompany.hu",
//MANAGER_ID = 4,
//MAINTAINER_ID = 2
//},
//
//new Employee{
//NAME = "Steiner Zsófia",
//ID = 6,
//PHONE = "+36 20 756 8635",
//MANAGER_ID = 4,
//MAINTAINER_ID = 2
//}
//}.AsQueryable();
//
//mockCRUD = new Mock<ICRUD>();
//
//mockCRUD.Setup(p => p.ReadAllCustomers()).Returns(customerData);
//mockCRUD.Setup(p => p.ReadAllEmployees()).Returns(employeeData);
//mockCRUD.Setup(p => p.ReadAllServices()).Returns(serviceData);
//mockCRUD.Setup(p => p.ReadAllMaintainerTeams()).Returns(maintainerTeamData);
logic = new LogicServices(new CRUD());
} }
[Test] [Test]
public void CreateCustomerTest() public void CreateCustomerTest()
{ {
Customer c = new Customer() var testData = logic.CRUDOperations.ReadAllCustomers();
List<Customer> tmp = new List<Customer>(testData);
Customer s = new Customer()
{
ID = 10,
NAME = "Testing Hungary Kft."
};
tmp.Add(s);
testData.Concat(tmp.AsQueryable());
logic.CRUDOperations.CreateCustomer(s);
Assert.That(logic.CRUDOperations.ReadAllCustomers() == testData);
}
[Test]
public void CreateEmployeeTest()
{
var testData = logic.CRUDOperations.ReadAllEmployees();
List<Employee> tmp = new List<Employee>(testData);
Employee s = new Employee()
{
ID = 10,
NAME = "Teszt Vilmos"
};
tmp.Add(s);
testData.Concat(tmp.AsQueryable());
logic.CRUDOperations.CreateEmployee(s);
Assert.That(logic.CRUDOperations.ReadAllEmployees() == testData);
}
[Test]
public void CreateServiceTest()
{
var testData = logic.CRUDOperations.ReadAllServices();
List<Service> tmp = new List<Service>(testData);
Service s = new Service()
{
ID = 10,
NAME = "System testing"
};
tmp.Add(s);
testData.Concat(tmp.AsQueryable());
logic.CRUDOperations.CreateService(s);
Assert.That(logic.CRUDOperations.ReadAllServices() == testData);
}
[Test]
public void CreateMaintainerTeamTest()
{
var testData = logic.CRUDOperations.ReadAllMaintainerTeams();
List<MaintainerTeam> tmp = new List<MaintainerTeam>(testData);
MaintainerTeam s = new MaintainerTeam()
{
ID = 10,
NAME = "Tesztelő csapat"
};
tmp.Add(s);
testData.Concat(tmp.AsQueryable());
logic.CRUDOperations.CreateMaintainerTeam(s);
foreach (MaintainerTeam x in testData)
{
Console.WriteLine(s);
}
foreach (MaintainerTeam x in logic.CRUDOperations.ReadAllMaintainerTeams())
{ {
NAME = "Teszt Kft.", Console.WriteLine(s);
ID = 3 }
};
logic.CRUDOperations.CreateCustomer(c); Assert.That(logic.CRUDOperations.ReadAllMaintainerTeams() == testData);
mockCRUD.Verify(p => p.CreateCustomer(c), Times.Once);
} }
} }
} }