Example #1
0
        public void UpdateOperations_DoNotIncreaseDateWhenRepeatedCallsTest()
        {
            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 sizeType   = new SizeType();
                var heightType = new SizeType();
                uow.Save(sizeType);
                uow.Save(heightType);

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

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

                var size = new Size {
                    SizeType = sizeType
                };
                var height = new Size {
                    SizeType = heightType
                };
                uow.Save(size);
                uow.Save(height);

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

                var position1 = new StockPosition(nomenclature, 0, size, height);
                var position2 = new StockPosition(nomenclature, 0, size, height);

                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 {
                    Warehouse = warehouse,
                    Date      = new DateTime(2017, 1, 1),
                    Operation = IncomeOperations.Enter
                };
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var income2 = new Income {
                    Warehouse = warehouse,
                    Date      = new DateTime(2018, 1, 1),
                    Operation = IncomeOperations.Enter
                };
                var incomeItem2 = income2.AddItem(nomenclature);
                incomeItem2.WearSize = size;
                incomeItem2.Amount   = 5;
                income2.UpdateOperations(uow, ask);
                uow.Save(income2);

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

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

                expense.UpdateOperations(uow, baseParameters, ask);                 //Здесь 2022(неправильно)
                uow.Save(expense);
                uow.Commit();

                expense.UpdateOperations(uow, baseParameters, ask);                 //Здесь 2024(неправильно)
                uow.Save(expense);
                uow.Commit();

                employee.UpdateNextIssue(expense.Items.Select(x => x.ProtectionTools).ToArray());

                //Тут ожидаем предложение перенести дату использование второй номенклатуры на год.
                ask.ReceivedWithAnyArgs().Question(String.Empty);

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