Exemplo n.º 1
0
        public void CanInsertTanksAndGetTanksFromDatabase()
        {
            _builder.UseInMemoryDatabase("CanInsertTanksAndGetTanks");

            using (var context = new AdministrationContext(_builder.Options))
            {
                var guid       = Guid.NewGuid();
                var gasStation = new GasStation(guid);
                var tank       = new Tank();
                tank.GasStationId = guid;
                tank.Number       = 1;
                tank.ProductId    = 1;
                tank.Name         = "Tank1";
                tank.AddMeasurement(new Measurement(TankMeasurement.Gallons, 100, 100, 800));
                gasStation.Tanks.Add(tank);
                context.GasStations.Add(gasStation);

                Assert.NotEqual(default(Guid), gasStation.Id);
                Assert.NotEqual(default(Guid), tank.GasStationId);
                Assert.Equal(EntityState.Added, context.Entry(tank).State);
                context.SaveChanges();

                var tanks = context.Tanks.Where(t => t.GasStationId == gasStation.Id).ToList();
                Assert.Single(tanks);
            }
        }
 public ActionResult Edit([Bind(Include = "ID,SavingsAmount,DavidPayAmount,DavidPayDay,SarahPayAmount,SarahPayDay,IncomeTotal")] Administration administration)
 {
     if (ModelState.IsValid)
     {
         db.Entry(administration).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(administration));
 }
Exemplo n.º 3
0
        public Room GetRoomById(int roomId)
        {
            var room = _context.Rooms.Find(roomId);

            if (room != null)
            {
                _context.Entry(room)
                .Collection(r => r.Visitors).Load();
            }

            return(room);
        }
Exemplo n.º 4
0
        public void CanInsertGasStationIntoDatabase()
        {
            _builder.UseInMemoryDatabase("CanInsertGasStation");

            using (var context = new AdministrationContext(_builder.Options))
            {
                var gasStation = new GasStation(Guid.NewGuid());
                context.GasStations.Add(gasStation);

                Assert.NotEqual(default(Guid), gasStation.Id);
                Assert.Equal(EntityState.Added, context.Entry(gasStation).State);
            }
        }
Exemplo n.º 5
0
        public void CanInsertProductAndGetProductFromDatabase()
        {
            _builder.UseInMemoryDatabase("CanInsertTanksAndGetTanks");

            using (var context = new AdministrationContext(_builder.Options))
            {
                var product = new Product();
                context.Products.Add(product);

                Assert.NotEqual(default(int), product.Id);
                Assert.Equal(EntityState.Added, context.Entry(product).State);
                context.SaveChanges();

                product = context.Products.Where(p => p.Id == product.Id).FirstOrDefault();
                Assert.NotNull(product);
            }
        }