private IEnumerable <IContainer> modelNeighborhoodsFor(string modelName, IContainer individualNeighborhoods) { var neighborhoodNames = new List <string>(); IEnumerable <FlatModelContainer> allNeighborhoodContainersForModel = from flatModelContainer in _modelContainerRepository.All() where flatModelContainer.Model == modelName where flatModelContainer.Type == CoreConstants.ContainerType.NEIGHBORHOOD select flatModelContainer; foreach (FlatModelContainer flatNeighborhoodContainer in allNeighborhoodContainersForModel) { if (individualNeighborhoods.ContainsName(flatNeighborhoodContainer.Name)) { //neighborhood available in individuum (species) neighborhoodNames.Add(flatNeighborhoodContainer.Name); continue; } //neighborhood available in model but not in individual (species) //Reaction depends on usage in individual flag if (flatNeighborhoodContainer.UsageInIndividual == CoreConstants.ORM.USAGE_IN_INDIVIDUAL_REQUIRED) { throw new ArgumentException(PKSimConstants.Error.ModelContainerNotAvailable(flatNeighborhoodContainer.Name)); } if (flatNeighborhoodContainer.UsageInIndividual == CoreConstants.ORM.USAGE_IN_INDIVIDUAL_OPTIONAL) { continue; } if (flatNeighborhoodContainer.UsageInIndividual == CoreConstants.ORM.USAGE_IN_INDIVIDUAL_EXTENDED) { throw new ArgumentException(PKSimConstants.Error.ExtendedNeighborhoodNotAllowed(flatNeighborhoodContainer.Name)); } throw new ArgumentException(PKSimConstants.Error.UnknownUsageInIndividualFlag(flatNeighborhoodContainer.UsageInIndividual)); } return(individualNeighborhoods.GetChildren <IContainer>(c => neighborhoodNames.Contains(c.Name))); }
protected override void Context() { base.Context(); _neighborhoodRepository = A.Fake <IFlatNeighborhoodRepository>(); _modelContainerRepository = A.Fake <IFlatModelContainerRepository>(); _neighborhoodBuilderFactory = A.Fake <INeighborhoodBuilderFactory>(); _modelProperties = A.Fake <ModelProperties>(); _modelProperties.ModelConfiguration = A.Fake <ModelConfiguration>(); _modelProperties.ModelConfiguration.ModelName = "3Comp"; _allFlatNeighborhoods = new List <FlatModelContainer>(); A.CallTo(() => _modelContainerRepository.All()).Returns(_allFlatNeighborhoods); _flatNeighborhoodFor3Comp = new FlatModelContainer { Model = "3Comp", Type = CoreConstants.ContainerType.NEIGHBORHOOD, Id = 1 }; _flatNeighborhoodFor4Comp = new FlatModelContainer { Model = "4Comp", Type = CoreConstants.ContainerType.NEIGHBORHOOD, Id = 2 }; _allFlatNeighborhoods.Add(_flatNeighborhoodFor3Comp); _allFlatNeighborhoods.Add(_flatNeighborhoodFor4Comp); sut = new ModelNeighborhoodQuery(_modelContainerRepository, _neighborhoodBuilderFactory); }
protected override void Context() { _entityPathResolver = new EntityPathResolver(new ObjectPathFactoryForSpecs()); _flatContainerIdToContainerMapper = A.Fake <IFlatContainerIdToContainerMapper>(); _modelContainerRepo = A.Fake <IFlatModelContainerRepository>(); _compartment = A.Fake <IContainer>(); _populationName = "HUMAN_POP"; A.CallTo(() => _modelContainerRepo.All()).Returns( new List <FlatModelContainer> { NewFMC(1, "C1", "ORGAN", "M1"), NewFMC(2, "C2", "COMPARTMENT", "M1"), NewFMC(3, Constants.ROOT, "SIMULATION", "M1") }); _populationContainerRepo = A.Fake <IFlatPopulationContainerRepository>(); A.CallTo(() => _populationContainerRepo.AllSubContainerFor(_populationName, 3)).Returns( new List <FlatPopulationContainer> { CreateFlatPopulationContainer(1, "C1", "ORGAN", _populationName), }); A.CallTo(() => _populationContainerRepo.AllSubContainerFor(_populationName, 1)).Returns( new List <FlatPopulationContainer> { CreateFlatPopulationContainer(2, "C2", "COMPARTMENT", _populationName) }); _flatContainerRepo = A.Fake <IFlatContainerRepository>(); var simulationFlatContainer = NewFC(3, Constants.ROOT, "SIMULATION", null, "", ""); var organFlatContainer = NewFC(1, "C1", "ORGAN", 3, "SIMULATION", Constants.ROOT); var compartmentFlatContainer = NewFC(2, "C2", "COMPARTMENT", 1, "C1", "ORGAN"); A.CallTo(() => _flatContainerRepo.All()).Returns( new List <FlatContainer> { organFlatContainer, compartmentFlatContainer, simulationFlatContainer }); A.CallTo(() => _flatContainerRepo.ParentContainerFrom(organFlatContainer.Id)).Returns(simulationFlatContainer); A.CallTo(() => _flatContainerRepo.ParentContainerFrom(compartmentFlatContainer.Id)).Returns(organFlatContainer); A.CallTo(() => _flatContainerRepo.ParentContainerFrom(simulationFlatContainer.Id)).Returns(null); A.CallTo(() => _flatContainerRepo.ContainerFrom(organFlatContainer.Id)).Returns(organFlatContainer); A.CallTo(() => _flatContainerRepo.ContainerFrom(compartmentFlatContainer.Id)).Returns(compartmentFlatContainer); A.CallTo(() => _flatContainerRepo.ContainerFrom(simulationFlatContainer.Id)).Returns(simulationFlatContainer); _flatModelCompartment = new FlatModelContainer { Id = compartmentFlatContainer.Id }; A.CallTo(() => _flatContainerRepo.ContainerFrom("ROOT")).Returns(organFlatContainer); A.CallTo(() => _flatContainerRepo.ContainerFrom("C1")).Returns(organFlatContainer); A.CallTo(() => _modelContainerRepo.AllSubContainerFor("M1", 1)).Returns(new[] { _flatModelCompartment }); A.CallTo(() => _flatContainerIdToContainerMapper.MapFrom(_flatModelCompartment)).Returns(_compartment); sut = new ModelContainerQuery(_modelContainerRepo, _populationContainerRepo, _flatContainerRepo, _flatContainerIdToContainerMapper, _entityPathResolver); }