Exemple #1
0
        public void GivenUserId_ShouldReturn_RideListAndInvoice()
        {
            invoiceGenerator = new InvoiceGenerator(RideType.NORMAL);
            Ride[]         ride1          = { new Ride(6.0, 7), new Ride(3.0, 5), new Ride(0.6, 3) };
            Ride[]         ride2          = { new Ride(5.0, 7), new Ride(15.0, 27), new Ride(9.0, 15) };
            string         P1             = "Tony";
            string         P2             = "Chris";
            RideRepository rideRepository = invoiceGenerator.GetRepo();

            rideRepository.AddRide(P1, ride1);
            rideRepository.AddRide(P2, ride2);
            InvoiceSummary invoice_P1         = invoiceGenerator.GetInvoiceSummary(P1);
            InvoiceSummary expectedInvoice_P1 = new InvoiceSummary(3, 65);

            Assert.AreEqual(invoice_P1, expectedInvoice_P1);
        }
        public void GivenUserId_ShouldReturn_RideListAndInvoice()
        {
            invoiceGenerator = new InvoiceGenerator(RideType.NORMAL);
            Ride[]         ridesPerson1   = { new Ride(2.0, 5), new Ride(0.1, 3), new Ride(3.0, 5) };
            Ride[]         ridesPerson2   = { new Ride(4.0, 20), new Ride(5.0, 25), new Ride(4.0, 30) };
            string         keyPerson1     = "Sam";
            string         keyPerson2     = "Mark";
            RideRepository rideRepository = invoiceGenerator.ToAccess_rideRepository();

            rideRepository.AddRide(keyPerson1, ridesPerson1);
            rideRepository.AddRide(keyPerson2, ridesPerson2);
            // Arrange
            InvoiceSummary invoiceReturn_For_Person1   = invoiceGenerator.GetInvoiceSummary(keyPerson1);
            InvoiceSummary expectedInvoice_For_Person1 = new InvoiceSummary(3, 65);

            // Assert
            Assert.AreEqual(expectedInvoice_For_Person1, invoiceReturn_For_Person1);
        }
        public void GivenUserID_WhenPassed_ShouldReturnInvoice()
        {
            invoiceGenerator = new InvoiceGenerator(RideType.NORMAL);
            RideRepository rideRepository = new RideRepository();

            rideRepository.AddRide("101", new Ride[] { new Ride(2.0, 5), new Ride(0.1, 1) });
            rideRepository.AddRide("102", new Ride[] { new Ride(2.0, 7), new Ride(0.1, 6) });
            rideRepository.AddRide("103", new Ride[] { new Ride(2.0, 2), new Ride(0.1, 4) });

            string given_UserID = "102";

            InvoiceSummary summary = invoiceGenerator.CalculateFare(rideRepository.GetRides(given_UserID));

            InvoiceSummary expected_Summary = new InvoiceSummary {
                total_Fare = 34, total_Rides = 2, avg_Fare = 17
            };

            Assert.That(expected_Summary, Is.EqualTo(summary));
        }
Exemple #4
0
        public void GivenUserIdReturnInvoiceSummary()
        {
            invoiceGenerator = new InvoiceGenerator();
            Ride[]         rides    = { new Ride(2.0, 5), new Ride(2.0, 5) };
            RideRepository rideRepo = invoiceGenerator.rideRepository;

            rideRepo.AddRide("100", rides);
            InvoiceSummary summary         = invoiceGenerator.GetInvoiceSummary("100");
            InvoiceSummary expectedSummary = new InvoiceSummary(2, 50.0);

            Assert.AreEqual(expectedSummary, summary);
        }
        public void GivenUserId_RideRepository_ShouldReturn_InvoiceSummary()
        {
            double expected = 206;

            Ride[]         rides           = { new Ride(0.1, 2, RideType.PREMIUM), new Ride(0.1, 10, RideType.NORMAL), new Ride(5, 50, RideType.PREMIUM) };
            RideRepository rideRepoTestObj = new RideRepository();

            rideRepoTestObj.AddRide("user1", rides);
            InvoiceSummary result = rideRepoTestObj.GetInvoice("user1");

            Assert.AreEqual(expected, result.totalFare);
        }
 public void GivenUserId_AndNullRides_RideRepository_ShouldThrow_CabInvoiceException()
 {
     try
     {
         Ride[]         rides           = null;
         RideRepository rideRepoTestObj = new RideRepository();
         rideRepoTestObj.AddRide("user1", rides);
         InvoiceSummary result = rideRepoTestObj.GetInvoice("user1");
     }
     catch (Exception e)
     {
         Assert.AreEqual(e.Message, "Rides Are Null");
     }
 }
