public void Import_Logic_With_One_Employee_Correctly() { List<Employee> employees = new List<Employee>(); Employee emp1 = new Employee() {Id = 1000000, FirstName = "TestOneEmp", LastName = "Peterson", BirthDate = DateTime.Now.AddYears(-96), Address = "Højvej 22", ZipCode = 6700, City = "Esbjerg", Country = "Danmark", Phone = "56428657", Active = true, Rank = "Programmer" }; employees.Add(emp1); ImportExportLogic imEx = new ImportExportLogic(); var principal = new GenericPrincipal(new GenericIdentity("*****@*****.**"), null); Thread.CurrentPrincipal = principal; var response = imEx.Import(employees); Assert.IsTrue(response); CompanyRepository comprepo = new CompanyRepository(); Company comp = comprepo.Get("*****@*****.**"); EmployeeRepository emprepo = new EmployeeRepository(); IEnumerable<Employee> emps = emprepo.GetAll(); Employee emp = emps.FirstOrDefault(c => c.FirstName.Equals("TestOneEmp")); Assert.AreEqual(comp.Identity.Email, emp.Company.Identity.Email); LogRepository logrepo = new LogRepository(); IEnumerable<Log> logList = logrepo.GetAll(); bool containsEmp = false; foreach (var log in logList) { foreach (var logEmp in log.Employees) { if (logEmp.FirstName.Equals(emp.FirstName) && log.Import) { containsEmp = true; } } } Assert.IsTrue(containsEmp); }
public void Import_Logic_With_Multiple_Employees_Correctly() { List<Employee> employees = new List<Employee>(); Employee emp1 = new Employee() { Id = 100002, FirstName = "100002 Employee", LastName = "Test", Active = true, Address = "TestRoad", BirthDate = DateTime.Now.AddYears(-36), City = "Esbjerg", Company = null, Country = "Denmark", ZipCode = 2345, Logs = null, Rank = "TestGuy", Phone = "52634189" }; employees.Add(emp1); Employee emp2 = new Employee() { Id = 100003, FirstName = "100003 Employee", LastName = "Test", Active = true, Address = "TestRoad", BirthDate = DateTime.Now.AddYears(-36), City = "Esbjerg", Company = null, Country = "Denmark", ZipCode = 2345, Logs = null, Rank = "TestGuy", Phone = "52634189" }; employees.Add(emp2); ImportExportLogic imEx = new ImportExportLogic(); var principal = new GenericPrincipal(new GenericIdentity("*****@*****.**"), null); Thread.CurrentPrincipal = principal; var response = imEx.Import(employees); Assert.IsTrue(response); CompanyRepository comprepo = new CompanyRepository(); //get the company with Id =1 Company comp = comprepo.Get("*****@*****.**"); EmployeeRepository emprepo = new EmployeeRepository(); IEnumerable<Employee> emps = emprepo.GetAll(); emp1 = emps.FirstOrDefault(c => c.FirstName.Equals("100002 Employee")); emp2 = emps.FirstOrDefault(c => c.FirstName.Equals("100003 Employee")); Assert.AreEqual(comp.Identity.Email, emp1.Company.Identity.Email); Assert.AreEqual(comp.Identity.Email, emp2.Company.Identity.Email); LogRepository logrepo = new LogRepository(); IEnumerable<Log> logList = logrepo.GetAll(); Log newLog = null; bool containsEmp = false; foreach (var log in logList) { foreach (var logEmp in log.Employees) { if (logEmp.FirstName.Equals(emp1.FirstName)) { newLog = log; } } } if (newLog != null && newLog.Import) { foreach (var logEmp in newLog.Employees) { if (logEmp.FirstName.Equals(emp2.FirstName)) { containsEmp = true; } } } Assert.IsTrue(containsEmp); }