public void RecalculateDatesOfIssueOperation_DontMoveStartOfUseTest()
        {
            var employee = Substitute.For <EmployeeCard>();

            var protectionTools = Substitute.For <ProtectionTools>();

            var norm = new NormItem()
            {
                Amount          = 1,
                NormPeriod      = NormPeriodType.Month,
                PeriodCount     = 24,
                ProtectionTools = protectionTools
            };

            var nomenclature = Substitute.For <Nomenclature>();

            nomenclature.TypeName.Returns("fake");

            var operation1 = Substitute.For <EmployeeIssueOperation>();

            operation1.ProtectionTools.Returns(protectionTools);
            operation1.OperationTime.Returns(new DateTime(2019, 4, 30));
            operation1.StartOfUse.Returns(new DateTime(2019, 4, 30));
            operation1.AutoWriteoffDate.Returns(new DateTime(2021, 4, 30));
            operation1.ExpiryByNorm.Returns(new DateTime(2021, 4, 30));
            operation1.Issued.Returns(1);

            var issue = new EmployeeIssueOperation
            {
                ProtectionTools  = protectionTools,
                Employee         = employee,
                Nomenclature     = nomenclature,
                NormItem         = norm,
                OperationTime    = new DateTime(2021, 4, 20),
                StartOfUse       = new DateTime(2021, 4, 20),
                AutoWriteoffDate = new DateTime(2023, 4, 20),
                ExpiryByNorm     = new DateTime(2023, 4, 20),
                Issued           = 1
            };

            var operations = new List <EmployeeIssueOperation>()
            {
                operation1, issue
            };
            var graph = new IssueGraph(operations);

            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(Arg.Any <string>()).ReturnsForAnyArgs(false);

            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(15);

            issue.RecalculateDatesOfIssueOperation(graph, baseParameters, ask);

            Assert.That(issue.StartOfUse, Is.EqualTo(new DateTime(2021, 4, 20)));
            Assert.That(issue.ExpiryByNorm, Is.EqualTo(new DateTime(2023, 4, 20)));
        }
        public void RecalculateDatesOfIssueOperation_MoveFirstLessNormTest()
        {
            var employee = Substitute.For <EmployeeCard>();

            var protectionTools = Substitute.For <ProtectionTools>();

            var operation1 = Substitute.For <EmployeeIssueOperation>();

            operation1.ProtectionTools.Returns(protectionTools);
            operation1.OperationTime.Returns(new DateTime(2018, 1, 1));
            operation1.AutoWriteoffDate.Returns(new DateTime(2018, 2, 1));
            operation1.Issued.Returns(2);

            var norm = Substitute.For <NormItem>();

            norm.Amount.Returns(2);
            norm.PeriodInMonths.Returns(1);
            norm.CalculateExpireDate(new DateTime(2018, 2, 1)).Returns(new DateTime(2018, 3, 1));

            var nomenclature = Substitute.For <Nomenclature>();

            nomenclature.TypeName.Returns("fake");

            var operation2 = Substitute.For <EmployeeIssueOperation>();

            operation2.ProtectionTools.Returns(protectionTools);
            operation2.OperationTime.Returns(new DateTime(2018, 2, 1));

            var operations = new List <EmployeeIssueOperation>()
            {
                operation1, operation2
            };

            var graph = new IssueGraph(operations);
            var issue = new EmployeeIssueOperation();

            issue.ProtectionTools = protectionTools;
            issue.Employee        = employee;
            issue.Nomenclature    = nomenclature;
            issue.NormItem        = norm;
            issue.OperationTime   = new DateTime(2018, 1, 15);
            issue.Issued          = 2;

            var ask = Substitute.For <IInteractiveQuestion>();

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

            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(0);

            issue.RecalculateDatesOfIssueOperation(graph, baseParameters, ask);

            Assert.That(issue.ExpiryByNorm, Is.EqualTo(new DateTime(2018, 3, 1)));
        }
        public void RecalculateDatesOfIssueOperation_LifeTimeAppendOnVacationTest()
        {
            var vacationType = Substitute.For <VacationType>();

            vacationType.ExcludeFromWearing.Returns(true);

            var employee = Substitute.For <EmployeeCard>();
            var vacation = Substitute.For <EmployeeVacation>();

            vacation.VacationType.Returns(vacationType);
            vacation.Employee.Returns(employee);
            vacation.BeginDate.Returns(new DateTime(2019, 2, 1));
            vacation.EndDate.Returns(new DateTime(2019, 2, 10));
            employee.Vacations.Returns(new List <EmployeeVacation> {
                vacation
            });

            var protectionTools = Substitute.For <ProtectionTools>();

            var norm = new NormItem();

            norm.Amount      = 2;
            norm.PeriodCount = 3;
            norm.NormPeriod  = NormPeriodType.Month;

            var nomenclature = Substitute.For <Nomenclature>();

            nomenclature.TypeName.Returns("fake");

            var operations = new List <EmployeeIssueOperation>()
            {
            };

            var graph = new IssueGraph(operations);
            var issue = new EmployeeIssueOperation();

            issue.Employee        = employee;
            issue.Nomenclature    = nomenclature;
            issue.ProtectionTools = protectionTools;
            issue.NormItem        = norm;
            issue.OperationTime   = new DateTime(2019, 1, 10);
            issue.Issued          = 2;

            var ask = Substitute.For <IInteractiveQuestion>();

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

            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(0);

            issue.RecalculateDatesOfIssueOperation(graph, baseParameters, ask);

            Assert.That(issue.ExpiryByNorm, Is.EqualTo(new DateTime(2019, 4, 20)));
        }
        public void RecalculateDatesOfIssueOperation_LifeTimeAppendProportionalTest()
        {
            var employee = Substitute.For <EmployeeCard>();

            var protectionTools = Substitute.For <ProtectionTools>();

            var operation1 = Substitute.For <EmployeeIssueOperation>();

            operation1.OperationTime.Returns(new DateTime(2018, 1, 1));
            operation1.AutoWriteoffDate.Returns(new DateTime(2018, 2, 1));
            operation1.Issued.Returns(2);

            var norm = new NormItem();

            norm.Amount      = 2;
            norm.PeriodCount = 1;
            norm.NormPeriod  = NormPeriodType.Month;

            var nomenclature = Substitute.For <Nomenclature>();

            nomenclature.TypeName.Returns("fake");

            var operations = new List <EmployeeIssueOperation>()
            {
                operation1
            };

            var graph = new IssueGraph(operations);
            var issue = new EmployeeIssueOperation();

            issue.Employee        = employee;
            issue.Nomenclature    = nomenclature;
            issue.ProtectionTools = protectionTools;
            issue.NormItem        = norm;
            issue.OperationTime   = new DateTime(2018, 3, 10);
            issue.Issued          = 3;

            var ask = Substitute.For <IInteractiveQuestion>();

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

            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(0);

            issue.RecalculateDatesOfIssueOperation(graph, baseParameters, ask);

            Assert.That(issue.ExpiryByNorm, Is.EqualTo(new DateTime(2018, 4, 25)));
        }
Example #5
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)));
                }
            }
        }