public void SimpleConversion()
        {
            var options = new DbContextOptions()
                .UseInMemoryStore();

            using (var db = new CycleSalesContext(options))
            {
                // Arange
                db.Bikes.Add(new Bike { Bike_Id = 1, Retail = 100M });
                db.Bikes.Add(new Bike { Bike_Id = 2, Retail = 99.95M });
                db.SaveChanges();

                // Act
                var convertor = new PriceService(db);
                var results = convertor.CalculateForeignPrices(exchangeRate: 2).ToArray();

                // Assert
                Assert.AreEqual(2, results.Length);

                Assert.AreEqual(100M, results[0].USPrice);
                Assert.AreEqual(199.95M, results[0].ForeignPrice);

                Assert.AreEqual(99.95M, results[1].USPrice);
                Assert.AreEqual(199.90M, results[1].ForeignPrice);
            }
        }
        public void SimpleConversion()
        {
            // TODO Test currently hits a real database, replace with something in-memory

            using (var db = new CycleSalesContext())
            {
                // Arange
                db.Bikes.Add(new Bike { Bike_Id = 1, Retail = 100M });
                db.Bikes.Add(new Bike { Bike_Id = 2, Retail = 99.95M });
                db.SaveChanges();

                // Act
                var convertor = new PriceService(db);
                var results = convertor.CalculateForeignPrices(exchangeRate: 2).ToArray();

                // Assert
                Assert.AreEqual(2, results.Length);

                Assert.AreEqual(100M, results[0].USPrice);
                Assert.AreEqual(199.95M, results[0].ForeignPrice);

                Assert.AreEqual(99.95M, results[1].USPrice);
                Assert.AreEqual(199.90M, results[1].ForeignPrice);
            }
        }
        private void buttonGo_Click(object sender, EventArgs e)
        {
            var exchangeRate = decimal.Parse(this.textExchangeRate.Text);

            using (var db = new CycleSalesContext())
            {
                var convertor = new PriceService(db);
                this.dataGridView1.DataSource = convertor.CalculateForeignPrices(exchangeRate);
            }
        }
        public static void EnsureInitialized()
        {
            using (var db = new CycleSalesContext())
            {
                if(!db.Database.AsRelational().Exists())
                {
                    db.Database.AsRelational().ApplyMigrations();

                    db.Bikes.Add(new Bike
                    {
                        Bike_Id = 1,
                        Name = "Mountain Monster 7000",
                        ModelNo = "MM7000",
                        Retail = 349.95M,
                        Description = "Tackle the mountains with confidence and attitude. Built to go fast, built to go hard, and built to last.",
                        ImageUrl = "~/ImageUploads/MountainMonster7000.png"
                    });

                    db.Bikes.Add(new Bike
                    {
                        Bike_Id = 2,
                        Name = "BMX Bandit B500",
                        ModelNo = "BBB500",
                        Retail = 249.95M,
                        Description = "Get your skills on with this little monster. Fly high, fly fast, and fly in style.",
                        ImageUrl = "~/ImageUploads/BmxBanditB500.png"
                    });

                    db.Bikes.Add(new Bike
                    {
                        Bike_Id = 3,
                        Name = "Toddler Terror Trainer 200",
                        ModelNo = "TTT200",
                        Retail = 199.95M,
                        Description = "The premium menacing machine for your young and aspiring bike rider. Who said training wheels couldn't look cool.",
                        ImageUrl = "~/ImageUploads/ToddlerTerrorTrainer200.png"
                    });

                    db.SaveChanges();
                }
            }
        }
        public static void EnsureInitialized()
        {
            using (var db = new CycleSalesContext())
            {
                if (!db.Database.AsRelational().Exists())
                {
                    db.Database.AsRelational().ApplyMigrations();

                    db.Bikes.Add(new Bike
                    {
                        Bike_Id     = 1,
                        Name        = "Mountain Monster 7000",
                        ModelNo     = "MM7000",
                        Retail      = 349.95M,
                        Description = "Tackle the mountains with confidence and attitude. Built to go fast, built to go hard, and built to last.",
                        ImageUrl    = "~/ImageUploads/MountainMonster7000.png"
                    });

                    db.Bikes.Add(new Bike
                    {
                        Bike_Id     = 2,
                        Name        = "BMX Bandit B500",
                        ModelNo     = "BBB500",
                        Retail      = 249.95M,
                        Description = "Get your skills on with this little monster. Fly high, fly fast, and fly in style.",
                        ImageUrl    = "~/ImageUploads/BmxBanditB500.png"
                    });

                    db.Bikes.Add(new Bike
                    {
                        Bike_Id     = 3,
                        Name        = "Toddler Terror Trainer 200",
                        ModelNo     = "TTT200",
                        Retail      = 199.95M,
                        Description = "The premium menacing machine for your young and aspiring bike rider. Who said training wheels couldn't look cool.",
                        ImageUrl    = "~/ImageUploads/ToddlerTerrorTrainer200.png"
                    });

                    db.SaveChanges();
                }
            }
        }
Beispiel #6
0
 public PriceService(CycleSalesContext context)
 {
     _context = context;
 }
Beispiel #7
0
 public PriceService(CycleSalesContext context)
 {
     _context = context;
 }