Пример #1
0
        public void HandleDeleteEmployeeVacation_RecalculateWithTwoIssuePerDayTest()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);
            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(0);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления")) {
                BuisnessLogicGlobalEventHandler.Init(ask, UnitOfWorkFactory);

                var nomenclatureType = new ItemsType();
                nomenclatureType.Name = "Тестовый тип номенклатуры";
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature();
                nomenclature.Type = nomenclatureType;
                uow.Save(nomenclature);

                var protectionTools = new ProtectionTools();
                protectionTools.Name = "СИЗ для тестирования";
                protectionTools.AddNomeclature(nomenclature);
                uow.Save(protectionTools);

                var norm     = new Norm();
                var normItem = norm.AddItem(protectionTools);
                normItem.Amount      = 1;
                normItem.NormPeriod  = NormPeriodType.Year;
                normItem.PeriodCount = 1;
                uow.Save(norm);

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);

                var vacationType = new VacationType();
                vacationType.Name = "Тестовый отпуск";
                vacationType.ExcludeFromWearing = true;

                var vacation = new EmployeeVacation();
                vacation.BeginDate    = new DateTime(2019, 2, 1);
                vacation.EndDate      = new DateTime(2019, 2, 10);
                vacation.VacationType = vacationType;
                employee.AddVacation(vacation);
                uow.Save(vacationType);
                uow.Save(vacation);
                uow.Save(employee);
                uow.Commit();

                var warehouseOperation = new WarehouseOperation();
                warehouseOperation.Nomenclature = nomenclature;
                uow.Save(warehouseOperation);

                var expenseOp = new EmployeeIssueOperation();
                expenseOp.OperationTime      = new DateTime(2019, 1, 1, 14, 0, 0);
                expenseOp.AutoWriteoffDate   = new DateTime(2020, 1, 1);
                expenseOp.Employee           = employee;
                expenseOp.Nomenclature       = nomenclature;
                expenseOp.ProtectionTools    = protectionTools;
                expenseOp.NormItem           = normItem;
                expenseOp.Issued             = 1;
                expenseOp.WarehouseOperation = warehouseOperation;
                var graph = IssueGraph.MakeIssueGraph(uow, employee, protectionTools);
                expenseOp.RecalculateDatesOfIssueOperation(graph, baseParameters, ask);
                uow.Save(expenseOp);

                var warehouseOperation2 = new WarehouseOperation();
                warehouseOperation2.Nomenclature = nomenclature;
                uow.Save(warehouseOperation2);

                var expenseOp2 = new EmployeeIssueOperation();
                expenseOp2.OperationTime      = new DateTime(2019, 1, 1, 13, 0, 0);
                expenseOp2.AutoWriteoffDate   = new DateTime(2020, 1, 1);
                expenseOp2.Employee           = employee;
                expenseOp2.Nomenclature       = nomenclature;
                expenseOp2.ProtectionTools    = protectionTools;
                expenseOp2.NormItem           = normItem;
                expenseOp2.Issued             = 1;
                expenseOp2.WarehouseOperation = warehouseOperation2;
                graph = IssueGraph.MakeIssueGraph(uow, employee, protectionTools);
                expenseOp2.RecalculateDatesOfIssueOperation(graph, baseParameters, ask);
                uow.Save(expenseOp2);
                uow.Commit();

                vacation.UpdateRelatedOperations(uow, new EmployeeIssueRepository(), baseParameters, ask);
                uow.Commit();

                Assert.That(employee.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2021, 1, 11)));

                //Выполняем удаление
                employee.Vacations.Remove(vacation);
                uow.Delete(vacation);
                uow.Commit();

                //проверяем данные
                using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления uow2")) {
                    var resultEmployee = uow2.GetById <EmployeeCard>(employee.Id);
                    Assert.That(resultEmployee.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2021, 1, 1)));
                }
            }
        }
