예제 #1
0
        private bool SaveLciaMethod(DbContextWrapper ilcdDb)
        {
            bool isSaved = false;
            string lookupName;
            string refUUID;
            string uuid = GetCommonUUID();
            if (!ilcdDb.IlcdEntityAlreadyExists<LCIAMethod>(uuid)) {
                LCIAMethod lciaMethod = new LCIAMethod();
                SaveIlcdEntity(ilcdDb, lciaMethod, DataTypeEnum.LCIAMethod);
                lciaMethod.Name = GetCommonName();
                lciaMethod.Methodology = GetElementValue(ElementName("methodology"));
                lookupName = GetElementValue(ElementName("impactCategory"));
                if (lookupName != null) {
                    lciaMethod.ImpactCategoryID = (int)ilcdDb.LookupEntityID<ImpactCategory>(lookupName);
                }
                lciaMethod.ImpactIndicator = GetElementValue(ElementName("impactIndicator"));
                lookupName = GetElementValue(ElementName("typeOfDataSet"));
                if (lookupName != null) {
                    lciaMethod.IndicatorTypeID = ilcdDb.LookupEntityID<IndicatorType>(lookupName);
                }
                lciaMethod.ReferenceYear = GetElementValue(ElementName("referenceYear"));
                lciaMethod.Duration = GetElementValue(ElementName("duration"));
                lciaMethod.ImpactLocation = GetElementValue(ElementName("impactLocation"));
                lciaMethod.Normalization = Convert.ToBoolean(GetElementValue(ElementName("normalisation")));
                lciaMethod.Weighting = Convert.ToBoolean(GetElementValue(ElementName("weighting")));
                lciaMethod.UseAdvice = GetElementValue(ElementName("useAdviceForDataSet"));
                refUUID = GetElementAttributeValue(ElementName("referenceQuantity"), "refObjectId");
                Debug.Assert(refUUID != null);
                int refID;
                if (ilcdDb.FindRefIlcdEntityID<FlowProperty>(refUUID, out refID)) {
                    lciaMethod.ReferenceFlowPropertyID = refID;
                }
                if (ilcdDb.AddIlcdEntity(lciaMethod, uuid)) {
                    List<LCIA> lciaList =
                        LoadedDocument.Root.Descendants(ElementName("characterisationFactors")).Elements(ElementName("factor")).Select(f =>
                            CreateLCIA(ilcdDb, f, lciaMethod.ID, uuid)).ToList();
                    ilcdDb.AddEntities<LCIA>(lciaList);

                    isSaved = true;

                }
            }
            return isSaved;
        }
        public void ShouldSuccesfullyGetProcessLCIAResult()
        {
            int processID = 1;
            int lciaMethodID = 1;
            int scenarioID = Scenario.MODEL_BASE_CASE_ID;

            //We only set up the mock repositories that we need
            _lciaMethod = new LCIAMethod()
            {
                LCIAMethodID = 1,
                Name = "ILCD2011; Non-cancer human health effects; midpoint; CTUh; USEtox",
                Methodology = "ILCD2011",
                ImpactCategoryID =10,
                ImpactIndicator = "Comparative Toxic Unit for human (CTUh)expressing the estimated increase in morbidity in the total human population per unit mass of a chemical emitted (cases per kilogramme).",
                ReferenceYear = "time independent",
                Duration="Indefinite",
                ImpactLocation="GLO",
                IndicatorTypeID=1,
                Normalization=false,
                Weighting=false,
                UseAdvice = "Recommended to do a sensitivity analysis by separately calculating the human toxicity results using (i) recommended and interim characterization factors, and (ii) recommended characterization factors only. No factors are listed for particulate matter as there is a specific impact category for that.",
                ReferenceFlowPropertyID=222,
                ILCDEntityID=1756
            };

            //needs to be converted into a LCIAMethodResource type as this is what the method will return
            LCIAMethodResource _lciaMethodResources = new LCIAMethodResource();
            _lciaMethodResources.LCIAMethodID = _lciaMethod.LCIAMethodID;
            _lciaMethodResources.Name = _lciaMethod.Name;
            _lciaMethodResources.Methodology = _lciaMethod.Methodology;
            _lciaMethodResources.ImpactCategoryID = Convert.ToInt32(_lciaMethod.ImpactCategoryID);
            _lciaMethodResources.ImpactIndicator = _lciaMethod.ImpactIndicator;
            _lciaMethodResources.ReferenceYear = _lciaMethod.ReferenceYear;
            _lciaMethodResources.Duration = _lciaMethod.Duration;
            _lciaMethodResources.ImpactLocation = _lciaMethod.ImpactLocation;
            _lciaMethodResources.Normalization = Convert.ToBoolean(_lciaMethod.Normalization);
            _lciaMethodResources.Weighting = Convert.ToBoolean(_lciaMethod.Weighting);
            _lciaMethodResources.UseAdvice = _lciaMethod.UseAdvice;

            _mockLCIAMethodRepository.Setup(m => m.Find(lciaMethodID)).Returns(_lciaMethod);

            //We only set up the mock repositories that we need

            _dataSources = new List<DataSource>
            {
                new DataSource() {
                    DataSourceID = 4,
                    Name = "Mock Data Source",
                    VisibilityID = 1
                }
            };

            _ilcdEntities = new List<ILCDEntity>
            {
                new ILCDEntity() {
                    ILCDEntityID = 1,
                    UUID = "01c96a9f-aeb1-4c5f-bc36-5de9638799f9",
                    Version	= "00.00.000",
                    DataSourceID = 4,
                    DataTypeID = 3
                }
            };

            _processes = new List<Process>
                     {
                            new Process(){   ProcessID = 1,
                Name = "Metal Emissions, DK MDO",
                ReferenceYear = "2013",
                Geography = "US",
                ReferenceTypeID = 1,
                ProcessTypeID = 5,
                ReferenceFlowID = null,
                ILCDEntityID = 1}

                     }.ToList();

            //needs to be converted into a LCIAMethodResource type as this is what the method will return
            List<ProcessResource> _processResources = _processes
                   .Select(x => new ProcessResource() {
                       ProcessID = x.ProcessID,
                       Name = x.Name,
                       ReferenceYear = x.ReferenceYear,
                       Geography = x.Geography,
                       ReferenceTypeID = x.ReferenceTypeID,
                       //ProcessTypeID = Convert.ToInt32(x.ProcessTypeID),
                       ReferenceFlowID=x.ReferenceFlowID
                   }).ToList();

            _mockProcessRepository.Setup(m => m.Queryable()).Returns(_processes.AsQueryable());
            //_mockIlcdEntityRepository.Setup(m => m.Queryable()).Returns(_ilcdEntities.AsQueryable());
            //_mockDataSourceRepository.Setup(m => m.Queryable()).Returns(_dataSources.AsQueryable());
            _processService = new ProcessService(_mockProcessRepository.Object);
            //Act
            _processService.IsPrivate(processID); // do not know how to accomplish this query with a mock repository layer
            //Assert
            _mockProcessRepository.Verify();

            //        _mockProcessRepository.As<IRepositoryAsync<Process>>()
            //.Setup( x => x.Queryable.() )
            //.Returns( Task.FromResult( userData.ToList() ) );

              _processLCIAResult = new LCIAResultResource()
                     {
                                LCIAMethodID=1,
                                ScenarioID = Scenario.MODEL_BASE_CASE_ID,
                                LCIAScore = new List<AggregateLCIAResource>
                                   {
                                      new AggregateLCIAResource()
                                         {
                                              ProcessID=1,
                                              LCIADetail = new List<DetailedLCIAResource>
                                                {
                                                     new DetailedLCIAResource()
                                                     {
                                                          FlowID = 168,
                                                          Direction = "Output",
                                                          Quantity = 3E-06,
                                                          Factor = 0.000171,
                                                          Result = 5.1300000000000009E-10
                                                     },
                                                      new DetailedLCIAResource()
                                                     {
                                                          FlowID = 398,
                                                          Direction = "Output",
                                                          Quantity = 6.93E-07,
                                                          Factor = 0.0168,
                                                          Result = 1.16424E-08
                                                     },
                                                      new DetailedLCIAResource()
                                                     {
                                                          FlowID = 1014,
                                                          Direction = "Output",
                                                          Quantity = 1.35E-06,
                                                          Factor = 4.19E-05,
                                                          Result = 5.6565E-11
                                                     }

                                                }
                                          }
                                    }

                     };

            //Act
            LCIAResultResource result = _resourceServiceFacade.GetProcessLCIAResult(processID, lciaMethodID, scenarioID);
            Assert.AreEqual(_processLCIAResult.LCIAMethodID, result.LCIAMethodID);
        }