public void GetReferencedDocuments_WriteOffTest() { var interactive = Substitute.For <IInteractiveQuestion>(); interactive.Question(string.Empty).ReturnsForAnyArgs(true); var baseParameters = Substitute.For <BaseParameters>(); using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) { var warehouse = new Warehouse(); uow.Save(warehouse); var nomenclatureType = new ItemsType { Name = "Тестовый тип номенклатуры" }; uow.Save(nomenclatureType); var nomenclature = new Nomenclature { Type = nomenclatureType }; uow.Save(nomenclature); var employee = new EmployeeCard(); uow.Save(employee); var expense = new Expense { Date = new DateTime(2021, 9, 10), Employee = employee, Operation = ExpenseOperations.Employee, Warehouse = warehouse, }; var size = new Size(); var height = new Size(); uow.Save(size); uow.Save(height); var stockPosition = new StockPosition(nomenclature, 0, size, height); var item = expense.AddItem(stockPosition, 10); expense.UpdateOperations(uow, baseParameters, interactive); uow.Save(expense); //Списываем 3 штуки var writeoff = new Writeoff() { Date = new DateTime(2021, 9, 11), }; var writeoffItem = writeoff.AddItem(item.EmployeeIssueOperation, 2); writeoff.UpdateOperations(uow); uow.Save(writeoff); uow.Commit(); var repository = new EmployeeIssueRepository(uow); var result = repository.GetReferencedDocuments(writeoffItem.EmployeeWriteoffOperation.Id); Assert.That(result.First().DocumentType, Is.EqualTo(StokDocumentType.WriteoffDoc)); Assert.That(result.First().DocumentId, Is.EqualTo(writeoff.Id)); Assert.That(result.First().ItemId, Is.EqualTo(writeoffItem.Id)); } }
static void Main(string[] args) { //Currency Test CurrencyRepository currencyRepo = new CurrencyRepository(); Currency EUR = currencyRepo.GetCurrencyWithName("EUR"); //Trip Test PersonRepository repo = new PersonRepository(); repo.AddPerson("Pieter"); repo.AddPerson("Margaux"); Person Pieter = repo.GetPerson(0); Person Margaux = repo.GetPerson(1); TripRepository tripRepo = new TripRepository(); tripRepo.AddTrip("Parijs", EUR); Trip Parijs = tripRepo.GetTrip(0); Parijs.AddPersonToTrip(Pieter); Parijs.AddPersonToTrip(Margaux); // "m" == decimal number Expense Resto = new Expense(Pieter, Parijs, EUR); Resto.AddItem("Pasta", 8.05m, Pieter); Resto.AddItem("Pasta", 8.05m, Margaux); Resto.AddItem("Wine", 8.05m, Margaux); Resto.AddItem("Ice cream", 5.00m, Margaux); Parijs.AddExpenseToTrip(Resto); Expense Museum = new Expense(Margaux, Parijs, EUR); Museum.AddItem("Entry", 12m, Pieter); Museum.AddItem("Entry", 12m, Margaux); Parijs.AddExpenseToTrip(Museum); Pieter.AddTransaction(Margaux, 2); var owes = Pieter.GetOwesPersonInCurrency(currencyRepo.GetCurrencyWithName("EUR")); Console.WriteLine(""); }
public void UpdateOperations_IssuingMultipleRows_TwoNomenclatureSameNeedsTest() { var ask = Substitute.For <IInteractiveQuestion>(); ask.Question(string.Empty).ReturnsForAnyArgs(true); 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 position1 = new StockPosition(nomenclature, 0, size, height); var nomenclature2 = new Nomenclature { Type = nomenclatureType }; uow.Save(nomenclature2); var position2 = new StockPosition(nomenclature2, 0, size, height); var protectionTools = new ProtectionTools { Name = "СИЗ для тестирования" }; protectionTools.AddNomeclature(nomenclature); protectionTools.AddNomeclature(nomenclature2); 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); uow.Save(employee); uow.Commit(); var employeeSize = new EmployeeSize { Size = size, SizeType = sizeType, Employee = employee }; var employeeHeight = new EmployeeSize { Size = height, SizeType = heightType, Employee = employee }; employee.Sizes.Add(employeeSize); employee.Sizes.Add(employeeHeight); var income = new Income { Warehouse = warehouse, Date = new DateTime(2017, 1, 1), 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 { Operation = ExpenseOperations.Employee, Warehouse = warehouse, Employee = employee, Date = new DateTime(2018, 10, 22) }; expense.AddItem(position1, 1); expense.AddItem(position2, 1); var baseParameters = Substitute.For <BaseParameters>(); baseParameters.ColDayAheadOfShedule.Returns(0); //Обновление операций expense.UpdateOperations(uow, baseParameters, ask); uow.Save(expense); uow.Commit(); expense.UpdateEmployeeWearItems(); //Тут ожидаем предложение перенести дату использование второй номенклатуры на год. ask.ReceivedWithAnyArgs().Question(String.Empty); Assert.That(employee.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2020, 10, 22)) ); } }
public void IssueAndCreateIssuanceSheetTest() { 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, HeightType = heightType }; uow.Save(nomenclatureType); var nomenclature = new Nomenclature { Type = nomenclatureType }; uow.Save(nomenclature); var protectionTools = new ProtectionTools { Name = "СИЗ для тестирования" }; protectionTools.AddNomeclature(nomenclature); uow.Save(protectionTools); var size = new Size { SizeType = sizeType }; var height = new Size { SizeType = heightType }; uow.Save(size); uow.Save(height); var position1 = 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 expense = new Expense { Operation = ExpenseOperations.Employee, Warehouse = warehouse, Employee = employee, Date = new DateTime(2018, 10, 22) }; var expenseItem = expense.AddItem(position1, 1); expense.CreateIssuanceSheet(null); //Обновление операций expense.UpdateOperations(uow, baseParameters, ask); expense.UpdateIssuanceSheet(); uow.Save(expense.IssuanceSheet); uow.Save(expense); uow.Commit(); expense.UpdateEmployeeWearItems(); uow.Commit(); Assert.That(expense.IssuanceSheet, Is.Not.Null); var issuanceItem = expense.IssuanceSheet.Items.First(); Assert.That(issuanceItem.ExpenseItem, Is.EqualTo(expenseItem)); } }
public void UpdateEmployeeWearItems_NextIssueDiffIdsTest() { NewSessionWithSameDB(); var ask = Substitute.For <IInteractiveQuestion>(); ask.Question(string.Empty).ReturnsForAnyArgs(true); 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); //Поднимаем id номенклатуры до 2. uow.Save(new Nomenclature()); 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 position1 = new StockPosition(nomenclature, 0, size, height); //Поднимаем id сиза до 3. uow.Save(new ProtectionTools { Name = "Id = 1" }); uow.Save(new ProtectionTools { Name = "Id = 2" }); var protectionTools = new 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 = 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 expense = new Expense { Operation = ExpenseOperations.Employee, Warehouse = warehouse, Employee = employee, Date = new DateTime(2018, 10, 22) }; expense.AddItem(position1, 1); var baseParameters = Substitute.For <BaseParameters>(); baseParameters.ColDayAheadOfShedule.Returns(0); //Обновление операций expense.UpdateOperations(uow, baseParameters, ask); uow.Save(expense); uow.Commit(); expense.UpdateEmployeeWearItems(); uow.Commit(); using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot()) { var employeeTest = uow2.GetById <EmployeeCard>(employee.Id); Assert.That(employeeTest.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2018, 11, 22))); } } }
public void IssuingToSubdivisionTest() { 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(); uow.Save(sizeType); var nomenclatureType = new ItemsType { Name = "Тестовый тип номенклатуры", SizeType = sizeType }; uow.Save(nomenclatureType); var nomenclature = new Nomenclature { Name = "Тестовая номеклатура", Type = nomenclatureType }; uow.Save(nomenclature); var size = new Size { SizeType = sizeType }; var height = new Size(); uow.Save(size); uow.Save(height); var position1 = new StockPosition(nomenclature, 0, size, height); var subdivision = new Subdivision { Name = "Тестовое подразделение" }; uow.Save(subdivision); var place = new SubdivisionPlace { Name = "Тестовое место", Subdivision = subdivision }; uow.Save(place); 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 expense = new Expense { Operation = ExpenseOperations.Object, Warehouse = warehouse, Subdivision = subdivision, Date = new DateTime(2018, 10, 22) }; var item1 = expense.AddItem(position1, 1); item1.SubdivisionPlace = place; //Обновление операций expense.UpdateOperations(uow, baseParameters, ask); uow.Save(expense); uow.Commit(); var listed = SubdivisionRepository.ItemsBalance(uow, subdivision); var balance = listed.First(); Assert.That(balance.Amount, Is.EqualTo(1)); Assert.That(balance.NomeclatureName, Is.EqualTo("Тестовая номеклатура")); Assert.That(balance.Place, Is.EqualTo("Тестовое место")); Assert.That(balance.WearPercent, Is.EqualTo(0m)); } }
public void AddItem(string itemName, decimal price, Person whoConsumedItem) { Expense.AddItem(itemName, price, whoConsumedItem); UpdateItems(); }
public void WriteoffMainTest() { var ask = Substitute.For <IInteractiveQuestion>(); ask.Question(string.Empty).ReturnsForAnyArgs(true); var baseParameters = Substitute.For <BaseParameters>(); using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) { var warehouse = new Warehouse(); uow.Save(warehouse); var nomenclatureType = new ItemsType { Name = "Тестовый тип номенклатуры" }; uow.Save(nomenclatureType); var nomenclature = new Nomenclature { Type = nomenclatureType }; uow.Save(nomenclature); var size = new Size(); var height = new Size(); uow.Save(size); uow.Save(height); var position1 = new StockPosition(nomenclature, 0, size, height); var protectionTools = new ProtectionTools { Name = "СИЗ для тестирования" }; protectionTools.AddNomeclature(nomenclature); uow.Save(protectionTools); var employee = new EmployeeCard(); 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 expense = new Expense { Operation = ExpenseOperations.Employee, Warehouse = warehouse, Employee = employee, Date = new DateTime(2018, 10, 22) }; var item = expense.AddItem(position1, 3); //Обновление операций expense.UpdateOperations(uow, baseParameters, ask); uow.Save(expense); uow.Commit(); var balance = EmployeeRepository.ItemsBalance(uow, employee, new DateTime(2018, 10, 30)); Assert.That(balance.First().Amount, Is.EqualTo(3)); //Списываем var writeoff = new Writeoff { Date = new DateTime(2018, 10, 25) }; writeoff.AddItem(item.EmployeeIssueOperation, 1); //Обновление операций writeoff.UpdateOperations(uow); uow.Save(writeoff); uow.Commit(); var balanceAfter = EmployeeRepository.ItemsBalance(uow, employee, new DateTime(2018, 10, 30)); Assert.That(balanceAfter.First().Amount, Is.EqualTo(2)); } }
public void UpdateOperations_DeleteRowTest() { 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 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 nomenclatureType2 = new ItemsType(); nomenclatureType2.Name = "Тестовый тип номенклатуры2"; uow.Save(nomenclatureType2); var nomenclature2 = new Nomenclature(); nomenclature2.Type = nomenclatureType2; uow.Save(nomenclature2); var protectionTools1 = new ProtectionTools(); protectionTools1.Name = "СИЗ для тестирования"; protectionTools1.AddNomeclature(nomenclature); uow.Save(protectionTools1); var protectionTools2 = new ProtectionTools(); protectionTools2.Name = "СИЗ для тестирования2"; protectionTools2.AddNomeclature(nomenclature2); uow.Save(protectionTools2); var position2 = new StockPosition(nomenclature2, 0, null, null); var norm = new Norm(); var normItem = norm.AddItem(protectionTools1); normItem.Amount = 1; normItem.NormPeriod = NormPeriodType.Year; normItem.PeriodCount = 1; var normItem2 = norm.AddItem(protectionTools2); normItem2.Amount = 1; normItem2.NormPeriod = NormPeriodType.Month; normItem2.PeriodCount = 4; uow.Save(norm); var employee = new EmployeeCard(); employee.HireDate = new DateTime(2018, 1, 15); 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 = 10; income.UpdateOperations(uow, ask); uow.Save(income); var expense = new Expense(); expense.Warehouse = warehouse; expense.Employee = employee; expense.Date = new DateTime(2018, 4, 22); expense.Operation = ExpenseOperations.Employee; expense.AddItem(position1, 1); expense.AddItem(position2, 1); //Обновление операций expense.UpdateOperations(uow, baseParameters, ask); uow.Save(expense); uow.Commit(); expense.UpdateEmployeeWearItems(); employee.WorkwearItems.First(e => e.ProtectionTools.IsSame(protectionTools2)).Created = new DateTime(2018, 4, 22); uow.Save(expense.Employee); uow.Commit(); Assert.That(employee.WorkwearItems.First(e => e.ProtectionTools.IsSame(protectionTools2)).NextIssue, Is.EqualTo(new DateTime(2018, 8, 22)) ); //Выполняем удаление expense.RemoveItem(expense.Items.First(e => e.Nomenclature.Type.IsSame(nomenclatureType2))); uow.Save(expense); uow.Commit(); //проверяем данные using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления uow2")) { var resultEmployee = uow2.GetById <EmployeeCard>(employee.Id); Assert.That(resultEmployee.WorkwearItems.First(e => e.ProtectionTools.IsSame(protectionTools2)).NextIssue, Is.EqualTo(new DateTime(2018, 4, 22))); } } }
public void UpdateEmployeeWearItems_NextIssueDiffIdsTest() { NewSessionWithSameDB(); var ask = Substitute.For <IInteractiveQuestion>(); ask.Question(string.Empty).ReturnsForAnyArgs(true); using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) { var warehouse = new Warehouse(); uow.Save(warehouse); var nomenclatureType = new ItemsType { Name = "Тестовый тип номенклатуры" }; uow.Save(nomenclatureType); var nomenclature = new Nomenclature { Type = nomenclatureType, Name = "Тестовая номенклатура" }; uow.Save(nomenclature); var protectionTools = new 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 = 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 baseParameters = Substitute.For <BaseParameters>(); baseParameters.ColDayAheadOfShedule.Returns(0); employee.FillWearInStockInfo(uow, baseParameters, warehouse, new DateTime(2018, 10, 22)); var expense = new Expense { Operation = ExpenseOperations.Employee, Warehouse = warehouse, Employee = employee, Date = new DateTime(2018, 10, 22) }; var itemExpense = expense.AddItem(employee.WorkwearItems.First(), baseParameters); itemExpense.Nomenclature = nomenclature; itemExpense.Amount = 1; //Обновление операций expense.UpdateOperations(uow, baseParameters, ask); uow.Save(expense); uow.Commit(); expense.UpdateEmployeeWearItems(); uow.Commit(); using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot()) { var employeeTest = uow2.GetById <EmployeeCard>(employee.Id); Assert.That(employeeTest.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2018, 11, 22))); } var returnOnStock = new Income { Operation = IncomeOperations.Return, Warehouse = warehouse, EmployeeCard = employee, Date = new DateTime(2018, 11, 2) }; returnOnStock.AddItem(expense.Items.First().EmployeeIssueOperation, 1); returnOnStock.UpdateOperations(uow, ask); uow.Save(returnOnStock); uow.Commit(); returnOnStock.UpdateEmployeeWearItems(); uow.Commit(); using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot()) { var employeeTest = uow2.GetById <EmployeeCard>(employee.Id); Assert.That(employeeTest.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2018, 11, 2))); } } }
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)) ); } }
public void Deletion_ExpenseEmployeeDocumentTest() { NewSessionWithSameDB(); var ask = Substitute.For <IInteractiveQuestion>(); ask.Question(string.Empty).ReturnsForAnyArgs(true); var navigation = Substitute.For <INavigationManager>(); using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) { var warehouse = new Warehouse(); uow.Save(warehouse); var nomenclatureType = new ItemsType { Name = "Тестовый тип номенклатуры" }; uow.Save(nomenclatureType); var nomenclature = new Nomenclature { Type = nomenclatureType }; uow.Save(nomenclature); var position1 = new StockPosition(nomenclature, 0, null, null); var nomenclature2 = new Nomenclature { Type = nomenclatureType }; uow.Save(nomenclature2); var position2 = new StockPosition(nomenclature2, 0, null, null); var protectionTools = new ProtectionTools { Name = "СИЗ для тестирования" }; protectionTools.AddNomeclature(nomenclature); uow.Save(protectionTools); var protectionTools2 = new ProtectionTools { Name = "СИЗ для тестирования 2" }; protectionTools2.AddNomeclature(nomenclature2); uow.Save(protectionTools2); var norm = new Norm(); var normItem = norm.AddItem(protectionTools); normItem.Amount = 1; normItem.NormPeriod = NormPeriodType.Year; normItem.PeriodCount = 1; var normItem2 = norm.AddItem(protectionTools2); normItem2.Amount = 1; normItem2.NormPeriod = NormPeriodType.Month; normItem2.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; var incomeItem2 = income.AddItem(nomenclature2); incomeItem2.Amount = 5; income.UpdateOperations(uow, ask); uow.Save(income); 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); var baseParameters = Substitute.For <BaseParameters>(); baseParameters.ColDayAheadOfShedule.Returns(0); expense.CreateIssuanceSheet(null); //Обновление операций expense.UpdateOperations(uow, baseParameters, ask); uow.Save(expense); uow.Save(expense.IssuanceSheet); uow.Commit(); expense.UpdateEmployeeWearItems(); uow.Commit(); var docs = uow.GetAll <Expense>().ToList(); Assert.That(docs.Count, Is.EqualTo(1)); //Непосредственно удаление документа var cancel = new CancellationTokenSource(); using (var uowDel = UnitOfWorkFactory.CreateWithoutRoot()) { var deletionService = new DeleteCore(DeleteConfig.Main, uowDel); deletionService.PrepareDeletion(typeof(Expense), expense.Id, cancel.Token); Assert.That(deletionService.TotalLinks, Is.GreaterThan(0)); deletionService.RunDeletion(cancel.Token); } //Проверяем удаление var expenseId = expense.Id; using (var uowCheck = UnitOfWorkFactory.CreateWithoutRoot()) { //Проверяем что удалили документ. docs = uow.GetAll <Expense>().ToList(); Assert.That(docs.Count, Is.Zero); //Проверяем что случайно не удалили СИЗ и номеклатуру. var protections = uow.GetAll <ProtectionTools>().ToList(); Assert.That(protections.Count, Is.EqualTo(2)); var nomenclatures = uow.GetAll <Nomenclature>().ToList(); Assert.That(nomenclatures.Count, Is.EqualTo(2)); } } }