public void TrackTime_FreelancerBackdating_ShouldReturnFalse() { //arrange string login = "******"; decimal salary = 40_000m; var employee = new FreelancerEmployee(login, salary); UserSession.Sessions.Add(employee); var timeLog = new TimeLog { Date = DateTime.Now.AddDays(-3), WorkingHours = 4, EmployeeLogin = employee.Login, Comment = "Test comment" }; _employeeRepositoryMock.Setup(x => x.GetEmployee(It.Is <string>(y => y == login))) .Returns(new FreelancerEmployee(login, salary)); //act var result = _service.TrackTime(timeLog, login); //assert Assert.IsFalse(result); }
public bool AddFreelancerEmployee(FreelancerEmployee employee) { bool isValid = !string.IsNullOrEmpty(employee.Login) && employee.Salary > 0; if (isValid) { _employeeRepository.AddFreelancer(employee); } return(isValid); }
public void GetFreelancerEmployeeReport_ShouldReturnReportWithOvertime() { //arrange var timesheetRepositoryMock = new Mock <ITimeLogRepository>(); var employeeRepositoryMock = new Mock <IEmployeeRepository>(); var totalBill = 37_500m; // ((200/160 * 30_000m) var totalHours = 200; // 10 * 20 var salary = 30_000m; var employee = new FreelancerEmployee("Иванов", salary); timesheetRepositoryMock.Setup(x => x.GetTimeLogs(It.Is <string>(l => l == employee.Login))) .Returns(() => { var timelogs = new TimeLog[20]; for (int i = 0; i < timelogs.Length; i++) { timelogs[i] = new TimeLog { WorkingHours = 10, Date = new DateTime(2021, 1, 1).AddDays(i), EmployeeLogin = employee.Login, Comment = "Abstract comment" }; } return(timelogs); }); employeeRepositoryMock.Setup(x => x.GetEmployee(It.Is <string>(l => l == employee.Login))) .Returns(() => employee); var service = new ReportService(timesheetRepositoryMock.Object, employeeRepositoryMock.Object); //act var result = service.GetEmployeeReport(employee.Login); //assert Assert.IsNotNull(result); Assert.IsNotNull(result.TimeLogs); Assert.IsNotEmpty(result.TimeLogs); Assert.AreEqual(employee.Login, result.Employee.Login); Assert.AreEqual(totalHours, result.TotalHours); Assert.AreEqual(totalBill, result.Bill); }
public Employee GetEmployee(string lastName) { var data = File.ReadAllText(_path); var dataRows = data.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); Employee employee = null; foreach (var dataRow in dataRows) { if (dataRow.Contains(lastName)) { var dataMembers = dataRow.Split(_delimeter); decimal salary = 0; decimal.TryParse(dataMembers[1], out salary); var position = dataMembers[2]; switch (position) { case "Руководитель": decimal bonus = 0; decimal.TryParse(dataMembers[1], out bonus); employee = new ChiefEmployee(lastName, salary, bonus); break; case "Штатный сотрудник": employee = new StaffEmployee(lastName, salary); break; case "Фрилансер": employee = new FreelancerEmployee(lastName, salary); break; default: break; // Выбрасывать исключение? } break; } } return(employee); }
public void AddFreelancerEmployee_ShouldReturnFalse(string login, decimal salary) { //arrange FreelancerEmployee employee = new FreelancerEmployee(login, salary); var employeeRepositoryMock = new Mock <IEmployeeRepository>(); employeeRepositoryMock .Setup(x => x.AddFreelancer(It.Is <FreelancerEmployee>(y => y == employee))); var service = new EmployeeService(employeeRepositoryMock.Object); //act var result = service.AddFreelancerEmployee(employee); //assert employeeRepositoryMock.Verify(x => x.AddFreelancer(employee), Times.Never); Assert.IsFalse(result); }
public IActionResult AddFreelancer([FromBody] FreelancerEmployee employee) { return(Ok(_employeeService.AddFreelancerEmployee(employee))); }
public ActionResult <bool> AddEmployee(FreelancerEmployee freelancerEmployee) { return(Ok(_employeeService.AddEmployee(freelancerEmployee))); }
public void AddFreelancer(FreelancerEmployee employee) { _context.FreelancerEmployees.Add(employee); _context.SaveChanges(); }