Esempio n. 1
0
        public void SearchHotelById()
        {
            //Setup mock data for test
            var mock = this.CreateMockDataTest();
            var productRepository = mock.Object;
            var api = new SearchHotel();
            //Call Service with Interface
            api.AddHotel(productRepository.SearchHotelById(10001));
            api.AddHotel(productRepository.SearchHotelById(10001));
            api.AddHotel(productRepository.SearchHotelById(10002));
            api.AddHotel(productRepository.SearchHotelById(10002));
            api.AddHotel(productRepository.SearchHotelById(10003));
            api.AddHotel(productRepository.SearchHotelById(10003));

            Console.WriteLine("Hotel count : {0}", api.CountHotel);
            Console.WriteLine("Total Price : {0}", api.GetTotalRoomPrice());
            var hotel = api.SearchHotelById(10003);
            Assert.IsTrue(hotel != null, "Not found hotel ");
            if (hotel != null) {
                Assert.IsTrue(hotel.HotelName.Equals("Ramsawintanee Bangkok"));
                Assert.IsTrue(hotel.Room.FirstOrDefault(r=>r.TotalPrice > 9).TotalPrice == 30);
            }
            //Verify logic
            Assert.AreEqual(6, api.CountHotel);
            Assert.AreEqual(120, api.GetTotalRoomPrice());
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var b = new SearchHotel();
            b.AddHotel(new Hotel {
                HotelId = 100011, HotelName = "Swiming Hotel Bangkok", Room = new List<Room>{
                new Room { Adult = 2, Child = 1, RoomName = "Single delux", TotalPrice = 10 },
                new Room{ Adult = 2, Child = 1, RoomName = "Single delux", TotalPrice = 20 },
            }
            });
            b.AddHotel(new Hotel {
                HotelId = 100011, HotelName = "SaomHotel Sukumvit", Room = new List<Room>{
                new Room{ Adult = 2, Child = 1, RoomName = "Deble delux", TotalPrice = 30 },
                new Room{ Adult = 2, Child = 1, RoomName = "Triple delux", TotalPrice = 40 },
            }
            });
            b.AddHotel(new Hotel {
                HotelId = 100011, HotelName = "Ramsawintanee Bangkok", Room = new List<Room>{
                new Room{ Adult = 2, Child = 1, RoomName = "Suit delux", TotalPrice = 50 },
                new Room{ Adult = 2, Child = 1, RoomName = "Quest delux", TotalPrice = 60 },
            }
            });

            Console.WriteLine("Hotel count : {0}", b.CountHotel);
            Console.WriteLine("Total Price : {0}", b.GetTotalRoomPrice());

            IProductRepository inRepository = b;
            var hotel = inRepository.SearchHotelById(100011);
            if (hotel != null) {
                Console.WriteLine("[+]{0} {1} RoomCount : {2}", hotel.HotelId, hotel.HotelName, hotel.Room.Count);
                foreach (var r in hotel.Room) {
                    Console.WriteLine(" {0} Price : {1} ", r.RoomName, r.TotalPrice);
                }
            }

            Console.ReadLine();
        }