using System; using System.Collections.Generic; using System.Linq; using Centron.BusinessLogic; using Centron.BusinessLogic.EmployeeArea; using Centron.BusinessLogic.Production; using Centron.BusinessLogic.WebServices.Production; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.BusinessLogic.WebServices.Warehousing; using Centron.Core.Extensions; using Centron.Data.Entities.Administration; using Centron.Data.Entities.Production; using Centron.Interfaces.Production; using Centron.Tests.EndToEnd.Infrastructure; using CentronSoftware.Centron.WebServices.Entities.Production; using CentronSoftware.Centron.WebServices.Entities.Production.ProductionOrder; using CentronSoftware.Centron.WebServices.Entities.Sales.Receipts; using DevExpress.CodeParser; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.ProductionOrder { public class ProductionOrderTest : EndToEndTest { public ProductionOrderTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { this.Verifier.Settings.IgnoreProperty(f => f.ChangedAt); this.Verifier.Settings.IgnoreProperty(f => f.ChangedThroughApplication); this.Verifier.Settings.IgnoreProperty(f => f.CreatedAt); this.Verifier.Settings.IgnoreProperty(f => f.CreatedThroughApplicationVersion); this.Verifier.Settings.IgnoreProperty(f => f.ChangedThroughApplicationVersion); this.Verifier.Settings.IgnoreProperty(f => f.LastChange); this.Verifier.Settings.IgnoreProperty(f => f.CreatedDate); this.Verifier.Settings.IgnoreProperty(f => f.CreatedVersion); } public override void Execute() { this.PrepareDB(); this.CreateProductionMachineKinds(); this.CreateProductionMachineLocations(); this.CreateMachines(); this.CreateProductionOrders(); } private void PrepareDB() { this.Sql("UPDATE dbo.ARTIK SET Fertigungsware = 1 WHERE I3D = 11"); } private void CreateProductionMachineKinds() { var machineKind1 = new ProductionMachineKindDTO() { Name = "Elf", IsActive = true }; var machineKind2 = new ProductionMachineKindDTO() { Name = "Mensch", IsActive = true }; var machineKind3 = new ProductionMachineKindDTO() { Name = "Hobbit", IsActive = true }; var machineKind4 = new ProductionMachineKindDTO() { Name = "Ork", IsActive = true }; var machineKind5 = new ProductionMachineKindDTO() { Name = "Maia", IsActive = false }; var machineKind6 = new ProductionMachineKindDTO() { Name = "Istari", IsActive = true }; var machineKind7 = new ProductionMachineKindDTO() { Name = "Valar", IsActive = false }; var kinds = new List() { machineKind1, machineKind2, machineKind3, machineKind4, machineKind5, machineKind6, machineKind7 }; WithSession(f => f.GetBL().SaveProductionMachineKinds(kinds)); var allKinds = WithSession(f => f.GetBL().GetProductionMachineKindByFilter(new ProductionMachineKindFilter())); this.Verifier.Verify("01_allProductionMachineKinds", allKinds); var humanKind = WithSession(f => f.GetBL().GetProductionMachineKindByFilter(new ProductionMachineKindFilter { SearchText = "Mensch" })); this.Verifier.Verify("02_humanKinds", humanKind); var inactiveKind = WithSession(f => f.GetBL().GetProductionMachineKindByFilter(new ProductionMachineKindFilter() { IsActive = false })); this.Verifier.Verify("03_inactiveKinds", inactiveKind); var description1 = new ProductionMachineKindStepsDescriptionDTO { IsActive = true, Description = "The Elves, were the first and eldest of the Children of Ilúvatar, considered the fairest and wisest of the earthly race of Arda. They called themselves the Quendi (Quenya; IPA: [ˈkʷendi]; 'the Speakers'; singular Quendë [ˈkʷende]), referring to how at their creation, they were the only living things they knew of who spoke", MachineKindI3D = allKinds.Data[0].I3D }; var savedDescription1 = WithSession(f => f.GetBL().SaveProductionMachineKindStepsDescriptionDTO(description1)); this.Verifier.Verify("17_descriptionElv", savedDescription1); var description2 = new ProductionMachineKindStepsDescriptionDTO { IsActive = true, Description = "Hobbits, also known as Halflings, were an ancient mortal race that lived in Middle-earth. Although their exact origins are unknown, they were initially found in the northern regions of Middle-earth and below the Vales of Anduin. At the beginning of the Third Age, hobbits moved north and west. Most of their race eventually founded the land of the Shire in the year TA 1601, though one type of hobbit known as Stoors remained in the Anduin Vale (the type of hobbit Sméagol was).", MachineKindI3D = allKinds.Data[1].I3D }; var savedDescription2 = WithSession(f => f.GetBL().SaveProductionMachineKindStepsDescriptionDTO(description2)); this.Verifier.Verify("18_descriptionHoobit", savedDescription2); var description3 = new ProductionMachineKindStepsDescriptionDTO { IsActive = false, Description = "The Order of Wizards (Q.: Heren Istarion), or simply the Wizards (Q.: Istari), were a group of Maiar sent to Middle-earth by the Valar in the Second and Third Ages. They were embodied as elderly Men and entrusted to aid the Free Peoples against the threat of Sauron's dark power by their wisdom and counsel. ", MachineKindI3D = allKinds.Data[2].I3D }; var savedDescription3 = WithSession(f => f.GetBL().SaveProductionMachineKindStepsDescriptionDTO(description3)); this.Verifier.Verify("19_descriptionIstari", savedDescription3); var allDescriptions = WithSession(f => f.GetBL().GetProductionMachineKindStepsDescriptionByFilter(new ProductionMachineKindStepsDescriptionFilter())); this.Verifier.Verify("20_allDescriptions", allDescriptions); } private void CreateProductionMachineLocations() { var machineLocation1 = new ProductionMachineLocationDTO() { Name = "Eä", IsActive = true, ParentProductionMachineLocationI3D = null, I3D = -1 }; var machineLocation2 = new ProductionMachineLocationDTO() { Name = "Arda", IsActive = true, ParentProductionMachineLocationI3D = -1, I3D = -2 }; var machineLocation3 = new ProductionMachineLocationDTO() { Name = "Middle-earth", IsActive = true, ParentProductionMachineLocationI3D = -2, I3D = -3 }; var machineLocation4 = new ProductionMachineLocationDTO() { Name = "Eriador", IsActive = true, ParentProductionMachineLocationI3D = -3, I3D = -4 }; var machineLocation5 = new ProductionMachineLocationDTO() { Name = "Shire", IsActive = true, ParentProductionMachineLocationI3D = -4, I3D = -5 }; var machineLocation6 = new ProductionMachineLocationDTO() { Name = "Ered Luin", IsActive = true, ParentProductionMachineLocationI3D = -3 }; var machineLocation7 = new ProductionMachineLocationDTO() { Name = "Hithaeglir", IsActive = true, ParentProductionMachineLocationI3D = -3 }; var machineLocation8 = new ProductionMachineLocationDTO() { Name = "Bob sein Haus", IsActive = false }; var locations = new List() { machineLocation1, machineLocation2, machineLocation3, machineLocation4, machineLocation5, machineLocation6,machineLocation7, machineLocation8, }; WithSession(f => f.GetBL().SaveProductionMachineLocations(locations)); var allLocations = WithSession(f => f.GetBL().GetProductionMachineLocationByFilter(new ProductionMachineLocationFilter())); this.Verifier.Verify("04_allLocations", allLocations); var middleEarth = WithSession(f => f.GetBL().GetProductionMachineLocationByFilter(new ProductionMachineLocationFilter() { SearchText = "Middle" })); this.Verifier.Verify("05_middleEarth", middleEarth); var middleEarthAndMiddleEarthAsParent = WithSession(f => f.GetBL().GetProductionMachineLocationByFilter(new ProductionMachineLocationFilter() { SearchText = "Middle-earth", SearchFullName = true })); this.Verifier.Verify("06_middleEarthAndMiddleEarthAsParent", middleEarthAndMiddleEarthAsParent); var inactiveLocations = WithSession(f => f.GetBL().GetProductionMachineLocationByFilter(new ProductionMachineLocationFilter() { IsActive = false })); this.Verifier.Verify("07_inactiveLocations", inactiveLocations); } private void CreateMachines() { // Runkind // 0 => Einzelnd // 1 => Volumen var kinds = WithSession(f => f.GetBL().GetProductionMachineKindByFilter(new ProductionMachineKindFilter()).Data); var locations = WithSession(f => f.GetBL().GetProductionMachineLocationByFilter(new ProductionMachineLocationFilter()).Data); var machine1 = new ProductionMachineDTO() { Name = "Hans der Elf", IsActive = true, RunKind = 0, AmountPerRun = 5, ProductionMachineKind = kinds.First(f => f.I3D == 1), ProductionMachineLocation = locations.First(f => f.I3D == 3), RunsPerDay = 1 }; var machine2 = new ProductionMachineDTO() { Name = "Samwise Gamgee", IsActive = true, RunKind = 0, AmountPerRun = 1, ProductionMachineKind = kinds.First(f => f.I3D == 3), ProductionMachineLocation = locations.First(f => f.I3D == 5) }; var machine3 = new ProductionMachineDTO() { Name = "Mithrandir", IsActive = true, RunKind = 1, AmountPerRun = 100, ProductionMachineKind = kinds.First(f => f.I3D == 5), ProductionMachineLocation = locations.First(f => f.I3D == 3) }; var machine4 = new ProductionMachineDTO() { Name = "Melkor", IsActive = false, RunKind = 1, AmountPerRun = 666, ProductionMachineKind = kinds.First(f => f.I3D == 7), ProductionMachineLocation = locations.First(f => f.I3D == 2) }; var machines = new List() { machine1, machine2, machine3, machine4 }; WithSession(f => f.GetBL().SaveProductionMachines(machines)); var allMachines = WithSession(f => f.GetBL().GetProductionMachineByFilter(new ProductionMachineFilter())); this.Verifier.Verify("08_allMachines", allMachines); var hobbitsAndElfes = WithSession(f => f.GetBL().GetProductionMachineByFilter(new ProductionMachineFilter(){ MachineKindI3Ds = new []{3,1}})); this.Verifier.Verify("09_MachineHobbitsAndElfes", hobbitsAndElfes); var secrestHero = WithSession(f => f.GetBL().GetProductionMachineByFilter(new ProductionMachineFilter() { SearchText = "Sam" })); this.Verifier.Verify("10_MachineSam", secrestHero); var inActiveMachines = WithSession(f => f.GetBL().GetProductionMachineByFilter(new ProductionMachineFilter() { IsActive = false })); this.Verifier.Verify("11_MachineInActive", inActiveMachines); } private void CreateProductionOrders() { var article = WithSession(f => f.GetBL().GetArticlePreviewByArticleI3D(11)); var user = WithSession(f => f.GetBL().GetAppUser(f => f.I3D == 11)); using (var session = new BLSession()) { ProductionOrderDTO order = new ProductionOrderDTO() { Comment = "Unterhalten sich zwei Gletscher. Sagt der eine: 'Was meinst du, was wird die Zukunft bringen?' Sagt der Andere: 'Naja, wir werden Seen.'", IsActive = true, OrderI3D = 277, OrderNumber = 20277, OrderItemI3D = 1321, PlannedFinishDate = new DateTime(1605, 11, 5), ProductionOrderItems = new List() { new () { Comment = "Wenn sich ein Professor ein Brot macht ist das dann wissenschaftlich belegt?", Description = "Nur solange bis die Gegenseite belegt wird.", IsActive = true, ProducedAmount = 24, RequiredAmount = 42, MachineKindI3D = 1, SortOrder = 5, DurationInMinutes = 60, State = ProductionOrderItemState.InProgression, WorkingEmployeeI3D = 22, MachineI3D = 1, ExecutionDailyRunPhase = 1, Article = article }, new () { Comment = "How did the hacker escape the police ?", Description = "He ransomware", IsActive = true, ProducedAmount = 0, RequiredAmount = 12, MachineKindI3D = 4, Article = article, State = ProductionOrderItemState.OpenNotStarted, SortOrder = 4, ExecutionDailyRunPhase = 0, } } }; this.WithSession(f => f.GetBL().SaveProductionOrder(order, user)); var productionOrder = WithSession(f => f.GetBL().GetProductionOrdersByFilter(new ProductionOrderFilter())); this.Verifier.Verify("12_order", productionOrder); var items = WithSession(f => f.GetBL().GetProductionOrderItemsByFilter(new ProductionOrderItemFilter())); this.Verifier.Verify("13_items", items); var logsStart = WithSession(f => f.GetBL().GetProductionOrderLogsByFilter(new ProductionOrderLogFilter())); this.Verifier.Verify("14_logsStart", logsStart); foreach (var productionOrderItem in items.Data) { productionOrderItem.Comment = "I work in a giant keyboard factor"; productionOrderItem.Description = "So far, i've put in several long shifts"; productionOrderItem.IsActive = false; this.WithSession(f => f.GetBL().SaveProductionOrderItem(productionOrderItem, user)); } var itemsAfterChange = WithSession(f => f.GetBL().GetProductionOrderItemsByFilter(new ProductionOrderItemFilter())); this.Verifier.Verify("15_itemsAfterChange",itemsAfterChange); var logsAfterItemChange = WithSession(f => f.GetBL().GetProductionOrderLogsByFilter(new ProductionOrderLogFilter())); this.Verifier.Verify("16_logsAfterItemChange", logsAfterItemChange); } } } }