public void Get_Active_Matching_Offers_For_User() { //Arrange var offerSaved = _offerService.CreateOffer(MongoDbTestUtil.CreateOffer("Little Jebbies 5 Cent Coffee")); _offerService.ActivateOffer(offerSaved.Id); var offerSaved2 = _offerService.CreateOffer(MongoDbTestUtil.CreateOffer()); User user1 = MongoDbTestUtil.CreateUserCustomer(); bool exists = _userRepo.DoesAccountExist(user1.Email, user1.Password); if (exists) { _userRepo.DeleteUser(user1.Email, user1.Password); } var user = _userService.CreateUser(user1); var profileId = _userService.GetProfileID(user.UserId); var savedProfile = _userService.SaveProfile(MongoDbTestUtil.CreateProfileWithPreferences(user.UserId, profileId)); //Act var matchingOffers = _match.GetActiveMatchesForUser(user.UserId); var offersFound = matchingOffers.FirstOrDefault().Value; //Assert Assert.IsTrue(offersFound.Count == 1); var matchingOffer = offersFound.FirstOrDefault(); Assert.IsTrue(matchingOffer.Name == "Little Jebbies 5 Cent Coffee"); Assert.IsTrue(matchingOffer.Category == "discounts"); _userRepo.DeleteProfile(savedProfile.Id); var profileDeleted = _userRepo.Profiles.FirstOrDefault(x => x.Id == savedProfile.Id); Assert.IsTrue(profileDeleted == null); _userRepo.DeleteUser(user1.Email, user1.Password); var userGet = _userRepo.GetUser(user.Id); Assert.IsNull(userGet); //Delete offers _offerRepo.DeleteOffer(offerSaved.Id); _offerRepo.DeleteOffer(offerSaved2.Id); }
public void GetJobOffersTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Create_Offer") .Options; var job = new Job { Id = "jobid" }; var account = new Account { UserName = "******", CompanyProfile = new CompanyProfile { Id = "id" } }; int result; using (var context = new ApplicationDbContext(options)) { context.Jobs.Add(job); context.Users.Add(account); context.SaveChanges(); IOfferService service = new OfferService(context); service.CreateOffer(12, DateTime.Now, DateTime.Now, "comment", "jobid", "username"); result = context.Offers.Count(); } Assert.Equal(1, result); }
public void NullObject_ReturnsNegativeOne() { // Arrange... var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object); // Act... var result = offerService.CreateOffer(null); // Assert... Assert.AreEqual(-1, result); }
public void Exception_ReturnsNegativeOne() { // Arrange... dbMock.Setup(m => m.SaveChanges()).Throws <Exception>(); var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object); var testValue = true; // Act... var result = offerService.CreateOffer(new OfferDTO() { IsActive = testValue }); // Assert... Assert.AreEqual(-1, result); }
public void Exception_LogsError() { // Arrange... dbMock.Setup(m => m.SaveChanges()).Throws <Exception>(); var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object); var testValue = true; // Act... var result = offerService.CreateOffer(new OfferDTO() { IsActive = testValue }); // Assert... loggerMock.Verify(l => l.LogError(It.IsAny <string>(), It.IsAny <Exception>()), Times.Once); }
public void DateModifiedSupplied_CreatedWithDateModifiedNull() { // Arrange... Offer offer = null; dbMock.Setup(m => m.Offer.Add(It.IsAny <Offer>())).Callback((Offer o) => { offer = o; }); dbMock.Setup(m => m.SaveChanges()).Returns(1); var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object); // Act... var result = offerService.CreateOffer(new OfferDTO() { DateModified = DateTime.Now }); // Assert... Assert.That(offer.DateModified, Is.Null); }
public void DateCreated_DateCreatedSaved() { // Arrange... Offer offer = null; dbMock.Setup(m => m.Offer.Add(It.IsAny <Offer>())).Callback((Offer o) => { offer = o; }); dbMock.Setup(m => m.SaveChanges()).Returns(1); var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object); // Act... var result = offerService.CreateOffer(new OfferDTO() { Price = 1.99M }); // Assert... Assert.That(offer.DateCreated, Is.EqualTo(DateTime.Now).Within(TimeSpan.FromSeconds(1))); }
public void PriceSupplied_PriceSaved() { // Arrange... Offer offer = null; dbMock.Setup(m => m.Offer.Add(It.IsAny <Offer>())).Callback((Offer o) => { offer = o; }); dbMock.Setup(m => m.SaveChanges()).Returns(1); var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object); var testValue = 1.99M; // Act... var result = offerService.CreateOffer(new OfferDTO() { Price = 1.99M }); // Assert... Assert.AreEqual(testValue, offer.Price); }
public void IsActiveSupplied_CreateAsActive() { // Arrange... Offer offer = null; dbMock.Setup(m => m.Offer.Add(It.IsAny <Offer>())).Callback((Offer o) => { offer = o; }); dbMock.Setup(m => m.SaveChanges()).Returns(1); var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object); var testValue = true; // Act... var result = offerService.CreateOffer(new OfferDTO() { IsActive = testValue }); // Assert... Assert.That(offer.IsActive, Is.EqualTo(testValue)); }
public void ProductIdExists_Created() { // Arrange... Offer offer = null; dbMock.Setup(m => m.Offer.Add(It.IsAny <Offer>())).Callback((Offer o) => { offer = o; }); dbMock.Setup(m => m.SaveChanges()).Returns(0); var productId = 123; productServiceMock.Setup(p => p.Exists(It.Is <int>(i => i == productId))).Returns(true); var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object); // Act... var result = offerService.CreateOffer(new OfferDTO() { ProductId = productId }); // Assert... Assert.That(offer.ProductId, Is.EqualTo(productId)); }
public void ProductIdDoesNotExist_ReturnsNegativeOne() { // Arrange... Offer offer = null; dbMock.Setup(m => m.Offer.Add(It.IsAny <Offer>())).Callback((Offer o) => { offer = o; }); dbMock.Setup(m => m.SaveChanges()).Returns(0); var productId = 123; productServiceMock.Setup(p => p.Exists(It.Is <int>(i => i == productId))).Returns(false); var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object); // Act... var result = offerService.CreateOffer(new OfferDTO() { ProductId = productId }); // Assert... Assert.AreEqual(-1, result); }
public void DateModifiedNull_Created() { // Arrange... Offer offer = null; dbMock.Setup(m => m.Offer.Add(It.IsAny <Offer>())) .Callback((Offer o) => { offer = o; offer.OfferId = 123; }); dbMock.Setup(m => m.SaveChanges()).Returns(1); var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object); // Act... var result = offerService.CreateOffer(new OfferDTO() { Price = 1.99M }); // Assert... Assert.That(result, Is.GreaterThan(0)); }
public static void Main(string[] args) { UserService UserService = new UserService(); BookingService BookingService = new BookingService(); OfferService OfferService = new OfferService(); OfferRequestService OfferRequestService = new OfferRequestService(); PaymentService PaymentService = new PaymentService(); LocationService LocationService = new LocationService(); while (true) { Login: Console.WriteLine("1 -> SignUp\n2 -> SignIn\n0 -> Exit"); IEnums.CarPoolOptions Option = (IEnums.CarPoolOptions)Convert.ToInt32(Console.ReadLine()); switch (Option) { case IEnums.CarPoolOptions.SignUp: { Console.WriteLine("enter name:"); string Name = Console.ReadLine(); Console.WriteLine("enter Password:"******"Name: " + NewUser.Name); Console.WriteLine("UserId: " + NewUser.UserId); Console.WriteLine("Account Created Successfully!!"); break; } case IEnums.CarPoolOptions.SignIn: { Console.WriteLine("enter UserId:"); string UserId = Console.ReadLine(); Console.WriteLine("enter Password:"******"Your Booking Status: " + Booking.Status); if (Booking.Status.Equals(IEnums.BookingStatus.Confirmed)) { Offer Offer = OfferService.GetDriverDetails(Booking.RiderId); Console.WriteLine("Drivername: " + Offer.DriverName + ", VehicleNumber: " + Offer.VehicleRegNumber + ", VehicleModel: " + Offer.VehicleModel); } Console.ReadKey(); Console.WriteLine("1 -> Book a Ride\n5 -> Display bookings history\n6 -> Display created offers history\n7 -> Cancel Ride\n10 -> Pay\n11 -> Add money to wallet\n" + "13 -> wallet Balance\n14 -> display payment History\n0 -> Logout"); } else if (OfferService.AnyActiveOffer(UserId)) { Console.WriteLine("4 -> Display Offer requests\n5 -> Display bookings history\n" + "6 -> Display offers history\n8 -> Cancel Offer\n9 -> End Ride\n15 -> End Offer\n10 -> Pay\n11 -> Add money to wallet\n" + "13 -> wallet Balance\n14 -> display payment History\n0 -> Logout"); } else { Console.WriteLine("1 -> Book a Ride\n2 -> Offer a Ride\n5 -> Display booking history\n" + "6 -> Display offers history\n10 -> Pay\n11 -> Add money to wallet\n" + "13 -> wallet Balance\n14 -> display payment History\n0 -> Logout"); } IEnums.UserOptions UserOption = (IEnums.UserOptions)Convert.ToInt32(Console.ReadLine()); switch (UserOption) { case IEnums.UserOptions.BookARide: { if (PaymentService.IsEligibleToBook(UserId)) { Console.WriteLine("enter pick-up location:"); string PickUpLocation = Console.ReadLine(); Location FromLocation = LocationService.GetLocation(PickUpLocation.ToUpper()); if (FromLocation != null) { Console.WriteLine("enter Destination:"); string Destination = Console.ReadLine(); Location ToLocation = LocationService.GetLocation(Destination.ToUpper()); if (ToLocation != null) { Console.WriteLine("number of passengers:"); int NumberOfPassengers = Convert.ToInt32(Console.ReadLine()); List <Offer> ActiveOffers = OfferService.DisplayActiveOffers(PickUpLocation.ToUpper(), Destination.ToUpper(), NumberOfPassengers); if (ActiveOffers.Count == 0) { Console.WriteLine("no active offers"); } else { foreach (var offer in ActiveOffers) { Console.WriteLine("Drivername: " + offer.DriverName + " RiderId " + offer.RiderId + " Vehicle Number: " + offer.VehicleRegNumber + " Vehicle Model: " + offer.VehicleModel + " Phone Number: " + offer.PhoneNumber); } Console.WriteLine("enter Riders userId to select the offer\nRider UserId:"); string RiderId = Console.ReadLine(); OfferRequestService.SendRideRequest(FromLocation, ToLocation, NumberOfPassengers, RiderId.ToUpper(), UserId.ToUpper()); Booking NewBooking = BookingService.CreateBooking(RiderId, UserId, FromLocation, ToLocation, NumberOfPassengers); } } else { Console.WriteLine(Destination + " not found"); } } else { Console.WriteLine(PickUpLocation + " not found"); } } else { Console.WriteLine("pay your pending dues to book for next ride"); Console.WriteLine("do you want to pay now?"); Console.WriteLine("1 -> paynow\n2 -> later"); IEnums.PaymentDecision Decision = (IEnums.PaymentDecision)Convert.ToInt32(Console.ReadLine()); if (Decision.Equals(IEnums.PaymentDecision.Now)) { List <Payment> PaymentDues = PaymentService.DisplayPendingDues(UserId); foreach (var payment in PaymentDues) { Console.WriteLine("BookingId: " + payment.PaymentID + ", amount to be paid: " + payment.Fair); } Console.WriteLine("enter paymentId: "); string PaymentId = Console.ReadLine(); if (PaymentService.Pay(PaymentId)) { Console.WriteLine("payment done successfully!!"); } else { Console.WriteLine("insufficient wallet balance"); Console.WriteLine("Do you want to add money to the wallet?"); Console.WriteLine("1 -> yes\n2 -> no"); IEnums.YesOrNo Choice = (IEnums.YesOrNo)Convert.ToInt32(Console.ReadLine()); if (Choice.Equals(IEnums.YesOrNo.Yes)) { Console.WriteLine("enter amount: "); double Amount = Convert.ToDouble(Console.ReadLine()); UserService.AddMoneyToWallet(Amount, UserId); Console.WriteLine("Money added successfully!!"); } } } } break; } case IEnums.UserOptions.OfferARide: { Console.WriteLine("enter name:"); string Name = Console.ReadLine(); Console.WriteLine("enter From location:"); string FromLocation = Console.ReadLine(); Location StartPoint = LocationService.GetLocation(FromLocation.ToUpper()); if (StartPoint != null) { Console.WriteLine("enter To location:"); string ToLocation = Console.ReadLine(); Location EndPoint = LocationService.GetLocation(ToLocation.ToUpper()); if (EndPoint != null) { Console.WriteLine("enter Availability"); int Availability = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter Vehicle Number"); string VehicleNumber = Console.ReadLine(); Console.WriteLine("enter Vehicle Model"); string VehicleModel = Console.ReadLine(); if (OfferService.VehicleVerification(VehicleNumber)) { Offer Offer = OfferService.CreateOffer(Name.ToUpper(), UserId, StartPoint, EndPoint, Availability, VehicleNumber.ToUpper(), VehicleModel.ToUpper()); List <Location> ViaPoints = LocationService.GetViaPoints(StartPoint, EndPoint); if (ViaPoints.Count != 0) { int SelectViaPoint = 0; do { Console.WriteLine("you might touch these locations: "); foreach (var location in ViaPoints) { Console.WriteLine(location.Index + " -> " + location.Name); } Console.WriteLine("0 -> end"); Console.WriteLine("selects the locations: "); SelectViaPoint = Convert.ToInt32(Console.ReadLine()); IEnums.LocationIndex LocationIndex = (IEnums.LocationIndex)SelectViaPoint; OfferService.AddViaPoint(Offer, LocationIndex); } while (SelectViaPoint != 0); Console.WriteLine("offer created successfully!!"); } else { Console.WriteLine("Cannot use same vehicle for two offers"); } } } else { Console.WriteLine(ToLocation + " not found"); } } else { Console.WriteLine(FromLocation + " not found"); } break; } case IEnums.UserOptions.DisplayCurrentBookingStatus: { Booking Booking = BookingService.ViewBookingStatus(UserId); if (Booking != null) { Console.WriteLine("Rider: " + Booking.RiderId + " From " + Booking.FromLocation + " To " + Booking.ToLocation + " Status " + Booking.Status); } else { Console.WriteLine("you have no current bookings"); } break; } case IEnums.UserOptions.DisplayOfferRequests: { if (OfferRequestService.AnyOfferRequest(UserId)) { List <OfferRequest> OfferRequests = OfferRequestService.DisplayOfferRequests(UserId); foreach (var offerRequest in OfferRequests) { Console.WriteLine("RequestId: " + offerRequest.RequestId + " from " + offerRequest.FromLocation + " to " + offerRequest.ToLocation); } Console.WriteLine("enter the RequestId to accept or reject offer request"); string RequestId = Console.ReadLine(); Console.WriteLine("1 -> Accept offer\n2 -> reject offer"); IEnums.Decisions Decision = (IEnums.Decisions)Convert.ToInt32(Console.ReadLine()); OfferRequestService.OfferRequestApproval(RequestId.ToUpper(), Decision); } else { Console.WriteLine("no offers requests to display"); } break; } case IEnums.UserOptions.DisplayBookingHistory: { List <Booking> AllBookings = BookingService.DisplayBookingsHistory(UserId); if (AllBookings != null) { foreach (var booking in AllBookings) { Console.WriteLine("From: " + booking.FromLocation.Name + " to " + booking.ToLocation.Name + " Status: " + booking.Status); } } else { Console.WriteLine("no bookings to display"); } break; } case IEnums.UserOptions.DisplayOfferHistory: { List <Offer> AllOffers = OfferService.DisplayOffersHistory(UserId); if (AllOffers != null) { foreach (var offer in AllOffers) { Console.WriteLine("From: " + offer.FromLocation.Name + " to " + offer.ToLocation.Name + " Status: " + offer.Status); } } else { Console.WriteLine("no offers to display"); } break; } case IEnums.UserOptions.CancelRide: { List <Booking> ActiveBookings = BookingService.DisplayActiveBookings(UserId); if (ActiveBookings != null) { foreach (var booking in ActiveBookings) { Console.WriteLine("RiderId: " + booking.RiderId + " From " + booking.FromLocation.Name + " to " + booking.ToLocation.Name + " Status: " + booking.Status); } Console.WriteLine("enter RiderId to cancel: "); string RiderId = Console.ReadLine(); BookingService.CancelRide(RiderId); Console.WriteLine("Ride Cancelled"); } else { Console.WriteLine("no active bookings to cancel"); } break; } case IEnums.UserOptions.CancelOffer: { OfferService.CancelOffer(UserId); Console.WriteLine("Offer Cancelled"); break; } case IEnums.UserOptions.EndRide: { List <string> PassengersInVehicle = BookingService.DisplayPassengersInVehicle(UserId); foreach (var Passenger in PassengersInVehicle) { Console.WriteLine("RideeId: " + Passenger); } Console.WriteLine("enter ridee Id"); string RideeId = Console.ReadLine(); BookingService.EndRide(UserId, RideeId); break; } case IEnums.UserOptions.Pay: { List <Payment> PendingPayments = PaymentService.DisplayPendingDues(UserId); if (PendingPayments.Count != 0) { foreach (var payment in PendingPayments) { Console.WriteLine("PaymentId: " + payment.PaymentID + ", Fair: " + payment.Fair); } Console.WriteLine("enter paymentId: "); string PaymentId = Console.ReadLine(); if (PaymentService.Pay(PaymentId)) { Console.WriteLine("payment done successfully!!"); } else { Console.WriteLine("insufficient wallet balance"); Console.WriteLine("Do you want to add money to the wallet?"); Console.WriteLine("1 -> yes\n2 -> no"); IEnums.YesOrNo Choice = (IEnums.YesOrNo)Convert.ToInt32(Console.ReadLine()); if (Choice.Equals(IEnums.YesOrNo.Yes)) { Console.WriteLine("enter amount: "); double Amount = Convert.ToDouble(Console.ReadLine()); UserService.AddMoneyToWallet(Amount, UserId); Console.WriteLine("Money added successfully!!"); } } } else { Console.WriteLine("no pending dues"); } break; } case IEnums.UserOptions.AddMoneyToWallet: { Console.WriteLine("enter amount: "); double Amount = Convert.ToDouble(Console.ReadLine()); UserService.AddMoneyToWallet(Amount, UserId); Console.WriteLine("Money added successfully!!"); break; } case IEnums.UserOptions.WalletBalance: { Console.WriteLine("your wallet balance: " + UserService.DisplayWalletBalance(UserId)); break; } case IEnums.UserOptions.DisplayPaymentHistory: { List <Payment> AllPayments = PaymentService.DisplayPaymentHistory(UserId); if (AllPayments.Count != 0) { foreach (var payment in AllPayments) { if (payment.RideeId.Equals(UserId)) { Console.WriteLine("PaymentId: " + payment.PaymentID + " to " + payment.RiderId + " Status: " + payment.Status); } else if (payment.RiderId.Equals(UserId)) { Console.WriteLine("PaymentId: " + payment.PaymentID + " from " + payment.RideeId + " Status: " + payment.Status); } } } else { Console.WriteLine("you have no payments to display"); } break; } case IEnums.UserOptions.Logout: { goto Login; } } } } else { Console.WriteLine("Incorrect userId or password"); } break; } case IEnums.CarPoolOptions.Exit: { System.Environment.Exit(0); break; } } } }