Example #1
0
        public void CarCantBeRentedForOverlapingTermsTest()
        {
            CarRecord carRecord   = new CarRecord("Lada Granta", "cherry", "1234321");
            DateTime  startOfRent = new DateTime(2017, 1, 1);
            DateTime  endOfRent   = new DateTime(2017, 1, 20);;
            // арендуем первый раз
            bool carRentSuccess = carRecord.Rent(startOfRent, endOfRent);

            DateTime[] startRentDates = carRecord.getStartRentDates();
            DateTime[] endRentDates   = carRecord.getEndRentDates();

            // 1. пробуем арендовать второй раз
            carRentSuccess = carRecord.Rent(startOfRent.AddDays(5), endOfRent.AddDays(5));
            Assert.AreEqual(carRentSuccess, false);
            CollectionAssert.AreEqual(carRecord.getStartRentDates(), startRentDates);
            CollectionAssert.AreEqual(carRecord.getEndRentDates(), endRentDates);
            // 2. пробуем арендовать второй раз
            carRentSuccess = carRecord.Rent(startOfRent.AddDays(-5), endOfRent.AddDays(-5));
            Assert.AreEqual(carRentSuccess, false);
            CollectionAssert.AreEqual(carRecord.getStartRentDates(), startRentDates);
            CollectionAssert.AreEqual(carRecord.getEndRentDates(), endRentDates);
            // 3. пробуем арендовать второй раз
            carRentSuccess = carRecord.Rent(startOfRent.AddDays(-5), endOfRent.AddDays(5));
            Assert.AreEqual(carRentSuccess, false);
            CollectionAssert.AreEqual(carRecord.getStartRentDates(), startRentDates);
            CollectionAssert.AreEqual(carRecord.getEndRentDates(), endRentDates);
            // 4. пробуем арендовать второй раз
            carRentSuccess = carRecord.Rent(startOfRent.AddDays(-5), startOfRent);
            Assert.AreEqual(carRentSuccess, false);
            CollectionAssert.AreEqual(carRecord.getStartRentDates(), startRentDates);
            CollectionAssert.AreEqual(carRecord.getEndRentDates(), endRentDates);
        }
Example #2
0
        public void CarRentWithCarCheckUpTest()
        {
            CarRecord carRecord = new CarRecord("Lada Granta", "cherry", "1234321");

            //                                  0                           1                       2                           3                           4                           5                       6                           7                           8                       9
            DateTime[] startRentDates = { new DateTime(2017, 1, 1), new DateTime(2017, 2, 1), new DateTime(2017, 2, 3), new DateTime(2017, 2, 5), new DateTime(2017, 2, 6), new DateTime(2017, 2, 7), new DateTime(2017, 2, 8), new DateTime(2017, 2, 9), new DateTime(2017, 2, 10), new DateTime(2017, 2, 21) };
            DateTime[] endRentDates   = { new DateTime(2017, 1, 20), new DateTime(2017, 2, 2), new DateTime(2017, 2, 4), new DateTime(2017, 2, 5), new DateTime(2017, 2, 6), new DateTime(2017, 2, 7), new DateTime(2017, 2, 8), new DateTime(2017, 2, 9), new DateTime(2017, 2, 10), new DateTime(2017, 2, 23) };
            bool       carRentSuccess;

            for (int i = 0; i < startRentDates.Count(); i++)
            {
                carRentSuccess = carRecord.Rent(startRentDates[i], endRentDates[i]);
                Assert.AreEqual(carRentSuccess, true);
            }

            // Время аренды попадает на уже запланированное ТО
            DateTime startOfRent = new DateTime(2017, 2, 24);
            DateTime endOfRent   = new DateTime(2017, 2, 25);

            // пробуем арендовать во время запланированного ТО
            carRentSuccess = carRecord.Rent(startOfRent, endOfRent);
            Assert.AreEqual(carRentSuccess, false);

            // Аренда, после которой придётся делать ТО, время которого пересечётся
            // с уже запланированной бронью:
            startOfRent = new DateTime(2017, 2, 19);
            endOfRent   = new DateTime(2017, 2, 20);
            // пробуем арендовать
            carRentSuccess = carRecord.Rent(startOfRent, endOfRent);
            Assert.AreEqual(carRentSuccess, false);

            // Нормальная аренда:
            startOfRent = new DateTime(2017, 2, 12);
            endOfRent   = new DateTime(2017, 2, 12);
            // пробуем арендовать на время, которое ни с чем не пересекается
            carRentSuccess = carRecord.Rent(startOfRent, endOfRent);
            Assert.AreEqual(carRentSuccess, true);

            // Аренда, сдвигающая расписание так, что только что добавленная нормальная аренда
            // попадёт на период ТО:
            startOfRent = new DateTime(2017, 1, 21);
            endOfRent   = new DateTime(2017, 1, 21);
            // пробуем арендовать
            carRentSuccess = carRecord.Rent(startOfRent, endOfRent);
            Assert.AreEqual(carRentSuccess, false);
        }
Example #3
0
        public void CarCanBeRentedSecondTimeForProperTermTest()
        {
            CarRecord carRecord = new CarRecord("Lada Granta", "cherry", "1234321");

            DateTime[] startRentDates = { new DateTime(2017, 1, 1), new DateTime(2017, 1, 21) };
            DateTime[] endRentDates   = { new DateTime(2017, 1, 20), new DateTime(2017, 1, 22) };
            // арендуем первый раз
            bool carRentSuccess = carRecord.Rent(startRentDates[0], endRentDates[0]);

            Assert.AreEqual(carRentSuccess, true);
            // арендуем 2 раз
            carRentSuccess = carRecord.Rent(startRentDates[1], endRentDates[1]);
            Assert.AreEqual(carRentSuccess, true);

            CollectionAssert.AreEqual(carRecord.getStartRentDates(), startRentDates);
            CollectionAssert.AreEqual(carRecord.getEndRentDates(), endRentDates);
        }
Example #4
0
        public void NewCarIsRentedFoProperTermTest()
        {
            CarRecord carRecord   = new CarRecord("Lada Granta", "cherry", "1234321");
            DateTime  startOfRent = new DateTime(2017, 1, 1);
            DateTime  endOfRent   = startOfRent;
            bool      isCarRented = carRecord.Rent(startOfRent, endOfRent);

            Assert.AreEqual(isCarRented, true);
            Assert.AreEqual(carRecord.getStartRentDates()[0], startOfRent);
            Assert.AreEqual(carRecord.getEndRentDates()[0], endOfRent);
        }