public void MapFromDomainEntity_ValidEntity_ReturnDTOEntity()
        {
            //Arrange
            var requisition = new RequisitionLineItemDTO
            {
                Account               = "802-001-5410615-421133-DR-00000-000-000",
                CostCode              = "",
                CreatedBy             = "Kate Machala",
                CurrentApprover       = "Anthony Diaz-Matos",
                Item                  = "Puppet Open Source Assessment",
                OrderTotal            = 6336.85,
                ProjectDescription    = "PRJ8962 - Windows 10 Program - Phase 1",
                ReportingTotal        = 6336.85,
                RequestedBy           = "Diana Thorgerson",
                RequisitionLineNumber = 14937,
                RequisitionHeaderId   = Guid.NewGuid(),
                ShipToAddressName     = "55 East 52nd Street, New York, NY 10055, United States",
                TargetLocationCode    = "Sao Paulo, Brazil - New Location - SP1 (JS)",
                Id = Guid.NewGuid()
            };

            //Act
            var response = RequisitionLineItem.MapFromDomainEntity(requisition);

            //Assert
            Assert.IsNotNull(response);
            Assert.AreEqual(requisition.Item, response.Item);
        }
Пример #2
0
        // Import Requisition
        public CoupaImporterJobDefinitionDTO ProcessRequisitionImportJob(Guid jobDefinitionId)
        {
            var jobDefinition = _coupaImporterRepository.Get(jobDefinitionId);

            if (jobDefinition == null)
            {
                return(null);
            }

            _unitOfWork.AutoDetectChanges(false);
            var requisitionHeaders   = new List <RequisitionHeader>();
            var listOfRequisitionDTO = new List <RequisitionDTO>();

            // Here we use 1000 records batch so that we can reduce the number of loops.
            var noOfRotation = jobDefinition.CoupaImporterJobDefinitionDetails.Count() / 1000;

            noOfRotation += jobDefinition.CoupaImporterJobDefinitionDetails.Count() % 1000 > 0 ? 1 : 0;

            for (var i = 0; i < noOfRotation; i++)
            {
                var strCoupaImporterJobDefinitionDetails = "[ ";
                strCoupaImporterJobDefinitionDetails += string.Join(", ", jobDefinition.CoupaImporterJobDefinitionDetails
                                                                    .Skip(i * 1000).Take(1000).Select(x => x.RawContent));
                strCoupaImporterJobDefinitionDetails += " ]";

                // Convert the RawContent to RequisitionHeader
                requisitionHeaders.AddRange(JsonConvert.DeserializeObject <List <RequisitionHeader> >(strCoupaImporterJobDefinitionDetails));
                // Convert the RawContent to RequisitionDTO
                listOfRequisitionDTO.AddRange(JsonConvert.DeserializeObject <List <RequisitionDTO> >(strCoupaImporterJobDefinitionDetails));
            }

            // In every InvoiceHeader Entity ProjectId is added
            requisitionHeaders.ForEach(i => { i.ProjectId = jobDefinition.ProjectId; i.Id = Guid.NewGuid(); });

            // Grouping InvoiceHeaders in terms of Unique combination of Supplier & InvoiceNumber
            requisitionHeaders = requisitionHeaders.GroupBy(i => new { i.RequisitionNumber, i.Supplier }).Select(x => x.First()).ToList();

            foreach (var objRequisition in requisitionHeaders)
            {
                // Allocate all line items for a invoice header + InvoiceHeaderId added in every associated Line Items.
                objRequisition.RequisitionLineItems = listOfRequisitionDTO.Where(x => x.Supplier == objRequisition.Supplier && x.RequisitionNumber == objRequisition.RequisitionNumber.ToString())
                                                      .Select(x => RequisitionLineItem.MapFromDomainEntity(RequisitionDTO.MapToRequisitionLineItemDTO(x))).ToList();
                objRequisition.RequisitionLineItems.ToList().ForEach(x => { x.RequisitionHeaderId = objRequisition.Id; x.Id = Guid.NewGuid(); });

                _projectRequisitionRepository.Add(objRequisition);
            }

            // At last update all job definition details records
            jobDefinition.CoupaImporterJobDefinitionDetails.ToList().ForEach(c => { c.IsProcessed = true; c.IsSuccessful = true; });
            _coupaImporterRepository.UpdateAllJobDefinitionDetail(jobDefinitionId, jobDefinition.CoupaImporterJobDefinitionDetails);

            jobDefinition.Status = (int)CoupaImporterStatus.Processed;
            _coupaImporterRepository.Update(jobDefinitionId, jobDefinition);

            _unitOfWork.SaveChanges();
            _unitOfWork.AutoDetectChanges(true);

            return(CoupaImporterJobDefinitionDTO.MapFromDatabaseEntity(jobDefinition));
        }
        public void MapFromDomainEntity_NullContent_ReturnNull()
        {
            //Act
            var response = RequisitionLineItem.MapFromDomainEntity(null);

            //Assert
            Assert.IsNull(response);
        }
Пример #4
0
        public RequisitionLineItemDTO AddLineItem(RequisitionLineItemDTO reqLineItemDTO)
        {
            var response = _projectRequisitionRepository.AddLineItem(RequisitionLineItem.MapFromDomainEntity(reqLineItemDTO));

            return(RequisitionLineItemDTO.MapFromDatabaseEntity(response));
        }