public ActionResult Create([Bind(Include = "ID,SavingsAmount,DavidPayAmount,DavidPayDay,SarahPayAmount,SarahPayDay,IncomeTotal")] Administration administration)
        {
            if (ModelState.IsValid)
            {
                db.Administration.Add(administration);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(administration));
        }
예제 #2
0
 public CourseRepositoryFixture WithXCourses(int x)
 {
     for (int i = 1; i <= x; i++)
     {
         _context.Courses.Add(new Course()
         {
             Code = "C" + i, LengthInDays = 5, Title = "Course" + i
         });
     }
     _context.SaveChanges();
     return(this);
 }
예제 #3
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 CourseInstanceRepositoryFixture WithXCourseInstances(int x)
 {
     for (int i = 1; i <= x; i++)
     {
         _context.CourseInstances.Add(new CourseInstance()
         {
             StartDate = DateTime.Now.Date.AddDays(i - 1), Course = new Course()
             {
                 Code = "C" + i, LengthInDays = 5, Title = "Course" + i
             }
         });
     }
     _context.SaveChanges();
     return(this);
 }
예제 #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);
            }
        }
예제 #6
0
        public void CanInsertGasStationTanksIntoDatabase()
        {
            _builder.UseInMemoryDatabase("CanInsertGasStationTanks");
            var guid       = Guid.NewGuid();
            var gasStation = new GasStation(guid);

            using (var context1 = new AdministrationContext(_builder.Options))
            {
                var tank1 = new SmartBuy.Administration.Domain.Tank();
                tank1.GasStationId = guid;
                tank1.Number       = 1;
                tank1.ProductId    = 1;
                tank1.Name         = "Tank1";
                tank1.AddMeasurement(new Measurement(TankMeasurement.Gallons, 100, 100, 800));
                var tank2 = new SmartBuy.Administration.Domain.Tank();
                tank2.GasStationId = guid;
                tank2.Number       = 1;
                tank2.ProductId    = 1;
                tank2.Name         = "Tank1";
                tank2.AddMeasurement(new Measurement(TankMeasurement.Gallons, 100, 100, 800));
                gasStation.Tanks.Add(tank1);
                gasStation.Tanks.Add(tank2);
                context1.GasStations.Add(gasStation);
                Assert.NotEqual(default(Guid), gasStation.Id);
                Assert.NotEqual(default(Guid), tank1.GasStationId);
                Assert.NotEqual(default(Guid), tank2.GasStationId);
                context1.SaveChanges();
            }

            using (var context2 = new AdministrationContext(_builder.Options))
            {
                var gasStationQuery = context2.GasStations.Include(g => g.Tanks).Where(g => g.Id == gasStation.Id);

                Assert.NotNull(gasStationQuery.FirstOrDefault());
                Assert.Equal(2, gasStationQuery.FirstOrDefault().Tanks.Count());
            }
        }
예제 #7
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
        public AdministrationDataFixture()
        {
            var _gasStationId = Guid.NewGuid();
            var _dateTime1    = new DateTime(2020, 8, 1, 9, 30, 0);
            var _dateTime2    = new DateTime(2020, 8, 2, 9, 30, 0);

            _gasStation = new GasStation(_gasStationId);
            var tank1   = new Tank();
            var product = new Product();

            _orderStrategy     = new OrderStrategy();
            _tanks             = new List <Tank>();
            _tankSales         = new List <TankSale>();
            tank1.GasStationId = _gasStationId;
            tank1.Number       = 1;
            tank1.ProductId    = 1;
            tank1.Name         = "Tank1";

            tank1.AddMeasurement(new Measurement(TankMeasurement.Gallons, 100, 100, 500));
            var tank2 = new Tank();

            tank2.GasStationId = _gasStationId;
            tank2.Number       = 1;
            tank2.Name         = "Tank2";
            tank2.AddMeasurement(new Measurement(TankMeasurement.Gallons, 100, 100, 500));
            var tank1Sale1 = new TankSale();

            tank1Sale1.Quantity = 100;
            tank1Sale1.SaleTime = _dateTime1;
            var tank1Sale2 = new TankSale();

            tank1Sale2.Quantity = 100;
            tank1Sale2.SaleTime = _dateTime2;
            var tank2Sale1 = new TankSale();

            tank2Sale1.Quantity = 100;
            tank2Sale1.SaleTime = _dateTime1;
            var tank2Sale2 = new TankSale();

            tank2Sale2.Quantity = 100;
            tank2Sale2.SaleTime = _dateTime2;
            var dispatcherGrp = new DispatcherGroup {
                Name = "DP1"
            };

            using (var context = new AdministrationContext())
            {
                _gasStation.Tanks.Add(tank1);
                _gasStation.Tanks.Add(tank2);
                context.DispatcherGroup.Add(dispatcherGrp);
                if (context.GasStations.Any())
                {
                    context.GasStations.RemoveRange(context.GasStations);
                    context.SaveChanges();
                }
                if (context.Products.Any())
                {
                    context.Products.RemoveRange(context.Products);
                    context.SaveChanges();
                }
                if (context.TankSales.Any())
                {
                    context.TankSales.RemoveRange(context.TankSales);
                    context.SaveChanges();
                }
                context.Products.Add(product);
                context.SaveChanges();
                tank1.ProductId = product.Id;
                tank2.ProductId = product.Id;
                _gasStation.DispatcherGroupId = dispatcherGrp.Id;
                context.GasStations.Add(_gasStation);
                context.SaveChanges();
                _tanks.AddRange(new[] { tank1, tank2 });
                tank1Sale1.TankId = tank1.Id;
                tank1Sale2.TankId = tank1.Id;
                tank2Sale1.TankId = tank2.Id;
                tank2Sale2.TankId = tank2.Id;
                context.TankSales.AddRange(new[] { tank1Sale1, tank1Sale2, tank2Sale1, tank2Sale2 });
                _orderStrategy.GasStationId = _gasStation.Id;
                _orderStrategy.OrderType    = OrderType.Schedule;
                context.OrderStrategies.Add(_orderStrategy);
                context.SaveChanges();
                _tankSales.AddRange(new[] { tank1Sale1, tank1Sale2, tank2Sale1, tank2Sale2 });
            }
        }