示例#1
0
        public void CanGetIncidentByIncidentId()
        {
            Incident newInc = new Incident
            {
                IncidentId     = 123,
                IncidentTypeId = 44,
                OrderId        = 3,
                CustomerId     = 22,
                EmployeeId     = 45,
                Resolution     = "Told to shop elsewhere"
            };

            try
            {
                newInc.save();
                IncidentFactory newIncidentFactory = new IncidentFactory();
                var             incident           = newIncidentFactory.get(123);

                Assert.Equal(incident.IncidentId, 123);
                Assert.Equal(incident.IncidentTypeId, 44);
                Assert.Equal(incident.OrderId, 3);
                Assert.Equal(incident.CustomerId, 22);
                Assert.Equal(incident.EmployeeId, 45);
                Assert.Equal(incident.Resolution, "Told to shop elsewhere");
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        /**
         * Class: ListIncidentsAction
         * Purpose: Lists all incidents for the current employee
         * Author: Dayne Wright
         * Methods:
         *     static void ReadInput() - Shows the list of incidents and sets selected
         */
        public static void ReadInput()
        {
            Employee employee = EmployeeFactory.Instance.ActiveEmployee;

            CustomerFactory custFact     = new CustomerFactory();
            OrderFactory    orderFact    = new OrderFactory();
            IncidentFactory incidentFact = new IncidentFactory();

            Console.WriteLine(@"
====================================
BANGAZON INC CUSTOMER SERVICE PORTAL
====================================");
            Console.WriteLine();

            List <Incident> incidents = incidentFact.getByEmployeeId(employee.EmployeeId);


            incidents.ForEach(delegate(Incident i)
            {
                Order order       = orderFact.get(i.OrderId);
                Customer customer = custFact.get(order.CustomerId);

                Console.WriteLine($"{i.IncidentId}. {customer.LastName}, {customer.FirstName} : Order {order.OrderId}");
            });
            Console.WriteLine("X.Exit");
            Console.Write("> ");
            int selection = 0;

            while (selection == 0)
            {
                try
                {
                    string input = Console.ReadLine();

                    if (input.ToLower() == "x")
                    {
                        return; // to main menu
                    }

                    selection = Convert.ToInt32(input);

                    if (incidents.Find(i => i.IncidentId == selection).IncidentId == selection)
                    {
                        IncidentFactory.Instance.ActiveIncident = incidentFact.get(selection);
                        CustomerFactory.Instance.ActiveCustomer = custFact.get(orderFact.get(IncidentFactory.Instance.ActiveIncident.OrderId).CustomerId);
                        ShowSingleIncidentAction.ReadInput();
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine("Sorry!  That is not a valid incident number.  Please select an incident from above.");
                    Console.Write("> ");
                }
                selection = 0;
            }
        }
        public void CanQuerySingleIncident(int id)
        {
            var      fact     = new IncidentFactory();
            Incident incident = fact.get(id);

            Assert.IsType <Incident>(incident);
            Assert.NotNull(incident.IncidentId);
            Assert.NotNull(incident.EmployeeId);
            Assert.NotNull(incident.OrderId);
        }
示例#4
0
        public void CanUpdateIncidentInDB()
        {
            var      fact = new IncidentFactory();
            Incident last = fact.getAll().Last();

            last.Resolution   = "Test Resolution";
            last.DateResolved = DateTime.Today;
            last.update();

            Incident updated = fact.get(last.IncidentId);

            Assert.Equal(updated.Resolution, last.Resolution);
            Assert.Equal(updated.DateResolved, last.DateResolved);
            // Remove Last Incident from Database
            if (last.IncidentId == updated.IncidentId)
            {
                var conn = new BangazonConnection();
                conn.insert($"DELETE FROM Incident WHERE IncidentId = {updated.IncidentId}");
            }
        }