public async Task InstructionAddDeliveriesVM_BuildDeliveriesList_IsSelectedPopulated()
        {
            base.ClearAll();

            _fixture.Customize <Order>(md => md.With(x => x.Type, Core.Enums.InstructionType.Deliver));
            _fixture.Customize <ItemAdditional>(md => md.With(x => x.BarcodeScanRequiredForDelivery, true));

            var nonCompletedDeliveryInstructions = _fixture.CreateMany <MobileData>();

            _mockMobileDataRepo.Setup(mdr => mdr.GetNonCompletedInstructionsAsync(It.IsAny <Guid>())).ReturnsAsync(nonCompletedDeliveryInstructions);

            var addDeliveriesVM          = _fixture.Create <InstructionAddDeliveriesViewModel>();
            NavData <MobileData> navData = new NavData <MobileData>()
            {
                Data = nonCompletedDeliveryInstructions.First()
            };

            // set the instruction to already have one "additional instruction"
            var additionalInstruction = nonCompletedDeliveryInstructions.Last();

            navData.GetAdditionalInstructions().Add(additionalInstruction);
            var navID = Guid.NewGuid();

            _navigationService.Setup(ns => ns.GetNavData <MobileData>(navID)).Returns(navData);

            await addDeliveriesVM.Init(navID);

            // the delivery that lives is already added as an additional delivery should be selected
            Assert.True(addDeliveriesVM.DeliveryInstructions.Single(x => x.MobileData == additionalInstruction).IsSelected);
        }
Ejemplo n.º 2
0
        public static DeliveryOptions GetWorseCaseDeliveryOptions(this NavData <MobileData> navData)
        {
            bool customerNameRequiredForDelivery      = false;
            bool customerSignatureRequiredForDelivery = false;
            bool barcodeScanRequiredForDelivery       = false;
            bool bypassCommentsScreen     = true;
            bool bypassCleanClausedScreen = true;


            List <MobileData> instructions = new List <MobileData>()
            {
                navData.Data
            };
            var additionalInstructions = navData.GetAdditionalInstructions();

            instructions.AddRange(additionalInstructions);

            foreach (var instruction in instructions)
            {
                customerNameRequiredForDelivery      = customerNameRequiredForDelivery || instruction.Order.Additional.CustomerNameRequiredForDelivery;
                customerSignatureRequiredForDelivery = customerSignatureRequiredForDelivery || instruction.Order.Additional.CustomerSignatureRequiredForDelivery;
                barcodeScanRequiredForDelivery       = barcodeScanRequiredForDelivery || instruction.Order.Items.Any(i => i.Additional.BarcodeScanRequiredForDelivery);
                bypassCleanClausedScreen             = bypassCleanClausedScreen && !instruction.Order.Items.Any(i => !i.Additional.BypassCleanClausedScreen);
                bypassCommentsScreen = bypassCommentsScreen && !instruction.Order.Items.Any(i => !i.Additional.BypassCommentsScreen);
            }

            return(new DeliveryOptions(customerNameRequiredForDelivery,
                                       customerSignatureRequiredForDelivery,
                                       barcodeScanRequiredForDelivery,
                                       bypassCommentsScreen,
                                       bypassCleanClausedScreen));
        }
