コード例 #1
0
        public void AddRent()
        {
            using (var context = new RentMyCarContext(options))
            {
                context.Users.Add(this._userFr);
                context.Users.Add(this._userLb);
                context.SaveChanges();

                var service = new CarRepository(context);
                service.AddCar(_userFr.UserName, _ferrari);
                service.AddCar(_userLb.UserName, _lambo);
            }

            Rent rent1 = new Rent()
            {
                EndDate = DateTime.Now.AddDays(5),
                Adress  = new Adress()
                {
                    PostalCode   = "02-785",
                    StreetName   = "Zlota",
                    StreetNumber = 52,
                    City         = "Warszawa"
                },
                CarId = _lambo.CarId
            };
            Rent rent2 = new Rent()
            {
                EndDate = DateTime.Now.AddDays(5),
                Adress  = new Adress()
                {
                    PostalCode   = "02-787",
                    StreetName   = "Pulawska",
                    StreetNumber = 99,
                    City         = "Warszawa"
                },
                CarId = _ferrari.CarId
            };

            using (var context = new RentMyCarContext(options))
            {
                var service = new RentRepository(context);
                service.AddRent(this._userFr.UserName, rent1);
                service.AddRent(this._userLb.UserName, rent2);
            }

            using (var context = new RentMyCarContext(options))
            {
                Assert.AreEqual(2, context.Rents.Count());
                Assert.AreEqual(_lambo.Model, context.Rents.Include(r => r.Car).FirstOrDefault().Car.Model);
                Assert.AreEqual(_userFr.UserName, context.Rents.Include(r => r.User).FirstOrDefault().User.UserName);
            }
        }
コード例 #2
0
        protected void ButtonRent_Click(object sender, EventArgs e)
        {
            Rent rent = new Rent()
            {
                BookID     = int.Parse(Request.QueryString["ID"]),
                UserID     = int.Parse(DropDownListUser.SelectedItem.Value),
                RentDate   = DateTime.Now,
                ReturnDate = DateTime.Now.AddDays(15)
            };

            RentRepository.AddRent(rent);
            Response.Redirect("AllRecords.aspx");
        }