Exemple #7
0
        public void GivenUserId_AndArrayOfRides_WhenNormalRide_ShouldReturnArrayOfRidesForParticularUserId()
        {
            Ride[] rides =
            {
                new Ride(1.0, 1),
                new Ride(2.0, 2),
                new Ride(3.0, 2),
                new Ride(4.0, 4),
                new Ride(5.0, 3)
            };
            string         userId         = "123";
            RideRepository rideRepository = new RideRepository();

            rideRepository.AddRide(userId, rides);
            Ride[] actual = rideRepository.GetRides(userId);
            Assert.AreEqual(rides, actual);
        }
        public void GivenUserId_InvoiceServiceGetsListOfRides_ShouldReturnInvoiceSummary()
        {
            /// Arrange
            invoiceGenerator = new InvoiceGenerator(RideType.NORMAL);
            RideRepository repository = new RideRepository();
            string         userId     = "101";

            Ride[] rides = { new Ride(2.0, 9), new Ride(0.1, 1), new Ride(0.2, 1) };
            repository.AddRide(userId, rides);
            ///Act
            Ride[]         rideData               = repository.GetRides(userId);
            InvoiceSummary invoiceSummary         = invoiceGenerator.CalculateFare(rideData);
            InvoiceSummary expectedInvoiceSummary = new InvoiceSummary(3, 39.0, 13.0);

            /// Assert
            Assert.AreEqual(expectedInvoiceSummary, invoiceSummary);
        }
Exemple #9
0
        public void GivenMultipleRidesShouldReturnInvoiceSummarywithAverageFare()
        {
            //Creating instance of invoice generator
            InvoiceGenerator invoiceGenerator = new InvoiceGenerator(RideType.NORMAL);

            Ride[]         rides          = { new Ride(2.0, 5), new Ride(0.1, 1) };
            RideRepository rideRepository = new RideRepository();
            string         userId         = "Vishal";

            rideRepository.AddRide(userId, rides);
            Ride[] rideData = rideRepository.GetRides(userId);
            //Generating Summary for rides
            InvoiceSummary summary         = invoiceGenerator.CalculateFare(rides);
            InvoiceSummary expectedSummary = new InvoiceSummary(2, 30.0, 15);

            //Asserting values with average in equals to formula in invoice summary
            Assert.AreEqual(expectedSummary, summary);
        }
Exemple #10
0
 public void GivenNullRide_WhenTryingToAddToRidelistShould_ReturnCabInvoiceException()
 {
     try
     {
         Ride[] rides =
         {
             new Ride(5, 20),
             null,
             new Ride(2, 10)
         };
         RideRepository rideRepository = new RideRepository();
         rideRepository.AddRide("111", rides);
     }
     catch (CabInvoiceException ex)
     {
         Assert.AreEqual(ex.type, CabInvoiceException.ExceptionType.NULL_RIDES);
     }
 }