Ejemplo n.º 3
0
        public static IEnumerable <MobileData> GetAllInstructions(this NavData <MobileData> navData)
        {
            List <MobileData> mobileDatas = new List <MobileData>();

            mobileDatas.Add(navData.Data);
            mobileDatas.AddRange(navData.GetAdditionalInstructions());

            return(mobileDatas);
        }
        public void InstructionAddDeliveriesVM_Done_RemoveDelivery()
        {
            base.ClearAll();

            _fixture.Customize <Order>(md => md.With(x => x.Type, Core.Enums.InstructionType.Deliver));
            _fixture.Customize <ItemAdditional>(md => md.With(x => x.BarcodeScanRequiredForDelivery, true));

            var nonCompletedDeliveryInstructions = _fixture.CreateMany <MobileData>();

            _mockMobileDataRepo.Setup(mdr => mdr.GetNonCompletedInstructionsAsync(It.IsAny <Guid>())).ReturnsAsync(nonCompletedDeliveryInstructions);

            var addDeliveriesVM          = _fixture.Create <InstructionAddDeliveriesViewModel>();
            NavData <MobileData> navData = new NavData <MobileData>()
            {
                Data = nonCompletedDeliveryInstructions.First()
            };

            // set the instruction to already have one "additional instruction"
            var additionalInstruction = nonCompletedDeliveryInstructions.Last();

            navData.GetAdditionalInstructions().Add(additionalInstruction);

            var navID = Guid.NewGuid();

            _navigationService.Setup(ns => ns.GetNavData <MobileData>(navID)).Returns(navData);

            addDeliveriesVM.Init(navID);

            // make sure all the items are unselected
            foreach (var delivery in addDeliveriesVM.DeliveryInstructions)
            {
                delivery.IsSelected = false;
            }

            // now excute the done command
            addDeliveriesVM.DoneCommand.Execute(null);

            // check that the selected item has been removed from the additional deliveries
            Assert.Equal(0, navData.GetAdditionalInstructions().Count);

            // since user pressed "done" the modal should have returned with true
            _mockMessenger.Verify(mm => mm.Publish(It.Is <ModalNavigationResultMessage <bool> >(msg => msg.Result == true)), Times.Once);
        }
        public async Task InstructionAddDeliveriesVM_BuildDeliveriesList_Done_AddDelivery()
        {
            base.ClearAll();

            _fixture.Customize <Order>(md => md.With(x => x.Type, Core.Enums.InstructionType.Deliver));
            _fixture.Customize <ItemAdditional>(md => md.With(x => x.BarcodeScanRequiredForDelivery, true));

            var nonCompletedDeliveryInstructions = _fixture.CreateMany <MobileData>();

            _mockMobileDataRepo.Setup(mdr => mdr.GetNonCompletedInstructionsAsync(It.IsAny <Guid>())).ReturnsAsync(nonCompletedDeliveryInstructions);

            var addDeliveriesVM          = _fixture.Create <InstructionAddDeliveriesViewModel>();
            NavData <MobileData> navData = new NavData <MobileData>()
            {
                Data = nonCompletedDeliveryInstructions.First()
            };

            var navID = Guid.NewGuid();

            _navigationService.Setup(ns => ns.GetNavData <MobileData>(navID)).Returns(navData);

            await addDeliveriesVM.Init(navID);

            // select one of the deliveries
            var selectedDelivery = addDeliveriesVM.DeliveryInstructions.Last();

            selectedDelivery.IsSelected = true;

            // now excute the done command
            addDeliveriesVM.DoneCommand.Execute(null);

            // check that the selected item has been added to the additional deliveries
            Assert.Equal(1, navData.GetAdditionalInstructions().Count);
            Assert.Equal(selectedDelivery.MobileData, navData.GetAdditionalInstructions().First());

            // since user pressed "done" the modal should have returned with true
            _mockMessenger.Verify(mm => mm.Publish(It.Is <ModalNavigationResultMessage <bool> >(msg => msg.Result == true)), Times.Once);
        }
Ejemplo n.º 6
0
        public static IEnumerable <MobileApplicationDataChunkContentActivity> GetAllDataChunks(this NavData <MobileData> navData)
        {
            List <MobileApplicationDataChunkContentActivity> dataChunks = new List <MobileApplicationDataChunkContentActivity>();

            dataChunks.Add(navData.GetDataChunk());

            var additionalInstructions = navData.GetAdditionalInstructions();

            foreach (var additionalInstruction in additionalInstructions)
            {
                dataChunks.Add(navData.GetAdditionalDataChunk(additionalInstruction));
            }

            return(dataChunks);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// A viewmodel can use this method to implement a standard respond to a GatewayInstructionNotificationMessage.
        /// </summary>
        /// <param name="viewModel">The viewmodel that has received the notification message</param>
        /// <param name="message">The message received</param>
        /// <param name="navData">The viewmodel's navigation data (must be of type NavData<MobileData>)</param>
        /// <param name="refreshPage">
        /// An Action delegate that should be invoked if the page needs to be refreshed.
        /// This can be null if no refresh action is required.
        /// Note that this action will not be called on the UI thread, so the viewmodel should use InvokeOnMainThread() to execute any code that modifies the UI.</param>
        public static async Task RespondToInstructionNotificationAsync(this IInstructionNotificationViewModel viewModel, Messages.GatewayInstructionNotificationMessage message, NavData <MobileData> navData, Action refreshPage)
        {
            if (navData.Data.ProgressState == Enums.InstructionProgress.Complete)
            {
                return;
            }

            var instructionID = navData.Data.ID;

            var isVisible = !(viewModel is IVisible) || ((IVisible)viewModel).IsVisible;

            if (message.DeletedInstructionIDs.Contains(instructionID))
            {
                // Note that if the primary current instruction has been deleted and this viewmodel is not visible then there is nothing we can do here.
                // We presume that the active viewmodel will have also responded to this message and will have redirected back to the Manifest screen.
                if (isVisible)
                {
                    await Mvx.Resolve <ICustomUserInteraction>().AlertAsync("Redirecting you back to the manifest screen", "This instruction has been deleted.");

                    await Mvx.Resolve <INavigationService>().GoToManifestAsync();
                }
            }
            else
            {
                var additionalInstructions   = navData.GetAdditionalInstructions();
                var additionalInstructionIDs = additionalInstructions.Select(i => i.ID).ToList();

                var isThisInstructionUpdated          = message.UpdatedInstructionIDs.Contains(instructionID);
                var updatedAdditionalInstructionIDs   = message.UpdatedInstructionIDs.Intersect(additionalInstructionIDs).ToList();
                var deletedAdditionalInstructionIDs   = message.DeletedInstructionIDs.Intersect(additionalInstructionIDs).ToList();
                var haveAdditionalInstructionsChanged = updatedAdditionalInstructionIDs.Any() || deletedAdditionalInstructionIDs.Any();

                if (isThisInstructionUpdated || haveAdditionalInstructionsChanged)
                {
                    if (isVisible)
                    {
                        var title = haveAdditionalInstructionsChanged ? "Instructions have been changed." : "This instruction has been updated.";
                        var msg   = refreshPage == null ? "Data may have changed." : "Refreshing the page.";
                        await Mvx.Resolve <ICustomUserInteraction>().AlertAsync(msg, title);
                    }

                    var repositories = Mvx.Resolve <Repositories.IRepositories>();

                    if (isThisInstructionUpdated)
                    {
                        navData.Data = await repositories.MobileDataRepository.GetByIDAsync(instructionID);
                    }

                    foreach (var updatedAdditionalInstructionID in updatedAdditionalInstructionIDs)
                    {
                        var instructionToUpdate = additionalInstructions.FirstOrDefault(ai => ai.ID == updatedAdditionalInstructionID);

                        if (instructionToUpdate != null)
                        {
                            additionalInstructions.Remove(instructionToUpdate);
                            additionalInstructions.Add(await repositories.MobileDataRepository.GetByIDAsync(updatedAdditionalInstructionID));
                        }
                    }

                    foreach (var deletedAdditionalInstructionID in deletedAdditionalInstructionIDs)
                    {
                        var instructionToDelete = additionalInstructions.FirstOrDefault(ai => ai.ID == deletedAdditionalInstructionID);

                        if (instructionToDelete != null)
                        {
                            additionalInstructions.Remove(instructionToDelete);
                        }
                    }

                    if (refreshPage != null)
                    {
                        refreshPage();
                    }
                }
            }
        }