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 Employee_With_The_Same_Id_Should_Be_Equal_Test() { Employee emp1 = new Employee {Id = 1 }; Employee emp2 = new Employee {Id = 1 }; Assert.AreEqual(emp1.Id, emp2.Id); }
public void Getters_And_Setters_Test() { List<Employee> employees = new List<Employee>(); Employee emp1 = new Employee() { Id = 1, FirstName = "First Employee", }; Employee emp2 = new Employee() { Id = 1, FirstName = "First Employee", }; employees.Add(emp1); employees.Add(emp2); Company comp = new Company() { Id = 1, Name = "Big Company", PhoneNr = "12345678", Employees = employees, Active = true, }; Assert.AreEqual(comp.Id, 1); Assert.AreEqual(comp.Name, "Big Company"); Assert.AreEqual(comp.PhoneNr, "12345678"); Assert.AreEqual(comp.Employees, employees); Assert.AreEqual(comp.Active,true); }
//Checks wether the recieved employee is already within the company list of employees. private bool ContainsEmployee(Company comp, Employee emp) { bool contains = false; contains = comp.Employees.FirstOrDefault(c => c.Address.Equals(emp.Address) && c.BirthDate.Year == emp.BirthDate.Year && c.BirthDate.Month == emp.BirthDate.Month && c.BirthDate.Day == emp.BirthDate.Day && c.FirstName.Equals(emp.FirstName) && c.LastName.Equals(emp.LastName) && c.Phone.Equals(emp.Phone)) != null; return contains; }
public void ShouldFindOneEmployee() { int employeeId = 1; Employee expected = new Employee(); employeeService.Find(employeeId).Returns(expected); Employee actual = employeeService.Find(employeeId); employeeRepository.Received().Find(employeeId); actual.Should().Be(expected); }
public ActionResult Edit(Employee employee) { if (ModelState.IsValid) { this.employeeService.InsertOrUpdate(employee); this.employeeService.Save(); return RedirectToAction("Index"); } return this.View(); }
public void Getters_And_Setters_Test() { Company comp = new Company() { Id = 1, Name = "Big Company", PhoneNr = "12345678", Active = true, }; List<Employee> employees = new List<Employee>(); Employee emp1 = new Employee() { Id = 1, FirstName = "First Employee", }; Employee emp2 = new Employee() { Id = 1, FirstName = "First Employee", }; employees.Add(emp1); employees.Add(emp2); Log log = new Log() { Id = 1, Company = comp, Date = DateTime.Now.Date, Import = true, Employees = employees, Active=true }; Assert.AreEqual(log.Id, 1); Assert.AreEqual(log.Company, comp); Assert.AreEqual(log.Date, DateTime.Now.Date); Assert.AreEqual(log.Import, true); Assert.AreEqual(log.Employees, employees); Assert.AreEqual(log.Active, true); }
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); }
public void Import_Controller_Method_With_Employees() { List<Employee> employees = new List<Employee>(); Employee emp1 = new Employee() { Id = 1000000, FirstName = "TestOneEmp1", 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); var principal = new GenericPrincipal(new GenericIdentity("*****@*****.**"), null); Thread.CurrentPrincipal = principal; var response = FakeImportRequest(employees); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public void Import_Logic_With_Already_Existing_Employee() { List<Employee> employees = new List<Employee>(); //Employee from the seed, which is certain to be in the database alread before the import is done. Employee emp1 = new Employee() { Company = null, Id = 1, FirstName = "Hans", LastName = "Peterson", BirthDate = DateTime.Now.AddYears(-36), Address = "Højvej 22", ZipCode = 6700, City = "Esbjerg", Country = "Danmark", Phone = "56428657", Active = true, Rank = "Programmer" }; employees.Add(emp1); ImportExportLogic imEx = new ImportExportLogic(); EmployeeRepository emprepo = new EmployeeRepository(); var principal = new GenericPrincipal(new GenericIdentity("*****@*****.**"), null); Thread.CurrentPrincipal = principal; int empStartCount = emprepo.GetAll().Count(); var response = imEx.Import(employees); Assert.IsTrue(response); int empEndCount = emprepo.GetAll().Count(); Assert.AreEqual(empStartCount, empEndCount); IEnumerable<Employee> emps = emprepo.GetAll(); Employee emp = emps.FirstOrDefault(c => c.FirstName.Equals("Hans")); Assert.IsTrue(emp != null); }
public HttpResponseMessage Update(Employee empl) { var response = Request.CreateResponse(HttpStatusCode.Accepted, repository.Update(empl)); return response; }
public HttpResponseMessage Add(Employee empl) { var response = Request.CreateResponse(HttpStatusCode.OK, repository.Add(empl)); return response; }
[Test] public void Employee_With_Different_Id_Should_Be_Unequal_And_Have_Different_HashCode_Test() { Employee emp1 = new Employee { Id = 1 }; Employee emp2 = new Employee { Id = 2 }; Assert.AreNotEqual(emp1, emp2); }
public void Getters_And_Setters_Test() { Company comp = new Company() { Id = 1, Name = "Big Company", PhoneNr = "12345678", Active = true, }; List<Log> logs = new List<Log>(); Log log = new Log() { Id = 1, Company = comp, Date = DateTime.Now.Date, Import = true, }; Log log2 = new Log() { Id = 1, Company = comp, Date = DateTime.Now.Date, Import = false, }; logs.Add(log); logs.Add(log2); Employee emp = new Employee() { Id = 1, FirstName = "First ", LastName = "Employee", Country = "Denmark", ZipCode = 6700, City = "Esbjerg", Address = "This Vej 7", BirthDate = DateTime.Now.Date, Rank = "Captain", Phone = "1111111", Company = comp, Active =true, Logs = logs }; Assert.AreEqual(emp.Id, 1); Assert.AreEqual(emp.FirstName, "First "); Assert.AreEqual(emp.LastName, "Employee"); Assert.AreEqual(emp.Country, "Denmark"); Assert.AreEqual(emp.Address, "This Vej 7"); Assert.AreEqual(emp.ZipCode, 6700); Assert.AreEqual(emp.City, "Esbjerg"); Assert.AreEqual(emp.BirthDate, DateTime.Now.Date); Assert.AreEqual(emp.Rank, "Captain"); Assert.AreEqual(emp.Phone,"1111111"); Assert.AreEqual(emp.Company, comp); Assert.IsTrue(emp.Active); Assert.AreEqual(emp.Logs, logs); }