Ejemplo n.º 1
0
        public void GivenBookingsWhenAddingDuplicateThenThrowException()
        {
            // ARRANGE
            var bookingManager = new BookingManager();
            var bookingDate    = new DateTime(2012, 3, 28);

            // ACT
            bookingManager.AddBooking("Patel", 101, bookingDate);

            // ASSERT
            var ex = Assert.Throws <Exception>(() => bookingManager.AddBooking("Li", 101, bookingDate));
        }
Ejemplo n.º 2
0
        public void GivenBookingsShouldReturnCorrectAmountOfBookings()
        {
            // ARRANGE
            var bookingManager = new BookingManager();
            var bookingDate    = new DateTime(2012, 3, 28);

            // ACT
            bookingManager.AddBooking("Patel", 101, bookingDate);
            bookingManager.AddBooking("Halford", 102, bookingDate);

            // ASSERT
            var result = bookingManager.GetAvailableRooms(bookingDate);

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(1, result.Where(x => x == 103).Count());
            Assert.AreEqual(1, result.Where(x => x == 104).Count());
        }
        public void TestItAll()
        {
            BookingManager bookingManager = new BookingManager(_context);
            List <Booking> allBookings    = bookingManager.GetAllBookings().ToList();


            //LicensePlate skal være det samme som en LicensePlate i Cars, dette er add
            Booking data = new Booking {
                ParkingId = 1, Username = "******", LicensePlate = "XR55143", StartTime = new DateTime(2021, 5, 15, 8, 10, 5), EndTime = new DateTime(2021, 5, 15, 14, 50, 4)
            };
            Booking newBooking = bookingManager.AddBooking(data);

            Assert.IsTrue(newBooking.Id > 0);
            Assert.AreEqual(data.ParkingId, newBooking.ParkingId);
            Assert.AreEqual(data.LicensePlate, newBooking.LicensePlate);
            Assert.AreEqual(data.Username, newBooking.Username);
            Assert.AreEqual(data.StartTime, newBooking.StartTime);
            Assert.AreEqual(data.EndTime, newBooking.EndTime);

            //Booking nullModelData = new Booking();
            //Assert.ThrowsException<BookingException>(() => bookingManager.AddBooking(nullModelData));

            //GetById
            Booking bookingById = bookingManager.GetBookingById(newBooking.Id);

            Assert.AreEqual(newBooking.Id, bookingById.Id);
            Assert.AreEqual(newBooking.ParkingId, bookingById.ParkingId);
            Assert.AreEqual(newBooking.LicensePlate, bookingById.LicensePlate);
            Assert.AreEqual(newBooking.Username, bookingById.Username);
            Assert.AreEqual(newBooking.StartTime, bookingById.StartTime);
            Assert.AreEqual(newBooking.EndTime, bookingById.EndTime);

            Assert.IsNull(bookingManager.GetBookingById(newBooking.Id + 1));

            //Update
            Booking updates = new Booking {
                Username = "******"
            };
            int     id             = newBooking.Id;
            Booking updatedBooking = bookingManager.UpdateBooking(id, updates);

            Assert.AreEqual(id, updatedBooking.Id);
            Assert.AreEqual(updates.Username, updatedBooking.Username);

            Assert.IsNull(bookingManager.UpdateBooking(id + 1, updates));

            //Delete all

            /*
             * foreach (var b in bookingManager.GetAllBookings().ToList())
             * {
             *  bookingManager.DeleteBooking(b.Id);
             * }*/
        }
Ejemplo n.º 4
0
        public void GivenABookingWhenRoomNotAvailableThenReturnFalse()
        {
            // ARRANGE
            var bookingManager = new BookingManager();
            var bookingDate    = new DateTime(2012, 3, 28);

            // ACT
            bookingManager.AddBooking("Patel", 101, bookingDate);
            var result = bookingManager.IsRoomAvailable(101, bookingDate);

            // ASSERT
            Assert.False(result);
        }