Exemple #11
0
        public void GivenUserId_InvoiceServiceShould_ReturnListOfRides()
        {
            Ride[] rides =
            {
                new Ride(1.0, 1),
                new Ride(2.0, 2),
                new Ride(3.0, 2),
                new Ride(4.0, 4),
                new Ride(5.0, 3)
            };
            string           userId           = "12345";
            InvoiceGenerator invoiceGenerator = new InvoiceGenerator(RideType.PREMIUM);
            RideRepository   rideRepository   = new RideRepository();

            rideRepository.AddRide(userId, rides);
            Ride[] actual = rideRepository.GetRides(userId);
            Assert.AreEqual(rides, actual);
        }
        public void GivenInvoiceService_GetsListOfRecords_FromRideRepository()
        {
            string         userId         = "*****@*****.**";
            InvoiceService invoiceService = new InvoiceService();

            Ride[] ride =
            {
                new Ride("Normal", 20, 10),
                new Ride("Normal", 15,  5),
                new Ride("Normal", 10, 3)
            };
            RideRepository rideRepository = new RideRepository();

            rideRepository.AddRide(userId, ride);
            double totalFare = invoiceService.CalculateFare(rideRepository.GetRides(userId));

            Assert.AreEqual(468, totalFare);
        }
        public void GivenInvoiceService_ReturnPremiumAndNormalRides()
        {
            string         userId         = "*****@*****.**";
            InvoiceService invoiceService = new InvoiceService();

            Ride[] ride =
            {
                new Ride("Normal",  15,  5),
                new Ride("Normal",  10,  3),
                new Ride("Premium", 20, 10),
                new Ride("Premium", 15, 20)
            };
            RideRepository rideRepository = new RideRepository();

            rideRepository.AddRide(userId, ride);
            double totalFare = invoiceService.CalculateFare(rideRepository.GetRides(userId));

            Assert.AreEqual(843, totalFare);
        }
Exemple #14
0
        public void GivenUserId_InvoiceServiceGetsListOfRides_ShouldReturnInvoiceSummary()
        {
            /// Arrange
            ///initialising the instance of the invoice generator class
            /// Creating the instance of the ride repository.
            /// Initialising the ride array with details of the ride.
            /// Adding the ride data for the user to the ride repository
            ///Getting the ride data from the ride repository class.
            invoiceGenerator = new InvoiceGenerator(RideType.NORMAL);
            RideRepository repository = new RideRepository();
            string         userId     = "xyz@12";

            Ride[] rides = { new Ride(2.0, 9), new Ride(0.1, 1), new Ride(0.2, 1) };
            repository.AddRide(userId, rides);
            ///Act
            Ride[]         rideData               = repository.GetRides(userId);
            InvoiceSummary invoiceSummary         = invoiceGenerator.CalculateTotalFare(rideData);
            InvoiceSummary expectedInvoiceSummary = new InvoiceSummary(3, 39.0, 13.0);

            /// Assert
            Assert.AreEqual(expectedInvoiceSummary, invoiceSummary);
        }
Exemple #15
0
        public void GivenUserId_ShouldReturnInvoiceSummary()
        {
            // Arrange
            // initialising the object of the invoice generator class
            invoiceGenerator = new InvoiceGenerator(RideType.NORMAL);
            // Creating the object of the ride repository
            RideRepository repository = new RideRepository();
            // Initialising the user ID
            string userID = "akash";

            // Initialising the ride array with details of the ride
            Ride[] rides = { new Ride(2.0, 5), new Ride(0.1, 1) };
            // Adding the ride data for the user to the ride repository
            repository.AddRide(userID, rides);
            // Getting the ride data from the ride repository class using the user ID
            Ride[] rideData = repository.GetRides(userID);
            // Getting the invoice summary when passing the ride Data
            InvoiceSummary invoiceSummary = invoiceGenerator.CalculateAvgFare(rideData);
            // Expected value of the Invoice Summary
            InvoiceSummary expectedInvoiceSummary = new InvoiceSummary(30.0, 2, 15.0);

            // Asserting the comparison between the expected and actual invoice summary
            Assert.AreEqual(expectedInvoiceSummary, invoiceSummary);
        }