示例#1
0
        public void GetFormattedPrice(decimal rate, int precision, int pipsPosition, string bigFigures, string pips, string tenthOfPip)
        {
            var formattedPrice = PriceFormatter.GetFormattedPrice(rate, precision, pipsPosition);

            Assert.AreEqual(bigFigures, formattedPrice.BigFigures);
            Assert.AreEqual(pips, formattedPrice.Pips);
            Assert.AreEqual(tenthOfPip, formattedPrice.TenthOfPip);
        }
        public void OneDiscountAboveOnePound()
        {
            var formatter = new PriceFormatter();
            var output    = formatter.Format(new Price(10.00m, new[] { new Discount("Test discount", 1.00m, 1) }));

            output.Should().BeEquivalentTo(new[] {
                "Subtotal: £10.00",
                "Test discount: -£1.00",
                "Total price: £9.00"
            });
        }
        public void OneDiscountBelowOnePound()
        {
            var formatter = new PriceFormatter();
            var output    = formatter.Format(new Price(1.00m, new[] { new Discount("Test discount", 0.01m, 1) }));

            output.Should().BeEquivalentTo(new[] {
                "Subtotal: £1.00",
                "Test discount: -1p",
                "Total price: 99p"
            });
        }
        public void NoDiscountsBelowOnePound()
        {
            var formatter = new PriceFormatter();
            var output    = formatter.Format(new Price(0.66m));

            output.Should().BeEquivalentTo(new[] {
                "Subtotal: 66p",
                "(No offers available)",
                "Total price: 66p"
            });
        }
        public void NoDiscountsAboveOnePound()
        {
            var formatter = new PriceFormatter();
            var output    = formatter.Format(new Price(2.00m));

            output.Should().BeEquivalentTo(new[] {
                "Subtotal: £2.00",
                "(No offers available)",
                "Total price: £2.00"
            });
        }
        public void ManyDiscounts()
        {
            var formatter = new PriceFormatter();
            var output    = formatter.Format(new Price(10.00m, new[] { new Discount("Test discount1", 1.00m, 2), new Discount("Test discount2", 0.50m, 1) }));

            output.Should().BeEquivalentTo(new[] {
                "Subtotal: £10.00",
                "Test discount1: -£1.00",
                "Test discount1: -£1.00",
                "Test discount2: -50p",
                "Total price: £7.50"
            });
        }
        public void FreshCheesePriceShouldDecreaseAtTwiceTheRateOfStandarCheese()
        {
            Utils.ReceivedDate = new DateTime(2021, 02, 15);
            var    currentDate = Utils.ReceivedDate;
            Cheese cheese      = new Fresh("Queso Fresco", "2021-02-14", "4", 2.21, CheeseType.Name.Fresh, Utils.ReceivedDate);

            for (int i = 0; i < 2; i++)
            {
                cheese.SetPrice(cheese, currentDate);
                currentDate = currentDate.AddDays(1);
            }

            Assert.Equal(1.41, PriceFormatter.ShowPriceAsDecimal(cheese.Price));
        }
        public void AgedCheesePriceShouldIncrease()
        {
            Utils.ReceivedDate = new DateTime(2021, 02, 15);
            var    currentDate = Utils.ReceivedDate;
            Cheese cheese      = new Aged("Roquefort", "2021-02-20", "8", 14.25, CheeseType.Name.Aged, Utils.ReceivedDate);

            for (int i = 0; i < 3; i++)
            {
                cheese.SetPrice(cheese, currentDate);
                currentDate = currentDate.AddDays(1);
            }

            Assert.Equal(16.50, PriceFormatter.ShowPriceAsDecimal(cheese.Price));
        }
        public void UniqueCheesePriceShouldNotChange()
        {
            Utils.ReceivedDate = new DateTime(2021, 02, 15);
            var    currentDate = Utils.ReceivedDate;
            Cheese cheese      = new Unique("Calcagno", null, null, 18.90, CheeseType.Name.Unique, Utils.ReceivedDate);

            for (int i = 0; i <= 5; i++)
            {
                cheese.SetPrice(cheese, currentDate);
                currentDate = currentDate.AddDays(1);
            }

            Assert.Equal(18.90, PriceFormatter.ShowPriceAsDecimal(cheese.Price));
        }
        public void CheesePriceShouldBeRounded()
        {
            Cheese cheese  = new Cheese();
            Cheese cheese2 = new Cheese();

            cheese.Price  = 3.624;
            cheese2.Price = 3.625;

            cheese.Price  = Math.Round(cheese.Price, 2, MidpointRounding.AwayFromZero);
            cheese2.Price = Math.Round(cheese2.Price, 2, MidpointRounding.AwayFromZero);

            Assert.Equal(3.62, PriceFormatter.ShowPriceAsDecimal(cheese.Price));
            Assert.Equal(3.63, cheese2.Price);
        }
        public void CheesePriceShouldNotBeLessThan0()
        {
            Utils.ReceivedDate = new DateTime(2021, 02, 15);
            var    currentDate = Utils.ReceivedDate;
            Cheese cheese      = new Fresh("Queso Fresco", "2021-02-14", "10", 1.10, CheeseType.Name.Fresh, Utils.ReceivedDate);

            for (int i = 0; i <= 14; i++)
            {
                cheese.SetPrice(cheese, currentDate);
                currentDate = currentDate.AddDays(1);
            }

            Assert.Equal(0, PriceFormatter.ShowPriceAsDecimal(cheese.Price));
        }
        public void SpecialCheesePriceShouldIncreaseAfter10Days()
        {
            Utils.ReceivedDate = new DateTime(2021, 02, 15);
            var    currentDate = Utils.ReceivedDate;
            Cheese cheese      = new Special("Dragon Mozzarella", "2021-02-28", "10", 2.21, CheeseType.Name.Special, Utils.ReceivedDate);

            for (int i = 0; i < 10; i++)
            {
                cheese.SetPrice(cheese, currentDate);
                currentDate = currentDate.AddDays(1);
            }

            Assert.Equal(2.93, PriceFormatter.ShowPriceAsDecimal(cheese.Price));
        }
        public void StandardCheesePriceShouldDecrease()
        {
            Utils.ReceivedDate = new DateTime(2021, 02, 15);
            var currentDate = Utils.ReceivedDate;
            var cheese      = new Standard("Cheddar", "2021-02-18", "10", 3.87, CheeseType.Name.Standard, Utils.ReceivedDate);

            for (int i = 0; i < 6; i++)
            {
                cheese.SetPrice(cheese, currentDate);
                currentDate = currentDate.AddDays(1);
            }

            Assert.Equal(2.55, PriceFormatter.ShowPriceAsDecimal(cheese.Price));
        }
        public void StandardCheeseShouldExpire()
        {
            Utils.ReceivedDate = new DateTime(2021, 02, 15);
            var    currentDate = Utils.ReceivedDate;
            Cheese cheese      = new Standard("Cheddar", "2021-02-15", "3", 3.87, CheeseType.Name.Standard, Utils.ReceivedDate);

            for (int i = 0; i <= 7; i++)
            {
                cheese.SetPrice(cheese, currentDate);
                currentDate = currentDate.AddDays(1);
            }

            Assert.True(cheese.IsExpired(currentDate));
            Assert.Equal(0, PriceFormatter.ShowPriceAsDecimal(cheese.Price));
        }
