Exemplo n.º 1
0
        public void Should_Discard_AnInvalidInvoice()
        {
            var factory     = AbstractDomainWrapperFactory.GetFactory(_dataServices);
            var invoice     = factory.CreateInvoice("28982");
            var dataFactory = _dataServices.GetInvoiceDataServices();

            invoice.Value = null;
            Assert.ThrowsAsync <DataLayerException>(async() => await dataFactory.SaveAsync(invoice));
        }
Exemplo n.º 2
0
        public async Task Should_Fail_SavingInvalidInvoiceNumber()
        {
            const string code        = "-19292";
            var          factory     = AbstractDomainWrapperFactory.GetFactory(_dataServices);
            var          invoice     = factory.CreateInvoice(code);
            var          dataFactory = _dataServices.GetInvoiceDataServices();

            // act
            Assert.IsNotInstanceOf(typeof(NullInvoice), invoice);
            var invoiceSaved = false;

            invoiceSaved = await dataFactory.SaveAsync(invoice);

            Assert.AreEqual(invoiceSaved, false);
        }
Exemplo n.º 3
0
        protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad)
        {
            bool      result     = false;
            bool      isInsert   = payLoad.PayloadType == DataPayLoad.Type.Insert;
            ClientDto clientData = payLoad.DataObject as ClientDto;

            // pre: DataServices and vehicle shall be present.
            if ((DataServices == null))
            {
                DataPayLoad nullDataPayLoad = new NullDataPayload();
                return(nullDataPayLoad);
            }
            if (clientData == null)
            {
                string message = (isInsert) ? "Error during the insert" : "Error during the update";
                SendError(message);
                // i return a null payload.
                return(new NullDataPayload());
            }
            // FIXME: check for the law of demeter.
            var clientDo = await DataServices.GetClientDataServices().GetDoAsync(clientData.NUMERO_CLI);

            if (clientDo == null)
            {
                payLoad.PayloadType = DataPayLoad.Type.Insert;
            }
            AbstractDomainWrapperFactory factory = AbstractDomainWrapperFactory.GetFactory(DataServices);
            IClientData clientWrapper            = await factory.CreateClientAsync(clientData).ConfigureAwait(false);

            clientWrapper.Value = clientData;
            result = await DataServices.GetClientDataServices().SaveAsync(clientWrapper).ConfigureAwait(false);             if (result)
            {
                payLoad.Sender               = ToolBarModule.NAME;
                payLoad.PayloadType          = DataPayLoad.Type.UpdateView;
                CurrentPayload               = payLoad;
                CurrentPayload.HasDataObject = true;
                CurrentPayload.DataObject    = clientDo;
                CurrentPayload.Subsystem     = payLoad.Subsystem;
            }
            else
            {
                string message = isInsert ? "Error during the insert" : "Error during the update";
                SendError(message);
            }
            return(payLoad);
        }
Exemplo n.º 4
0
 /// <summary>
 ///  Unity
 /// </summary>
 /// <param name="unityContainer">Container </param>
 public TestMainWindowViewModel(IUnityContainer unityContainer, IDataServices dataServices, ISqlExecutor executor)
 {
     _clientDataServices = dataServices.GetClientDataServices();
     _domainFactory      = AbstractDomainWrapperFactory.GetFactory(dataServices);
     _unityContainer     = unityContainer;
     evSummaryCompleted += OnEventCompleted;
     SourceView          = new IncrementalList <ClientSummaryExtended>(LoadMoreItems)
     {
         MaxItemCount = 10000
     };
     //Controller = _unityContainer.Resolve<RequestController>();
     ItemChangedCommand = new DelegateCommand <Dictionary <string, object> >(OnItemChangedCommand);
     AssistCommand      = new DelegateCommand <object>(OnAssistCommand);
     GridCommand        = new DelegateCommand <object>(OnGridFilterCommand);
     _dataFilterService = new DataFilterSummaryService <ClientSummaryExtended>(null, executor);
     _dataFilterService.FilterEventResult += _dataFilterService_FilterEventResult;
     notifyTaskCompletion = NotifyTaskCompletion.Create(_clientDataServices.GetPagedSummaryDoAsync(1, 500), evSummaryCompleted);
 }
Exemplo n.º 5
0
        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 InvoiceSummaryViewObject()
            {
                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 InvoiceSummaryViewObject()
            {
                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 <InvoiceSummaryViewObject> {
                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());
        }