Esempio n. 1
0
        public async Task UpdateExpiredRidesAndOrders_WhenCalled_NotifiesTwice()
        {
            var _unitOfWork = NSubstitute.Substitute.For <IUnitOfWork>();
            var orderList   = new List <Order>();
            var order       = new Order();
            var ride        = new Ride();

            ride.StartDestination = new Address("city", 1000, "street", 1);
            ride.EndDestination   = new Address("city", 1000, "street", 1);
            order.Rides.Add(ride);
            orderList.Add(order);
            var rideList = new List <Ride>();

            rideList.Add(ride);
            _unitOfWork.OrderRepository.FindOrdersWithExpiredRides().ReturnsForAnyArgs(orderList);
            _unitOfWork.RideRepository.FindExpiredUnmatchedRides().ReturnsForAnyArgs(rideList);
            var push = Substitute.For <IPushNotificationFactory>();

            push.GetPushNotification().ReturnsForAnyArgs(new PushNotification(), new PushNotification());
            var center = Substitute.For <IPushNotificationService>();

            IExpirationService _uut = new ExpirationService(_unitOfWork, push, center);
            await _uut.UpdateExpiredRidesAndOrders();

            center.ReceivedWithAnyArgs(2).SendAsync(null);
        }
        public async Task UpdateExpiredRidesAndOrders_UpdatesOrderToExpired_OrdersHasBeenUpdated()
        {
            await CreateRideWithLogin();
            await CreateRide(RideType.SoloRide);

            ClearHeaders();
            await LoginOnCustomerAccount("*****@*****.**");
            await DepositToCustomer(1000);
            await CreateRide(RideType.SharedRide);

            //Sleep to allow task to run(hopefully)
            Thread.Sleep(2000);

            var expiration = new ExpirationService(
                new UnitOfWork(_factory.CreateContext(), Substitute.For <IIdentityUserRepository>()),
                new PushNotificationFactory(),
                new FakeAppCenterPushNotificationService()
                );
            await expiration.UpdateExpiredRidesAndOrders();

            using (var context = _factory.CreateContext())
            {
                Assert.That(context.Orders.First().Status, Is.EqualTo(OrderStatus.Expired));
                Assert.That(context.Rides.Where(ride => ride.Status != RideStatus.Expired).Any, Is.EqualTo(false));
                Assert.That(context.Customers.Where(customer => customer.ReservedAmount != 0).Any, Is.EqualTo(false));
            }
        }
Esempio n. 3
0
        public async Task UpdateExpiredRidesAndOrders_WhenCalled_SavesChanges()
        {
            var _unitOfWork = NSubstitute.Substitute.For <IUnitOfWork>();

            //Create
            var orderList = new List <Order>();
            var order     = new Order();
            var ride      = new Ride();

            //Set
            ride.StartDestination = new Address("city", 1000, "street", 1);
            ride.EndDestination   = new Address("city", 1000, "street", 1);
            order.Rides.Add(ride);
            orderList.Add(order);
            //Create and set
            var rideList = new List <Ride>();

            rideList.Add(ride);

            //Stub out
            _unitOfWork.OrderRepository.FindOrdersWithExpiredRides().ReturnsForAnyArgs(orderList);
            _unitOfWork.RideRepository.FindExpiredUnmatchedRides().ReturnsForAnyArgs(rideList);


            var push    = Substitute.For <IPushNotificationFactory>();
            var pushNot = new PushNotification();

            //VERY Important that push notification gets a new otherwise it will throw misleading exception
            //For all. So 1 order with 1 ride, and 1 ride. aka two.
            push.GetPushNotification().ReturnsForAnyArgs(new PushNotification(), new PushNotification());
            var center = Substitute.For <IPushNotificationService>();

            IExpirationService _uut = new ExpirationService(_unitOfWork, push, center);
            await _uut.UpdateExpiredRidesAndOrders();

            _unitOfWork.Received(1).SaveChangesAsync();
        }
Esempio n. 4
0
 public ExpirationServiceTests()
 {
     _mockDeliveryRepository = new Mock <IDeliveryRepository>();
     _expirationService      = new ExpirationService(_mockDeliveryRepository.Object);
 }