public void Should_Refuse_An_Incoming_Null_Payload() { DataPayLoad dataPayLoad = new NullDataPayload(); _companyInfoViewModel.IncomingPayload(dataPayLoad); var outObject = _companyInfoViewModel.DataObject; Assert.Null(outObject); }
public void Should_Refuse_An_Incoming_Payload_WithNullDO() { DataPayLoad dataPayLoad = new NullDataPayload(); dataPayLoad.DataObject = null; dataPayLoad.HasDataObject = true; _companyInfoViewModel.IncomingPayload(dataPayLoad); var outObject = _companyInfoViewModel.DataObject; Assert.Null(outObject.Codigo); }
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); }
public void ShouldInterpreter_Discard_AnInvalidPayload() { var initValue = 0; var cleanUpValue = 0; DataPayLoad payLoad = new NullDataPayload(); var parser = new PayloadInterpeter <OfficeDtos> { Init = (value, packet, insertion) => { initValue++; }, CleanUp = (key, system, name) => { cleanUpValue++; } }; // act parser.ActionOnPayload(payLoad, "3893893", "838393", DataSubSystem.OfficeSubsystem, MasterModuleConstants.OfficeSubSytemName); // assert. Assert.AreEqual(initValue, 0); Assert.AreEqual(cleanUpValue, 0); }
/// <summary> /// /// </summary> /// <param name="payLoad"></param> /// <returns></returns> protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad) { bool result = false; bool isInsert = payLoad.PayloadType == DataPayLoad.Type.Insert; IVehicleData vehicleData = (IVehicleData)payLoad.DataObject; // pre: DataServices and vehicle shall be present. if (DataServices == null) { DataPayLoad nullDataPayLoad = new NullDataPayload(); return(nullDataPayLoad); } _vehicleDataServices = DataServices.GetVehicleDataServices(); if (vehicleData == null) { string message = (payLoad.PayloadType == DataPayLoad.Type.Insert) ? "Error during the insert" : "Error during the update"; ShowErrorMessage(message); // OnErrorExecuting?.Invoke(message); } // FIXME: unify the update and the insert. switch (payLoad.PayloadType) { case DataPayLoad.Type.Update: case DataPayLoad.Type.Insert: { result = await _vehicleDataServices.SaveAsync(vehicleData).ConfigureAwait(false); break; } } if (result) { payLoad.Sender = ToolBarModule.NAME; payLoad.PayloadType = DataPayLoad.Type.UpdateView; CurrentPayload = payLoad; } else { string message = isInsert ? "Error during the insert" : "Error during the update"; ShowErrorMessage(message); // OnErrorExecuting?.Invoke(message); } return(payLoad); }
protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad) { bool result = false; bool isInsert = false; ISupplierData supplierData = (ISupplierData)payLoad.DataObject; if (DataServices == null) { DataPayLoad nullDataPayLoad = new NullDataPayload(); return(nullDataPayLoad); } switch (payLoad.PayloadType) { case DataPayLoad.Type.Update: { result = await DataServices.GetSupplierDataServices().SaveChanges(supplierData) .ConfigureAwait(false); break; } case DataPayLoad.Type.Insert: { isInsert = true; result = await DataServices.GetSupplierDataServices().Save(supplierData).ConfigureAwait(true); break; } } if (result) { payLoad.Sender = ToolBarModule.NAME; payLoad.PayloadType = DataPayLoad.Type.UpdateView; CurrentPayload = payLoad; } else { string message = isInsert ? "Error during the insert" : "Error during the update"; OnErrorExecuting?.Invoke(message); } return(payLoad); }
protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad) { bool result = false; bool isInsert = false; ISupplierData supplierData = payLoad.DataObject as ISupplierData; if (supplierData == null) { string message = (payLoad.PayloadType == DataPayLoad.Type.Insert) ? "Error during the insert" : "Error during the update"; OnErrorExecuting?.Invoke(message); return(new DataPayLoad()); } if (DataServices == null) { DataPayLoad nullDataPayLoad = new NullDataPayload(); return(nullDataPayLoad); } var checkedSupplierData = await DataServices.GetSupplierDataServices().GetAsyncSupplierDo(supplierData.Value.NUM_PROVEE); if (checkedSupplierData.Value == null) { payLoad.PayloadType = DataPayLoad.Type.Insert; } switch (payLoad.PayloadType) { case DataPayLoad.Type.Update: { result = await DataServices.GetSupplierDataServices().SaveChanges(supplierData) .ConfigureAwait(false); break; } case DataPayLoad.Type.Insert: { isInsert = true; result = await DataServices.GetSupplierDataServices().Save(supplierData).ConfigureAwait(true); break; } case DataPayLoad.Type.UpdateInsertGrid: { result = true; if (payLoad.RelatedObject is IEnumerable <BranchesViewObject> ) { await UpdateGridAsync <BranchesViewObject, ProDelega>(payLoad); } else { await UpdateGridAsync <ContactsViewObject, ProContactos>(payLoad); } break; } case DataPayLoad.Type.DeleteGrid: { if (payLoad.RelatedObject is IEnumerable <BranchesViewObject> branches) { foreach (var branch in branches) { if (branch.IsDeleted) { // a delete bulk. result = await DataServices.GetHelperDataServices().ExecuteAsyncDelete <BranchesViewObject, ProDelega>(branch); } } } ContactsViewObject contactsViewObject = payLoad.RelatedObject as ContactsViewObject; if (contactsViewObject != null) { result = await DataServices.GetHelperDataServices().ExecuteAsyncDelete <ContactsViewObject, ProContactos>(contactsViewObject); } break; } } if (result) { payLoad.Sender = ToolBarModule.NAME; payLoad.PayloadType = DataPayLoad.Type.UpdateView; CurrentPayload = new DataPayLoad(); CurrentPayload.PayloadType = DataPayLoad.Type.UpdateView; CurrentPayload.DataObject = supplierData; CurrentPayload.Sender = ToolBarModule.NAME; CurrentPayload.HasDataObject = true; CurrentPayload.Subsystem = payLoad.Subsystem; } else { string message = isInsert ? "Error during the insert" : "Error during the update"; OnErrorExecuting?.Invoke(message); } return(payLoad); }