Ejemplo n.º 5
0
 public ActionResult <Booking> Post([FromBody] Booking value)
 {
     try
     {
         Booking newBooking = _bookingManager.AddBooking(value);
         string  uri        = Url.RouteUrl(RouteData.Values) + "/" + newBooking.Id;
         return(Created(uri, newBooking));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 6
0
        public void GivenAGuestThenShouldAddBooking()
        {
            // ARRANGE
            var bookingManager = new BookingManager();
            var bookingDate    = new DateTime(2012, 3, 28);

            // ACT
            bookingManager.AddBooking("Patel", 101, bookingDate);

            // ASSERT
            var bookingCount = bookingManager
                               .Bookings
                               .Where(x => x.Guest == "Patel" && x.RoomDetails.RoomNumber == 101 && x.BookingDate == bookingDate)
                               .Count();

            Assert.AreEqual(1, bookingCount);
        }
Ejemplo n.º 7
0
        public void handler(IResponder responder)
        {
            Booking booking = new Booking();

            booking.Bookingname = SJSRequest.GetString("Bookingname").Trim();
            DateTime dt    = DateTime.Now;
            string   dtStr = SJSRequest.GetString("Bookingtime");

            if (string.IsNullOrEmpty(dtStr) == false)
            {
                dt = Convert.ToDateTime(dtStr);
                dt = dt.AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute).AddSeconds(DateTime.Now.Second);
            }
            booking.Bookingtime = dt;// DateTime.UtcNow;
            booking.Isbooking   = true;
            booking.Uid         = PageUtils.AccountID;
            booking.Realname    = PageUtils.RealName;
            booking.Issettle    = false;
            booking.Haserror    = false;

            if (string.IsNullOrEmpty(booking.Bookingname))
            {
                responder.WriteErroredMsg("预订名称不能为空!");
                return;
            }

            booking.Bookingname += "(" + booking.Bookingtime.Month + "-" + booking.Bookingtime.Day + ")";

            int rlt = BookingManager.AddBooking(booking);

            if (rlt <= 0)
            {
                responder.WriteErroredMsg("预订新建失败,数据库写入不成功!");
                return;
            }

            responder.WriteSuccessedMsg("新建预订成功!");
        }
        public ActionResult ResumeFcl(FormCollection fc)
        {
            try
            {
                var viewModel = new ResumeDossierFcl();
                viewModel.Clients           = rezCli;
                viewModel.DossierFclExports = rezDoss;
                viewModel.Bookings          = rezBkg;
                viewModel.InstruTrans       = rezInstru;
                viewModel.Transporteurs     = rezTrans;
                viewModel.Mads  = rezMad;
                viewModel.Devis = rezDevi;
                viewModel.CompagnieMaritimes = rezCompa;
                viewModel.Conteneurs         = lstTC;
                viewModel.Marchandises       = lsMarchandises;
                viewModel.LigneDeVentes      = lstLV;

                //Instanciation de l'objet client
                rezCli.CLT_ID      = leCliDuDoss.NewIdClient();
                rezCli.CLT_REF     = fc["Clients.CLT_REF"];
                rezCli.CLT_NOMRAIS = fc["Clients.CLT_NOMRAIS"];
                if (!String.IsNullOrEmpty(fc["Clients.CLT_SIRET"]))
                {
                    rezCli.CLT_SIRET = Convert.ToInt32(fc["Clients.CLT_SIRET"]);
                }
                else
                {
                    rezCli.CLT_SIRET = 0;
                }

                rezCli.CLT_ADRESSE = fc["Clients.CLT_ADRESSE"];
                rezCli.CLT_CP      = fc["Clients.CLT_CP"];
                rezCli.CLT_VILLE   = fc["Clients.CLT_VILLE"];
                rezCli.CLT_PAYS    = fc["Clients.CLT_PAYS"];
                leCliDuDoss.AddClient(rezCli);
                //db.SaveChanges();

                //Instanciation de l'objet dossier
                rezDoss.FCL_ID = (DateTime.Now.Year + "E" + leDoss.numDossCompteur().ToString());
                rezDoss.CLT_ID = rezCli.CLT_ID;
                leDoss.AddDossier(rezDoss);

                //Instanciation de l'objet Transporteur
                rezTrans.TRS_REF     = lesTransDuDoss.numTransCompteur().ToString();
                rezTrans.TYTRANS_ID  = Convert.ToInt32(fc["TYTRANS_ID"]);
                rezTrans.TRS_NOMRAIS = fc["Transporteurs.TRS_NOMRAIS"];
                lesTransDuDoss.AddTrans(rezTrans);

                //Instanciation de l'objet MAD
                rezMad.MAD_ID          = madDuDoss.NumMad();
                rezMad.MAD_LIEU_ENLEV  = fc["Mads.MAD_LIEU_ENLEV"];
                rezMad.MAD_ADRES_ENLEV = fc["Mads.MAD_ADRES_ENLEV"];
                if (!String.IsNullOrEmpty(fc["Mads.MAD_DATE"]))
                {
                    rezMad.MAD_DATE = Convert.ToDateTime(fc["Mads.MAD_DATE"]);
                }
                else
                {
                    rezMad.MAD_DATE = DateTime.Now;
                }
                madDuDoss.AddMad(rezMad);


                //Instanciation de l'objet Instruction Transporteur
                rezInstru.INSTR_NUMOFR = instruDoss.NumOffreAuto();
                rezInstru.MAD_ID       = rezMad.MAD_ID;
                rezInstru.FCL_ID       = rezDoss.FCL_ID;
                rezInstru.TRS_REF      = rezTrans.TRS_REF;
                instruDoss.AddInstruTrans(rezInstru);

                //Instanciation de l'objet CompagnieMaritime
                rezCompa.CM_REF     = cmDuDoss.numCompMaritime().ToString();
                rezCompa.CM_NOMRAIS = fc["CompagnieMaritimes.CM_NOMRAIS"];
                rezCompa.CM_SIRET   = 0;
                rezCompa.CM_ADRESSE = "";
                rezCompa.CM_CP      = "";
                rezCompa.CM_VILLE   = fc["CompagnieMaritimes.CM_VILLE"];
                cmDuDoss.AddCM(rezCompa);

                //Instanciation de l'objet Booking
                rezBkg.BKG_ID        = lesBkDuDoss.CompteurNumBkg();
                rezBkg.BKG_NUM       = fc["Bookings.BKG_NUM"];
                rezBkg.FCL_ID        = rezDoss.FCL_ID;
                rezBkg.CM_REF        = rezCompa.CM_REF;
                rezBkg.BKG_NOMNAVIRE = fc["Bookings.BKG_NOMNAVIRE"];
                rezBkg.BKG_DATE      = DateTime.Now;
                if (!String.IsNullOrEmpty(fc["Bookings.BKG_ETA"]))
                {
                    rezBkg.BKG_ETA = Convert.ToDateTime(fc["Bookings.BKG_ETA"]);
                }
                else
                {
                    rezBkg.BKG_ETA = DateTime.Now;
                }
                if (!String.IsNullOrEmpty(fc["Bookings.BKG_ETD"]))
                {
                    rezBkg.BKG_ETD = Convert.ToDateTime(fc["Bookings.BKG_ETD"]);
                }
                else
                {
                    rezBkg.BKG_ETD = DateTime.Now;
                }
                rezBkg.BKG_FORWARDER     = "";
                rezBkg.BKG_LOADTERM      = "";
                rezBkg.BKG_NUMVYG        = "";
                rezBkg.BKG_PORTARRIVEE   = fc["Bookings.BKG_PORTARRIVEE"];
                rezBkg.BKG_PORTDEPART    = fc["Bookings.BKG_PORTDEPART"];
                rezBkg.BKG_PORTFORWARDER = "";
                rezBkg.BKG_REFCOTATION   = "";
                rezBkg.BKG_OBS           = "";
                rezBkg.BKG_REFBL         = fc["Bookings.BKG_REFBL"];
                lesBkDuDoss.AddBooking(rezBkg);


                ViewBag.TYTRANS_ID = new SelectList(db.TypeTransporteurs, "TYTRANS_ID", "TYTRANS_LIBELLE");
                return(RedirectToAction("Index", new { Controller = "DossierFclExports" }));
            }
            catch (RetryLimitExceededException /* dex */)
            {
                ModelState.AddModelError(" ", "Unable to save changes. Try again, and if the problem persists see your system administrator");
            }
            return(RedirectToAction("Details", new { Controller = "DossierFclExports", id = rezDoss.FCL_ID }));
        }