Exemplo n.º 1
0
        protected void machineGridView_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedMachineID = int.Parse(machineGridView.SelectedRow.Cells[1].Text.ToString());

            var partManagementRepository = new PartManagementRepository();

            partGridView.DataSource = partManagementRepository.GetPartsByMachineId(selectedMachineID);
            partGridView.DataBind();
        }
        public void GetPartsByMachineId_ReturnsRelatedParts()
        {
            Part[] parts =
            {
                new Part {
                    Id = 1, SKU = "sku1"
                },
                new Part {
                    Id = 2, SKU = "sku2"
                },
                new Part {
                    Id = 3, SKU = "sku3"
                },
                new Part {
                    Id = 4, SKU = "sku4"
                },
            };
            Machine[] machines =
            {
                new Machine {
                    Id = 1111, ModelNumber = "mn1"
                },
                new Machine {
                    Id = 2222, ModelNumber = "mn2"
                },
            };
            MachinePart[] machineParts =
            {
                new MachinePart {
                    Machine = machines[0], Part = parts[0]
                },
                new MachinePart {
                    Machine = machines[0], Part = parts[1]
                },
                new MachinePart {
                    Machine = machines[1], Part = parts[2]
                },
                new MachinePart {
                    Machine = machines[1], Part = parts[3]
                },
            };

            var dataContext = new BDataContext <PartsSiteDataContext>();

            dataContext.SetOne("Parts", parts);
            dataContext.SetNext("Machines", machines);
            dataContext.SetNext("Machine Parts", machineParts);
            dataContext.SetNext("Inventory Locations", new InventoryLocation[] {});

            var target  = new PartManagementRepository(dataContext);
            var results = target.GetPartsByMachineId(1111).OrderBy((p) => p.Sku).ToList();

            Assert.AreEqual(2, results.Count);
            Assert.AreEqual("sku1", results[0].Sku);
            Assert.AreEqual("sku2", results[1].Sku);
        }
        private void machineResultsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            var selectedMachineId =
                int.Parse(MachineResultsGridView.DataKeys[int.Parse(e.CommandArgument.ToString())].Value.ToString());

            using (var partManagementRepository = new PartManagementRepository())
            {
                switch (e.CommandName)
                {
                case "ViewParts":
                    if (OnRelatedPartsFound != null)
                    {
                        RelatedPartsFound(new GenericEventArgs <IEnumerable <Part> >
                        {
                            PayLoad = partManagementRepository.GetPartsByMachineId(selectedMachineId)
                        });
                    }

                    break;
                }
            }
        }