예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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();
                }
            }
        }
예제 #5
0
        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();
                }
            }
        }
예제 #6
0
 public PriceService(CycleSalesContext context)
 {
     _context = context;
 }
예제 #7
0
 public PriceService(CycleSalesContext context)
 {
     _context = context;
 }