示例#15
0
        static int Main(string[] args)
        {
            var basketParser = new BasketParser(new Inventory());

            var(items, failed) = basketParser.ParseBasket(args);
            if (failed.Any())
            {
                Console.WriteLine("Could not parse input:");
                foreach (var error in failed)
                {
                    Console.WriteLine($"Item {error} not in inventory");
                }
                return(1);
            }
            var pricing = new Pricing(new Offers());
            var price   = pricing.CalculatePrice(items);
            var lines   = new PriceFormatter().Format(price);

            foreach (var line in lines)
            {
                Console.WriteLine(line);
            }
            return(0);
        }
示例#16
0
        private dynamic RouteEvent()
        {
            try
            {
                //RecipeItem.ResetId();
                sql.Open(WebSettings.Settings.CreateDescription());

                DataService db = new DataService(sql);

                var knightRidersCollection = CrossoutDataService.Instance.KnightRidersCollection;
                var statusModel            = db.SelectStatus();

                KnightRidersModel knightRidersModel = new KnightRidersModel();

                List <int> containedItemIDs = new List <int>();

                foreach (var item in knightRidersCollection.EventItems)
                {
                    foreach (var ingredient in item.Ingredients)
                    {
                        if (!containedItemIDs.Contains(ingredient.Id))
                        {
                            containedItemIDs.Add(ingredient.Id);
                        }
                    }
                    if (item.Id != null)
                    {
                        containedItemIDs.Add((int)item.Id);
                    }
                }
                knightRidersModel.ContainedItems = db.SelectListOfItems(containedItemIDs);

                foreach (var item in knightRidersCollection.EventItems)
                {
                    decimal sellSum = 0;
                    decimal buySum  = 0;
                    foreach (var ingredient in item.Ingredients)
                    {
                        ingredient.Name            = knightRidersModel.ContainedItems[ingredient.Id].Name;
                        ingredient.SellPrice       = knightRidersModel.ContainedItems[ingredient.Id].SellPrice;
                        ingredient.BuyPrice        = knightRidersModel.ContainedItems[ingredient.Id].BuyPrice;
                        ingredient.FormatSellPrice = PriceFormatter.FormatPrice(ingredient.SellPrice);
                        ingredient.FormatBuyPrice  = PriceFormatter.FormatPrice(ingredient.BuyPrice);
                        sellSum += ingredient.SellPrice * ingredient.Amount / knightRidersModel.ContainedItems[ingredient.Id].Amount;
                        buySum  += ingredient.BuyPrice * ingredient.Amount / knightRidersModel.ContainedItems[ingredient.Id].Amount;
                    }

                    if (item.Id != null)
                    {
                        item.SellPrice       = knightRidersModel.ContainedItems[(int)item.Id].SellPrice;
                        item.BuyPrice        = knightRidersModel.ContainedItems[(int)item.Id].BuyPrice;
                        item.FormatSellPrice = PriceFormatter.FormatPrice(item.SellPrice);
                        item.FormatBuyPrice  = PriceFormatter.FormatPrice(item.BuyPrice);
                    }

                    item.FormatSellSum      = PriceFormatter.FormatPrice(sellSum);
                    item.FormatBuySum       = PriceFormatter.FormatPrice(buySum);
                    item.TotalSellSum       = sellSum;
                    item.TotalBuySum        = buySum;
                    item.FormatTotalSellSum = PriceFormatter.FormatPrice(sellSum);
                    item.FormatTotalBuySum  = PriceFormatter.FormatPrice(buySum);
                }
                knightRidersModel.EventItems = knightRidersCollection.EventItems;

                knightRidersModel.Status = statusModel;

                return(View["event", knightRidersModel]);
            }
            catch
            {
                return(Response.AsRedirect("/"));
            }
        }
        private dynamic RoutePackages()
        {
            try
            {
                //RecipeItem.ResetId();
                sql.Open(WebSettings.Settings.CreateDescription());

                DataService db = new DataService(sql);

                var packagesCollection = CrossoutDataService.Instance.PremiumPackagesCollection;
                var statusModel        = db.SelectStatus();
                var appPrices          = db.SelectAllSteamPrices();

                PremiumPackagesModel packagesModel = new PremiumPackagesModel();

                List <int> itemIDs = new List <int>();

                //Load contained items
                foreach (var package in packagesCollection.Packages)
                {
                    foreach (var itemID in package.MarketPartIDs)
                    {
                        if (!itemIDs.Contains(itemID))
                        {
                            itemIDs.Add(itemID);
                        }
                    }
                }
                packagesModel.ContainedItems = db.SelectListOfItems(itemIDs);


                //Calc prizes
                foreach (var package in packagesCollection.Packages)
                {
                    package.Prices = appPrices.Find(x => x.Id == package.SteamAppID).Prices;
                    decimal sellSum = 0;
                    decimal buySum  = 0;
                    foreach (var id in package.MarketPartIDs)
                    {
                        sellSum += packagesModel.ContainedItems[id].SellPrice;
                        buySum  += packagesModel.ContainedItems[id].BuyPrice;
                    }

                    package.FormatSellSum      = PriceFormatter.FormatPrice(sellSum);
                    package.FormatBuySum       = PriceFormatter.FormatPrice(buySum);
                    package.TotalSellSum       = sellSum + (package.RawCoins * 100);
                    package.TotalBuySum        = buySum + (package.RawCoins * 100);
                    package.FormatTotalSellSum = PriceFormatter.FormatPrice(sellSum + (package.RawCoins * 100));
                    package.FormatTotalBuySum  = PriceFormatter.FormatPrice(buySum + (package.RawCoins * 100));

                    foreach (var price in package.Prices)
                    {
                        if (price != null && price.Final != 0)
                        {
                            price.FormatFinal = PriceFormatter.FormatPrice(price.Final);
                            price.FormatSellPriceDividedByCurrency = PriceFormatter.FormatPrice(package.TotalSellSum / ((decimal)price.Final / 100));
                            price.FormatBuyPriceDividedByCurrency  = PriceFormatter.FormatPrice(package.TotalBuySum / ((decimal)price.Final / 100));
                        }
                    }
                }

                //Add all possible categories to dict
                var listOfCategories = new List <int>();
                listOfCategories.Clear();
                listOfCategories.Add(1);
                listOfCategories.Add(99);
                foreach (var package in packagesCollection.Packages)
                {
                    if (!listOfCategories.Contains(package.Category) && package.Category != 0)
                    {
                        listOfCategories.Add(package.Category);
                    }
                }
                listOfCategories.Sort();
                foreach (var category in listOfCategories)
                {
                    packagesModel.Packages.Add(category, new List <PremiumPackage>());
                }

                //Categorize
                foreach (var package in packagesCollection.Packages)
                {
                    if (package.Prices.Any(x => x.Final != 0))
                    {
                        if (package.Category == 0)
                        {
                            package.Category = 1;
                        }
                    }
                    else
                    {
                        package.Category = 99;
                    }

                    packagesModel.Packages[package.Category].Add(package);
                }

                packagesModel.Status = statusModel;

                return(View["packages", packagesModel]);
            }
            catch
            {
                return(Response.AsRedirect("/"));
            }
        }
示例#18
0
 public void GetFormattedSpread(decimal spread, int precision, int pipsPosition, string expected)
 {
     Assert.AreEqual(expected, PriceFormatter.GetFormattedSpread(spread, precision, pipsPosition));
 }