Exemplo n.º 1
0
        public void GetValidTo()
        {
            // Arrange
            ParkingMachine machine = new ParkingMachine(30);
            int            days    = 5;
            int            hours   = 3;
            int            minutes = 2;

            TimeSpan expectedParkingTime;

            expectedParkingTime = new TimeSpan(
                days: days,
                hours: hours,
                minutes: minutes,
                seconds: 0);

            machine.InsertMoney(1); // 2 minutes
            machine.InsertMoney(hours * 30);
            machine.InsertMoney(days * 24 * 30);

            DateTime expectedValidTo = DateTime.Now;

            expectedValidTo = expectedValidTo.Add(expectedParkingTime);

            // Act
            DateTime validTo = machine.GetValidTo();

            // Assert
            Assert.AreEqual(expectedValidTo.ToString(), validTo.ToString());
        }
Exemplo n.º 2
0
        public void GetParkingTimeSpan()
        {
            // Arrange
            ParkingMachine machine = new ParkingMachine(30);
            int            days    = 5;
            int            hours   = 3;
            int            minutes = 2;

            TimeSpan expectedParkingTime;

            expectedParkingTime = new TimeSpan(
                days: days,
                hours: hours,
                minutes: minutes,
                seconds: 0);

            // Act
            machine.InsertMoney(1); // 2 minutes
            machine.InsertMoney(hours * 30);
            machine.InsertMoney(days * 24 * 30);


            // Assert
            Assert.AreEqual(expectedParkingTime, machine.GetParkingTimeSpan());
        }
Exemplo n.º 3
0
        public void CostPerHour()
        {
            // Arrange
            ParkingMachine machine = new ParkingMachine(40);

            // Act
            machine.InsertMoney(30);

            // Assert
            Assert.AreEqual(40, machine.CostPerHour);
        }
Exemplo n.º 4
0
        public void InvalidInsertMoney()
        {
            // Arrange
            ParkingMachine machine = new ParkingMachine(20);

            // Act
            machine.InsertMoney(-30);

            // Assert
            Assert.AreEqual(0, machine.CurrentTotal);
        }
Exemplo n.º 5
0
        public void Cancel_AmoutRefunded()
        {
            // Arrange
            ParkingMachine machine = new ParkingMachine(20);

            // Act
            machine.InsertMoney(100);
            int refund = machine.Cancel();

            // Assert
            Assert.AreEqual(100, refund);
        }
Exemplo n.º 6
0
        public void Cancel_CurrentTotal_Zeroed()
        {
            // Arrange
            ParkingMachine machine = new ParkingMachine(20);

            // Act
            machine.InsertMoney(100);
            int refund = machine.Cancel();

            // Assert
            Assert.AreEqual(0, machine.CurrentTotal);
        }
Exemplo n.º 7
0
        public void BuyTicket4Day()
        {
            // Arrange
            ParkingMachine machine = new ParkingMachine(20);

            // Act
            machine.InsertMoney(20 * 24 * 4);
            Ticket ticket = machine.BuyTicket();

            // Assert
            Assert.AreEqual(TimeToTicketText(days: 4, hours: 0, minutes: 0), ticket.ToString());
        }
Exemplo n.º 8
0
        public void BuyTicket2Day3Hour15Min()
        {
            // Arrange
            ParkingMachine machine = new ParkingMachine(20);
            int            money   = 2 * 24 * 20 + 3 * 20 + 5;

            // Act
            machine.InsertMoney(money);
            Ticket ticket = machine.BuyTicket();

            // Assert
            Assert.AreEqual(TimeToTicketText(days: 2, hours: 3, minutes: 15), ticket.ToString());
        }
Exemplo n.º 9
0
        public void MultipleBuyTicket_CurrentTotal_ZeroAfterBuy()
        {
            // Arrange
            ParkingMachine machine = new ParkingMachine(20);
            int            money   = 2 * 24 * 20 + 3 * 20 + 5;

            // Act
            machine.InsertMoney(money);
            machine.BuyTicket();
            machine.InsertMoney(money);
            machine.BuyTicket();
            machine.InsertMoney(money);
            machine.BuyTicket();

            // Assert
            Assert.AreEqual(0, machine.CurrentTotal);
        }
Exemplo n.º 10
0
        public void MultipleBuyTicket_Total()
        {
            // Arrange
            ParkingMachine machine = new ParkingMachine(20);
            int            money   = 2 * 24 * 20 + 3 * 20 + 5;

            // Act
            machine.InsertMoney(money);
            machine.BuyTicket();
            machine.InsertMoney(money);
            machine.BuyTicket();
            machine.InsertMoney(money);
            machine.BuyTicket();

            // Assert
            Assert.AreEqual(3 * money, machine.Total);
        }