public void UpdateNextIssue_NotBreakNextIssueDateAfterRecreateItem() { var operation1 = Substitute.For <EmployeeIssueOperation>(); operation1.OperationTime.Returns(new DateTime(2017, 1, 1)); operation1.AutoWriteoffDate.Returns(new DateTime(2017, 10, 1)); operation1.Issued.Returns(10); var uow = Substitute.For <IUnitOfWork>(); var list = new List <EmployeeIssueOperation> { operation1 }; var graph = new IssueGraph(list); var employee = Substitute.For <EmployeeCard>(); employee.Id.Returns(777); //Необходимо чтобы было более 0, для запроса имеющихся операций. var norm = Substitute.For <NormItem>(); norm.Amount.Returns(10); var item = new EmployeeCardItemTested(); item.EmployeeCard = employee; item.GetIssueGraphForItemFunc = () => graph; item.Created = new DateTime(2018, 1, 15); item.ActiveNormItem = norm; item.UpdateNextIssue(uow); Assert.That(item.NextIssue, Is.EqualTo(new DateTime(2017, 10, 1))); }
public void UpdateNextIssue_WihtoutWriteoffAndWithoutExpiryByNormCase() { var operation1 = Substitute.For <EmployeeIssueOperation>(); operation1.OperationTime.Returns(new DateTime(2018, 1, 1)); operation1.ExpiryByNorm.Returns(x => null); operation1.Issued.Returns(10); var list = new List <EmployeeIssueOperation> { operation1 }; var graph = new IssueGraph(list); var uow = Substitute.For <IUnitOfWork>(); var employee = Substitute.For <EmployeeCard>(); employee.Id.Returns(777); //Необходимо чтобы было более 0, для запроса имеющихся операций. var norm = Substitute.For <NormItem>(); norm.Amount.Returns(10); var item = new EmployeeCardItemTested(); item.EmployeeCard = employee; item.GetIssueGraphForItemFunc = () => graph; item.ActiveNormItem = norm; item.UpdateNextIssue(uow); Assert.That(item.NextIssue, Is.Null); }
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 EmployeeIssueGraphViewModel( INavigationManager navigation, IUnitOfWorkFactory factory, EmployeeCard employee, ProtectionTools protectionTools) : base(navigation) { using (var unitOfWork = factory.CreateWithoutRoot()) Intervals = IssueGraph.MakeIssueGraph(unitOfWork, employee, protectionTools).Intervals; Title = $"Хронология {employee.ShortName} - {protectionTools.Name}"; }
public void FineIntervalForDateReturnNullBeforeIntervalsTest() { var graph = new IssueGraph(); graph.Intervals.Add(new GraphInterval { StartDate = new DateTime(2018, 4, 1) }); Assert.That(graph.IntervalOfDate(new DateTime(2018, 2, 2)), Is.Null); }
public DateTime FineIntervalForDateTest(DateTime fineDate, DateTime[] intervalDates) { var graph = new IssueGraph(); graph.Intervals.AddRange(intervalDates.Select(x => new GraphInterval { StartDate = x })); return(graph.IntervalOfDate(fineDate).StartDate); }
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_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 AmountAtDay_OverrideBeforeInOneDayTest() { var operation1 = Substitute.For <EmployeeIssueOperation>(); operation1.Id.Returns(1); operation1.OperationTime.Returns(new DateTime(2017, 11, 28)); operation1.StartOfUse.Returns(new DateTime(2017, 11, 28)); operation1.ExpiryByNorm.Returns(new DateTime(2020, 11, 28)); operation1.AutoWriteoffDate.Returns(new DateTime(2020, 11, 28)); operation1.Issued.Returns(1); var operation3 = Substitute.For <EmployeeIssueOperation>(); operation3.Id.Returns(3); operation3.OperationTime.Returns(new DateTime(2019, 12, 16, 0, 0, 0)); operation3.StartOfUse.Returns(new DateTime(2019, 12, 16)); operation3.ExpiryByNorm.Returns(new DateTime(2021, 12, 16)); operation3.AutoWriteoffDate.Returns(new DateTime(2021, 12, 16)); operation3.Issued.Returns(1); var operationOverride = Substitute.For <EmployeeIssueOperation>(); operationOverride.Id.Returns(4); operationOverride.OperationTime.Returns(new DateTime(2019, 12, 16, 17, 21, 0)); operationOverride.StartOfUse.Returns(new DateTime(2019, 12, 16)); operationOverride.ExpiryByNorm.Returns(new DateTime(2021, 1, 10)); operationOverride.AutoWriteoffDate.Returns(new DateTime(2021, 1, 10)); operationOverride.OverrideBefore.Returns(true); operationOverride.Issued.Returns(5); var list = new List <EmployeeIssueOperation>() { operation1, operation3, operationOverride }; var graph = new IssueGraph(list); //Проверяем корректное начисление количества Assert.That(graph.UsedAmountAtEndOfDay(new DateTime(2019, 12, 15)), Is.EqualTo(1)); Assert.That(graph.AmountAtEndOfDay(new DateTime(2019, 12, 16)), Is.EqualTo(5)); Assert.That(graph.UsedAmountAtEndOfDay(new DateTime(2020, 1, 15)), Is.EqualTo(5)); Assert.That(graph.UsedAmountAtEndOfDay(new DateTime(2021, 1, 15)), Is.EqualTo(0)); //Проверяем что не создали пустых интервалов. var last = graph.OrderedIntervals.Last(); Assert.That(last.StartDate, Is.EqualTo(new DateTime(2021, 1, 10))); //Проверяем что имеется отметка что данный интервал сбрасывает предыдущую историю. var beforeLast = graph.OrderedIntervalsReverse.Skip(1).First(); Assert.That(beforeLast.Reset, Is.True); }
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))); }
public void MakeIssueGraph_UseManualOperationsTest() { using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) { 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 employee = new EmployeeCard(); uow.Save(employee); //Операция без номеклатуры var manualOp = new EmployeeIssueOperation(); manualOp.OperationTime = new DateTime(2019, 1, 1, 14, 0, 0); manualOp.AutoWriteoffDate = new DateTime(2020, 1, 1); manualOp.Employee = employee; manualOp.ProtectionTools = protectionTools; manualOp.Issued = 1; manualOp.OverrideBefore = true; uow.Save(manualOp); var expenseOp = new EmployeeIssueOperation(); expenseOp.OperationTime = new DateTime(2020, 1, 1, 13, 0, 0); expenseOp.AutoWriteoffDate = new DateTime(2021, 1, 1); expenseOp.Employee = employee; expenseOp.Nomenclature = nomenclature; expenseOp.ProtectionTools = protectionTools; expenseOp.Issued = 1; uow.Save(expenseOp); uow.Commit(); var graph = IssueGraph.MakeIssueGraph(uow, employee, protectionTools); Assert.That(graph.Intervals.Count, Is.EqualTo(3)); var first = graph.OrderedIntervals.First(); Assert.That(first.StartDate, Is.EqualTo(new DateTime(2019, 1, 1))); } }
public void UsedAmountAtEndOfDay_IgnoreTimeTest() { var operation1 = Substitute.For <EmployeeIssueOperation>(); operation1.OperationTime.Returns(new DateTime(2018, 1, 1, 9, 0, 0)); operation1.StartOfUse.Returns(new DateTime(2018, 1, 1, 14, 0, 0)); operation1.AutoWriteoffDate.Returns(new DateTime(2018, 2, 1)); operation1.Issued.Returns(2); var list = new List <EmployeeIssueOperation>() { operation1 }; var graph = new IssueGraph(list); Assert.That(graph.UsedAmountAtEndOfDay(new DateTime(2018, 1, 1)), Is.EqualTo(2)); }
public void IssueGraphConstructor_ExistEndingIntervalWithZeroAmountTest() { var operation1 = Substitute.For <EmployeeIssueOperation>(); operation1.OperationTime.Returns(new DateTime(2018, 1, 1)); operation1.AutoWriteoffDate.Returns(new DateTime(2018, 2, 1)); operation1.Issued.Returns(10); var list = new List <EmployeeIssueOperation>() { operation1 }; var graph = new IssueGraph(list); Assert.That(graph.OrderedIntervals.Last().CurrentCount, Is.EqualTo(0), "Количество в последнем интервале должно быть 0, при наличии автосписания."); Assert.That(graph.OrderedIntervals.First().CurrentCount, Is.EqualTo(10), "Количество в первом интервале должно быть 10."); }
public void AmountAtDay_OverrideBeforeTest() { var operation1 = Substitute.For <EmployeeIssueOperation>(); operation1.Id.Returns(1); operation1.OperationTime.Returns(new DateTime(2017, 11, 28)); operation1.StartOfUse.Returns(new DateTime(2017, 11, 28)); operation1.ExpiryByNorm.Returns(new DateTime(2020, 11, 28)); operation1.AutoWriteoffDate.Returns(new DateTime(2020, 11, 28)); operation1.Issued.Returns(1); var operation3 = Substitute.For <EmployeeIssueOperation>(); operation3.Id.Returns(3); operation3.OperationTime.Returns(new DateTime(2018, 12, 16, 17, 51, 0)); operation3.StartOfUse.Returns(new DateTime(2018, 12, 16)); operation3.ExpiryByNorm.Returns(new DateTime(2021, 12, 16)); operation3.AutoWriteoffDate.Returns(new DateTime(2021, 12, 16)); operation3.Issued.Returns(1); var operationOverride = Substitute.For <EmployeeIssueOperation>(); operationOverride.Id.Returns(4); operationOverride.OperationTime.Returns(new DateTime(2019, 12, 16, 17, 21, 0)); operationOverride.StartOfUse.Returns(new DateTime(2019, 12, 16)); operationOverride.ExpiryByNorm.Returns(new DateTime(2021, 1, 10)); operationOverride.AutoWriteoffDate.Returns(new DateTime(2021, 1, 10)); operationOverride.OverrideBefore.Returns(true); operationOverride.Issued.Returns(5); var list = new List <EmployeeIssueOperation>() { operation1, operation3, operationOverride }; var graph = new IssueGraph(list); //Проверяем корректное начисление количества Assert.That(graph.UsedAmountAtEndOfDay(new DateTime(2019, 12, 15)), Is.EqualTo(2)); Assert.That(graph.AmountAtEndOfDay(new DateTime(2019, 12, 16)), Is.EqualTo(5)); Assert.That(graph.UsedAmountAtEndOfDay(new DateTime(2020, 1, 15)), Is.EqualTo(5)); Assert.That(graph.UsedAmountAtEndOfDay(new DateTime(2021, 1, 15)), Is.EqualTo(0)); //Проверяем что не создали пустых интервалов. var last = graph.OrderedIntervals.Last(); Assert.That(last.StartDate, Is.EqualTo(new DateTime(2021, 1, 10))); }
public void IssuedAndWriteofAtDay_ShowAllMovmentsInOneDayTest() { var operation1 = Substitute.For <EmployeeIssueOperation>(); operation1.Id.Returns(1); operation1.OperationTime.Returns(new DateTime(2017, 11, 28)); operation1.Issued.Returns(1); var operation2 = Substitute.For <EmployeeIssueOperation>(); operation2.Id.Returns(2); operation2.OperationTime.Returns(new DateTime(2018, 12, 16)); operation2.IssuedOperation.Returns(operation1); operation2.Returned.Returns(1); var operation3 = Substitute.For <EmployeeIssueOperation>(); operation3.Id.Returns(3); operation3.OperationTime.Returns(new DateTime(2018, 12, 16, 17, 51, 0)); operation3.Issued.Returns(1); var operation4 = Substitute.For <EmployeeIssueOperation>(); operation4.Id.Returns(4); operation4.OperationTime.Returns(new DateTime(2018, 12, 16, 17, 21, 0)); operation4.IssuedOperation.Returns(operation3); operation4.Returned.Returns(1); var operation5 = Substitute.For <EmployeeIssueOperation>(); operation5.Id.Returns(5); operation5.OperationTime.Returns(new DateTime(2018, 12, 16)); operation5.Issued.Returns(2); var list = new List <EmployeeIssueOperation>() { operation1, operation2, operation3, operation4, operation5 }; var graph = new IssueGraph(list); //Assert.That(graph.Intervals.Count, Is.GreaterThanOrEqualTo(3)); Assert.That(graph.Intervals.Last().Issued, Is.EqualTo(3)); Assert.That(graph.Intervals.Last().WriteOff, Is.EqualTo(2)); }
public void UpdateNextIssue_MoveDateToLeaveEndCase() { var operation1 = Substitute.For <EmployeeIssueOperation>(); operation1.OperationTime.Returns(new DateTime(2018, 1, 1)); operation1.AutoWriteoffDate.Returns(new DateTime(2018, 2, 1)); operation1.Issued.Returns(10); var list = new List <EmployeeIssueOperation> { operation1 }; var graph = new IssueGraph(list); var uow = Substitute.For <IUnitOfWork>(); var employee = Substitute.For <EmployeeCard>(); employee.Id.Returns(777); //Необходимо чтобы было более 0, для запроса имеющихся операций. var vacation = Substitute.For <EmployeeVacation>(); vacation.Employee.Returns(employee); vacation.BeginDate.Returns(new DateTime(2018, 1, 15)); vacation.EndDate.Returns(new DateTime(2018, 2, 15)); employee.Vacations.Returns(new List <EmployeeVacation> { vacation }); var norm = Substitute.For <NormItem>(); norm.Amount.Returns(10); var item = new EmployeeCardItemTested(); item.EmployeeCard = employee; item.GetIssueGraphForItemFunc = () => graph; item.ActiveNormItem = norm; item.UpdateNextIssue(uow); Assert.That(item.NextIssue, Is.EqualTo(new DateTime(2018, 2, 16))); }
public void IssueGraphConstructor_Create3InntervalsTest() { var operation1 = Substitute.For <EmployeeIssueOperation>(); operation1.OperationTime.Returns(new DateTime(2018, 1, 1)); operation1.AutoWriteoffDate.Returns(new DateTime(2018, 2, 1)); operation1.Issued.Returns(10); var operation2 = Substitute.For <EmployeeIssueOperation>(); operation2.OperationTime.Returns(new DateTime(2018, 1, 15)); operation2.Returned.Returns(2); var list = new List <EmployeeIssueOperation>() { operation1, operation2 }; var graph = new IssueGraph(list); Assert.That(graph.Intervals.Count, Is.GreaterThanOrEqualTo(3)); Assert.That(graph.Intervals.Last().StartDate, Is.EqualTo(new DateTime(2018, 2, 1))); Assert.That(graph.Intervals[1].StartDate, Is.EqualTo(new DateTime(2018, 1, 15))); }
public void IssueGraphConstructor_CraeteOnlyOneIntervalForOneDayTest() { var operation1 = Substitute.For <EmployeeIssueOperation>(); operation1.OperationTime.Returns(new DateTime(2018, 1, 1)); operation1.AutoWriteoffDate.Returns(new DateTime(2018, 2, 1)); operation1.Issued.Returns(1); var operation2 = Substitute.For <EmployeeIssueOperation>(); operation2.OperationTime.Returns(new DateTime(2018, 1, 1, 17, 0, 0)); operation2.AutoWriteoffDate.Returns(new DateTime(2018, 2, 1, 18, 1, 1)); operation2.Issued.Returns(2); var list = new List <EmployeeIssueOperation>() { operation1, operation2 }; var graph = new IssueGraph(list); Assert.That(graph.Intervals.Count, Is.EqualTo(2)); Assert.That(graph.Intervals.First().StartDate, Is.EqualTo(new DateTime(2018, 1, 1))); Assert.That(graph.Intervals.Last().StartDate, Is.EqualTo(new DateTime(2018, 2, 1))); }
public void RecalculateLastIssue(EmployeeCardItem row) { var operation = row.LastIssueOperation; //Если строку нормы по которой выдавали удалили, пытаемся пере-подвязать к имеющийся совпадающей по СИЗ if (!row.EmployeeCard.WorkwearItems.Any(x => x.ActiveNormItem.IsSame(operation.NormItem))) { if (row.EmployeeCard.WorkwearItems.Any(x => x.ProtectionTools.Id == operation.ProtectionTools.Id)) { var norm = row.EmployeeCard.WorkwearItems .Where(x => x.ProtectionTools.Id == operation.ProtectionTools.Id) .Select(x => x.ActiveNormItem) .FirstOrDefault(); if (norm != null) { operation.NormItem = norm; } } } var graph = IssueGraph.MakeIssueGraph(UoW, row.EmployeeCard, operation.ProtectionTools); operation.RecalculateDatesOfIssueOperation(graph, BaseParameters, interactive); row.UpdateNextIssue(UoW); }
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))); } } }
void UpdateLastIssue(EmployeeProcessingJournalNode[] nodes) { var progressPage = NavigationManager.OpenViewModel <ProgressWindowViewModel>(null); var progress = progressPage.ViewModel.Progress; loggerProcessing.Info($"Пересчет сроков носки получного для {nodes.Length} сотрудников"); loggerProcessing.Info($"База данных: {dataBaseInfo.Name}"); progress.Start(nodes.Length + 2, text: "Загружаем сотрудников"); var employees = UoW.GetById <EmployeeCard>(nodes.Select(x => x.Id)).ToArray(); progress.Add(text: $"Получаем последние выдачи"); var employeeIssueRepository = AutofacScope.Resolve <EmployeeIssueRepository>(new TypedParameter(typeof(IUnitOfWork), UoW)); var operations = employeeIssueRepository.GetLastIssueOperationsForEmployee(employees); int step = 0; foreach (var employee in employees) { progress.Add(text: $"Обработка {employee.ShortName}"); step++; var employeeOperations = operations.Where(x => x.Employee.IsSame(employee)).ToList(); if (employeeOperations.Count == 0) { Results[employee.Id] = "Нет выданного"; continue; } int changes = 0; foreach (var operation in employeeOperations) { if (operation.ProtectionTools == null) { continue; } var oldDate = operation.ExpiryByNorm; var graph = IssueGraph.MakeIssueGraph(UoW, employee, operation.ProtectionTools); operation.RecalculateDatesOfIssueOperation(graph, baseParameters, interactive); if (operation.ExpiryByNorm?.Date != oldDate?.Date) { UoW.Save(operation); loggerProcessing.Info($"Изменена дата окончания носки с {oldDate:d} на {operation.ExpiryByNorm:d} для выдачи {operation.OperationTime} [{operation.Title}]"); changes++; var item = employee.WorkwearItems.FirstOrDefault(x => x.ProtectionTools.IsSame(operation.ProtectionTools)); if (item != null) { var lastDate = item.NextIssue; item.UpdateNextIssue(UoW); if (item.NextIssue?.Date != lastDate?.Date) { loggerProcessing.Info($"Изменена дата следующей выдачи с {lastDate:d} на {item.NextIssue:d} для потребности [{item.Title}]"); } } } } if (changes > 0) { Results[employee.Id] = NumberToTextRus.FormatCase(changes, "изменена {0} дата", "изменено {0} даты", "изменено {0} дат"); UoW.Save(employee); } else { Results[employee.Id] = "Без изменений"; } if (step % 10 == 0) { UoW.Commit(); } } progress.Add(text: "Готово"); UoW.Commit(); NavigationManager.ForceClosePage(progressPage, CloseSource.FromParentPage); Refresh(); }