Esempio n. 1
0
        public void FindHAvingOnlyOneOtherStarportShouldCalculateProfit()
        {
            Starport origin = Starports.DrzewieckiGateway;

            Starport[] destinations = new[]
            {
                Starports.McKayPort,
                Starports.DrzewieckiGateway
            };

            TradeRouteCalculator finder = new TradeRouteCalculator(destinations);

            TradeRoute route = finder.Find(origin);

            Assert.AreEqual(5133, route.Buy);
            Assert.AreEqual(5818, route.Sell);
            Assert.AreEqual(685, route.Profit);
            Assert.AreNotEqual(Starports.DrzewieckiGateway, route.Destination);
        }
Esempio n. 2
0
        public TradeRouteModel[] Destinations(string name)
        {
            List <TradeRouteModel> result = new List <TradeRouteModel>();

            IQueryable <Starport> starports = _Context.Set <Starport>()
                                              .Include(x => x.Goods)
                                              .Include(x => x.System)
                                              .Include(x => x.Goods.Select(c => c.Commodity))
                                              .Include(x => x.Goods.Select(c => c.Commodity.Category));

            TradeRouteCalculator calculator = new TradeRouteCalculator(starports.Where(x => x.IsInRange).ToList());

            foreach (Starport origin in starports.Where(x => x.Name == name))
            {
                IEnumerable <TradeRoute> routes = calculator.FindAll(origin);

                foreach (TradeRoute route in routes)
                {
                    TradeRouteModel model = new TradeRouteModel();
                    model.Category    = route.Commodity.Category.Name;
                    model.Commodtiy   = route.Commodity.Name;
                    model.Destination = new StarportModel()
                    {
                        Name   = route.Destination.Name,
                        System = route.Destination.System.Name
                    };
                    model.Origin = new StarportModel()
                    {
                        Name   = origin.Name,
                        System = origin.System.Name
                    };
                    model.Profit = route.Profit;
                    model.Buy    = route.Buy;
                    model.Sell   = route.Sell;
                    result.Add(model);
                }
            }

            return(result.ToArray());
        }