Пример #2
0
        public void HandleDeleteEmployeeVacation_RecalculateDatesAndNextIssueTest()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления")) {
                BuisnessLogicGlobalEventHandler.Init(ask, UnitOfWorkFactory);

                var nomenclatureType = new ItemsType();
                nomenclatureType.Name = "Тестовый тип номенклатуры";
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature();
                nomenclature.Type = nomenclatureType;
                uow.Save(nomenclature);

                var protectionTools = new ProtectionTools();
                protectionTools.Name = "СИЗ для тестирования";
                protectionTools.AddNomeclature(nomenclature);
                uow.Save(protectionTools);

                var norm     = new Norm();
                var normItem = norm.AddItem(protectionTools);
                normItem.Amount      = 1;
                normItem.NormPeriod  = NormPeriodType.Month;
                normItem.PeriodCount = 2;
                uow.Save(norm);

                var employee = new EmployeeCard();

                var vacationType = new VacationType();
                vacationType.Name = "Тестовый отпуск";
                vacationType.ExcludeFromWearing = true;

                var vacation = new EmployeeVacation();
                vacation.BeginDate    = new DateTime(2019, 2, 1);
                vacation.EndDate      = new DateTime(2019, 3, 1);
                vacation.VacationType = vacationType;
                employee.AddVacation(vacation);
                uow.Save(vacationType);
                uow.Save(vacation);
                uow.Save(employee);

                var warehouseOperation = new WarehouseOperation();
                warehouseOperation.Nomenclature = nomenclature;
                uow.Save(warehouseOperation);

                var expenseOp = new EmployeeIssueOperation();
                expenseOp.OperationTime      = new DateTime(2019, 1, 1);
                expenseOp.ExpiryByNorm       = new DateTime(2019, 4, 1);
                expenseOp.Employee           = employee;
                expenseOp.Nomenclature       = nomenclature;
                expenseOp.ProtectionTools    = protectionTools;
                expenseOp.NormItem           = normItem;
                expenseOp.Issued             = 1;
                expenseOp.WarehouseOperation = warehouseOperation;
                uow.Save(expenseOp);
                uow.Commit();

                //Выполняем удаление
                employee.Vacations.Remove(vacation);
                uow.Delete(vacation);
                uow.Commit();

                //проверяем данные
                using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления uow2")) {
                    var resultOp = uow2.GetById <EmployeeIssueOperation>(expenseOp.Id);
                    Assert.That(resultOp.ExpiryByNorm, Is.EqualTo(new DateTime(2019, 3, 1)));
                }
            }
        }
        public void UpdateOperations_RecalculeteDatesAfterCreateVacation()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);
            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(0);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

                var nomenclatureType = new ItemsType();
                nomenclatureType.Name = "Тестовый тип номенклатуры";
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature();
                nomenclature.Type = nomenclatureType;
                uow.Save(nomenclature);

                var position1 = new StockPosition(nomenclature, 0, null, null);

                var nomenclature2 = new Nomenclature();
                nomenclature2.Type = nomenclatureType;
                uow.Save(nomenclature2);

                var protectionTools = new ProtectionTools();
                protectionTools.AddNomeclature(nomenclature);
                protectionTools.AddNomeclature(nomenclature2);
                protectionTools.Name = "СИЗ для тестирования";
                uow.Save(protectionTools);

                var position2 = new StockPosition(nomenclature2, 0, null, null);

                var norm     = new Norm();
                var normItem = norm.AddItem(protectionTools);
                normItem.Amount      = 1;
                normItem.NormPeriod  = NormPeriodType.Year;
                normItem.PeriodCount = 1;
                uow.Save(norm);

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);
                uow.Save(employee);
                uow.Commit();

                var income = new Income();
                income.Warehouse = warehouse;
                income.Date      = new DateTime(2017, 1, 1);
                income.Operation = IncomeOperations.Enter;
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount = 5;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var expense = new Expense();
                expense.Warehouse = warehouse;
                expense.Employee  = employee;
                expense.Date      = new DateTime(2018, 5, 10);
                expense.Operation = ExpenseOperations.Employee;
                expense.AddItem(position1, 1);
                expense.AddItem(position2, 1);

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                uow.Save(expense);
                uow.Commit();

                expense.UpdateEmployeeWearItems();
                uow.Commit();

                Assert.That(employee.WorkwearItems[0].NextIssue,
                            Is.EqualTo(new DateTime(2020, 5, 10))
                            );

                //Добавляем новый отпуск на 10 дней.
                var vacationType = new VacationType();
                vacationType.Name = "Тестовый отпуск";
                vacationType.ExcludeFromWearing = true;

                var vacation = new EmployeeVacation();
                vacation.BeginDate    = new DateTime(2019, 2, 1);
                vacation.EndDate      = new DateTime(2019, 2, 10);
                vacation.VacationType = vacationType;
                employee.AddVacation(vacation);
                vacation.UpdateRelatedOperations(uow, new workwear.Repository.Operations.EmployeeIssueRepository(), baseParameters, ask);
                uow.Save(vacationType);
                uow.Save(vacation);
                uow.Save(employee);

                Assert.That(employee.WorkwearItems[0].NextIssue,
                            Is.EqualTo(new DateTime(2020, 5, 20))
                            );
            }
        }