Beispiel #1
0
        public void ModifyTest()
        {
            OrderDetails        orderDetails = new OrderDetails("ww", 1, 1);
            List <OrderDetails> tmp          = new List <OrderDetails>();

            tmp.Add(orderDetails);
            Order        order = new Order("wiki", 3, tmp);
            List <Order> tmp2  = new List <Order>();

            tmp2.Add(order);
            OrderService orderService = new OrderService();

            orderService.SetOrders(tmp2);

            OrderService orderService2 = new OrderService();

            orderService2.Add();
            orderService2.Modify();

            XmlSerializer xmlSer = new XmlSerializer(typeof(List <Order>));

            orderService.Export(xmlSer, "1.xml");
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("1.xml");

            orderService2.Export(xmlSer, "2.xml");
            XmlDocument xmlDocument2 = new XmlDocument();

            xmlDocument2.Load("2.xml");

            Assert.AreEqual(xmlDocument.InnerXml, xmlDocument2.InnerXml);
        }
Beispiel #2
0
        private static void HandleOptions()
        {
            OrderService orderService = new OrderService();

            while (true)
            {
                Console.WriteLine("  菜  单");
                Console.WriteLine("1、添加订单");
                Console.WriteLine("2、删除订单");
                Console.WriteLine("3、修改订单");
                Console.WriteLine("4、查询订单");
                Console.WriteLine("5、显示所有订单");
                Console.WriteLine("6、退出系统");
                Console.Write("请选择需要进行的操作:");
                try
                {
                    int option = int.Parse(Console.ReadLine());
                    switch (option)
                    {
                    case 1:
                        orderService.Add();
                        break;

                    case 2:
                        orderService.Remove();
                        break;

                    case 3:
                        orderService.Modify();
                        break;

                    case 4:
                        orderService.Query();
                        break;

                    case 5:
                        orderService.Show();
                        break;

                    case 6:
                        return;

                    default:
                        Console.WriteLine("请输入1到6之间的数字!任意键继续");
                        Console.ReadKey();
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Beispiel #3
0
        public void QueryTest()
        {
            OrderService orderService = new OrderService();

            orderService.Add();
            StreamWriter sw = new StreamWriter("querytest2.txt");

            Console.SetOut(sw);
            orderService.Query();
            sw.Flush();
            sw.Close();
            string[] line = File.ReadAllLines("querytest2.txt");
            Assert.AreEqual("未找到此订单!", line[line.Length - 1]);
        }
Beispiel #4
0
        public void RemoveTest()
        {
            OrderService orderService = new OrderService();

            OrderService orderService2 = new OrderService();

            orderService2.Add();
            orderService2.Remove();

            XmlSerializer xmlSer = new XmlSerializer(typeof(List <Order>));

            orderService.Export(xmlSer, "1.xml");
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load("1.xml");

            orderService2.Export(xmlSer, "2.xml");
            XmlDocument xmlDocument2 = new XmlDocument();

            xmlDocument2.Load("2.xml");

            Assert.AreEqual(xmlDocument.InnerXml, xmlDocument2.InnerXml);
        }
Beispiel #5
0
        private static void HandleOptions()
        {
            OrderService orderService = new OrderService();

            while (true)
            {
                Console.WriteLine("  菜  单");
                Console.WriteLine("1、添加订单");
                Console.WriteLine("2、删除订单");
                Console.WriteLine("3、修改订单");
                Console.WriteLine("4、查询订单");
                Console.WriteLine("5、显示所有订单");
                Console.WriteLine("6、序列化为xml文件");
                Console.WriteLine("7、从xml文件载入订单");
                Console.WriteLine("8、退出系统");
                Console.Write("请选择需要进行的操作:");
                try
                {
                    int           option      = int.Parse(Console.ReadLine());
                    XmlSerializer xmlSer      = new XmlSerializer(typeof(List <Order>));
                    string        xmlFileName = "orders.xml";
                    switch (option)
                    {
                    case 1:
                        orderService.Add();
                        break;

                    case 2:
                        orderService.Remove();
                        break;

                    case 3:
                        orderService.Modify();
                        break;

                    case 4:
                        orderService.Query();
                        break;

                    case 5:
                        orderService.Show();
                        break;

                    case 6:
                        orderService.Export(xmlSer, xmlFileName);
                        break;

                    case 7:
                        orderService.Import(xmlSer, xmlFileName);
                        break;

                    case 8:
                        return;

                    default:
                        Console.WriteLine("请输入1到8之间的数字!任意键继续");
                        Console.ReadKey();
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }