public async Task Should_Save_AnInvoiceWithLines()
        {
            var factory      = AbstractDomainWrapperFactory.GetFactory(_dataServices);
            var invoice      = factory.CreateInvoice("28982");
            var invoiceDto   = invoice.Value;
            var firstKey1    = string.Empty;
            var secondKey1   = string.Empty;
            int numberLiFact = 0;

            using (var dbConnection = SqlExecutor.OpenNewDbConnection())
            {
                var pageAndCount = await dbConnection.GetPageCount <LIFAC>().ConfigureAwait(false);

                numberLiFact = pageAndCount.Item1;
            }
            numberLiFact++;
            firstKey1 = numberLiFact.ToString();
            numberLiFact++;
            secondKey1              = numberLiFact.ToString();
            invoiceDto.CLIENTE_FAC  = "129231";
            invoiceDto.BRUTO_FAC    = 1000;
            invoiceDto.BASE_FAC     = 1000;
            invoiceDto.CONTRATO_FAC = "128283";


            var item0 = new InvoiceSummaryDto()
            {
                Description = "Lamps",
                Subtotal    = 0,
                FileNumber  = "1",
                VehicleCode = "9202920",
                Iva         = 19,
                Price       = 170,
                User        = "******",
                Unity       = "M",
                Number      = "0",
                Quantity    = 1,
                IsNew       = true,
                IsValid     = true,
                KeyId       = firstKey1
            };
            var item1 = new InvoiceSummaryDto()
            {
                Discount    = 0,
                Description = "Lamps",
                Subtotal    = 270,
                FileNumber  = "1",
                Number      = "1",
                VehicleCode = "9202920",
                Iva         = 19,
                Price       = 100,
                User        = "******",
                Unity       = "M",
                Quantity    = 1,
                IsNew       = true,
                KeyId       = secondKey1
            };

            var invoiceList = new List <InvoiceSummaryDto> {
                item0, item1
            };

            invoice.Value.InvoiceItems = invoiceList;
            var dataFactory = _dataServices.GetInvoiceDataServices();
            await dataFactory.DeleteAsync(invoice);

            // act
            var retValue = await dataFactory.SaveAsync(invoice);

            // assert
            var invoiceValue = await dataFactory.GetDoAsync(invoice.Value.NUMERO_FAC);

            Assert.NotNull(invoiceValue);
            Assert.AreEqual(retValue, true);
            Assert.IsTrue(invoiceValue.Valid);
            var value = invoiceValue.Value;

            Assert.AreEqual(invoiceDto.CLIENTE_FAC, value.CLIENTE_FAC);
            Assert.AreEqual(invoiceDto.BRUTO_FAC, value.BRUTO_FAC);
            Assert.AreEqual(invoiceDto.BASE_FAC, value.BASE_FAC);
            Assert.AreEqual(invoiceDto.CONTRATO_FAC, value.CONTRATO_FAC);
            var invoiceLines = value.InvoiceItems.Except(invoiceList);

            Assert.AreEqual(0, invoiceLines.Count());
        }
        /// <summary>
        /// InvoiceInfoViewModel.
        /// </summary>
        /// <param name="dataServices">DataServices</param>
        /// <param name="dialogServices"></param>
        /// <param name="manager"></param>
        /// <param name="container"></param>
        /// <param name="regionManager"></param>
        /// <param name="controller"></param>

        public InvoiceInfoViewModel(IDataServices dataServices,
                                    IDialogService dialogServices,
                                    IEventManager manager,

                                    IRegionManager regionManager,
                                    IInteractionRequestController controller) : base(dataServices,
                                                                                     controller,
                                                                                     dialogServices,
                                                                                     manager)
        {
            _dataServices       = dataServices;
            _regionManager      = regionManager;
            _invoiceDataService = _dataServices.GetInvoiceDataServices();

            SourceView          = new ObservableCollection <InvoiceSummaryDto>();
            AssistMapper        = _dataServices.GetAssistDataServices().Mapper;
            ItemChangedCommand  = new Prism.Commands.DelegateCommand <IDictionary <string, object> >(OnChangedCommand);
            NavigateCommand     = new DelegateCommand <object>(OnNavigate);
            AssistCommand       = new DelegateCommand <object>(OnAssistCommand);
            AddNewClientCommand = new DelegateCommand <object>(OnAddNewClientCommand);
            OpenContractCommand = new DelegateCommand <object>(OnOpenContract);
            OpenVehiclesCommand = new DelegateCommand <object>(OnOpenVehicles);
            AssistExecuted     += OnAssistExecuted;
            CompanyName         = String.Empty;
            AddressName         = String.Empty;
            List <string> colList;
            var           genericInovice = new InvoiceSummaryDto();

            colList = genericInovice.GetType().GetProperties().Select(value => value.Name).ToList();

            GridColumns = new List <string>()
            {
                "AgreementCode", "VehicleCode", "Opciones", "Description", "Quantity", "Price", "Discount", "Subtotal",
                "Unity", "Iva"
            };

            /*
             * This is a cell grid presentation item
             */
            var presenter = new ObservableCollection <CellPresenterItem>()
            {
                new NavigationAwareItem()
                {
                    DataTemplateName = "NavigateInvoiceItem", MappingName = "AgreementCode", RegionName = RegionNames.LineRegion
                },
                new NavigationAwareItem()
                {
                    DataTemplateName = "NavigateVehicleItem", MappingName = "VehicleCode", RegionName = RegionNames.LineRegion
                }
            };

            CellGridPresentation = presenter;
            EventManager.RegisterObserverSubsystem(InvoiceModule.InvoiceSubSystem, this);
            var gid = Guid.NewGuid();

            GridIdentifier  = GridIdentifiers.InvoiceLineGrids;
            ViewModelUri    = new Uri("karve://invoice/viewmodel?id=" + gid.ToString());
            MailBoxHandler += IncomingMailBox;
            SubSystem       = DataSubSystem.InvoiceSubsystem;
            RegisterMailBox(ViewModelUri.ToString());
        }