Exemple #1
0
        public void TrackTime_ChiefEmployeeBackdating_ShouldReturnTrue()
        {
            //arrange
            int     workingHourse = 8;
            string  login         = "******";
            decimal salary        = 100_000m;
            decimal bonus         = 20_000m;

            var employee = new ChiefEmployee(login, salary, bonus);
            var timeLog  = new TimeLog
            {
                Date          = DateTime.Now.AddDays(-10),
                WorkingHours  = workingHourse,
                EmployeeLogin = employee.Login,
                Comment       = ""
            };

            UserSession.Sessions.Add(employee);

            _employeeRepositoryMock.Setup(x =>
                                          x.GetEmployee(It.Is <string>(y => y == login)))
            .Returns(new ChiefEmployee(login, salary, bonus));

            //act
            var result = _service.TrackTime(timeLog, login);

            //assert
            _timeLogRepositoryMock.Verify(x => x.Add(timeLog), Times.Once);
            Assert.IsTrue(result);
        }
Exemple #2
0
        public bool AddChiefEmployee(ChiefEmployee employee)
        {
            bool isValid = !string.IsNullOrEmpty(employee.Login) &&
                           employee.Salary > 0 &&
                           employee.Bonus > 0;

            if (isValid)
            {
                _employeeRepository.AddChief(employee);
            }

            return(isValid);
        }
        public void GetChiefEmployeeReport_ShouldReturnReportWithOvertime()
        {
            //arrange
            var timesheetRepositoryMock = new Mock <ITimeLogRepository>();
            var employeeRepositoryMock  = new Mock <IEmployeeRepository>();

            var totalBill  = 120_000m; //  ((160/160 * 100_000m) + ((8 / 160 * 20_000) * 20)
            var totalHours = 180;      // 9 * 20
            var salary     = 100_000m;
            var bonus      = 20_000m;
            var employee   = new ChiefEmployee("Иванов", salary, bonus);

            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  = 9,
                        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);
        }
Exemple #4
0
        public void AddChiefEmployee_ShouldReturnFalse(string login, decimal salary, decimal bonus)
        {
            //arrange
            ChiefEmployee employee = new ChiefEmployee(login, salary, bonus);

            var employeeRepositoryMock = new Mock <IEmployeeRepository>();

            employeeRepositoryMock.Setup(x
                                         => x.AddChief(It.Is <ChiefEmployee>(y
                                                                             => y == employee)));

            var service = new EmployeeService(employeeRepositoryMock.Object);
            //act
            var result = service.AddChiefEmployee(employee);

            //assert
            employeeRepositoryMock.Verify(x
                                          => x.AddChief(employee), Times.Never);
            Assert.IsFalse(result);
        }
Exemple #5
0
        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 IActionResult AddChief([FromBody] ChiefEmployee employee)
 {
     return(Ok(_employeeService.AddChiefEmployee(employee)));
 }
Exemple #7
0
 public ActionResult <bool> AddEmployee(ChiefEmployee chiefEmployee)
 {
     return(Ok(_employeeService.AddEmployee(chiefEmployee)));
 }
Exemple #8
0
 public void AddChief(ChiefEmployee employee)
 {
     _context.ChiefEmployees.Add(employee);
     _context.SaveChanges();
 }