예제 #1
0
        protected override void Context()
        {
            base.Context();
            _context = A.Fake <IMoBiContext>();
            A.CallTo(() => _context.HistoryManager).Returns(A.Fake <IMoBiHistoryManager>());
            _startValuesTask = A.Fake <IMoleculeStartValuesTask>();
            _view            = A.Fake <IImportQuantityView>();
            _dialogCreator   = A.Fake <IDialogCreator>();
            _dataTableToImportQuantityDTOMapperForMolecules = A.Fake <IDataTableToImportQuantityDTOMapperForMolecules>();
            _buildingBlock = new MoleculeStartValuesBuildingBlock();
            _excelTask     = A.Fake <IImportFromExcelTask>();
            sut            = new ImportMoleculeStartValuePresenter(_view, _dialogCreator, _context, _excelTask, _startValuesTask, _dataTableToImportQuantityDTOMapperForMolecules);
            sut.Initialize();

            _quantityImporterDTO = new QuantityImporterDTO();

            new List <ImportedQuantityDTO>
            {
                new ImportedQuantityDTO {
                    Name = "drug", ContainerPath = new ObjectPath("First")
                },
                new ImportedQuantityDTO {
                    Name = "drug", ContainerPath = new ObjectPath("Second")
                },
            }.Each(_quantityImporterDTO.QuantitDTOs.Add);

            A.CallTo(() => _dataTableToImportQuantityDTOMapperForMolecules.MapFrom(A <DataTable> ._, _buildingBlock)).Returns(_quantityImporterDTO);

            A.CallTo(() => _view.Display()).Invokes(() =>
            {
                sut.StartImport();
                sut.TransferImportedQuantities();
            });
        }
예제 #2
0
        protected virtual void ValidateInContext(ImportedQuantityDTO dto, QuantityImporterDTO quantityImporterDTO, TImportTarget buildingBlock, DataRow row, int rowIndex)
        {
            if (IsUpdate(dto, buildingBlock) && !ValidateDTOForUpdate(dto))
            {
                throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Validation.ValueNotValidForUpdate(dto.Path.ToString()));
            }

            if (IsNewInsert(dto, buildingBlock) && !ValidateDTOForInsert(dto))
            {
                throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Validation.ValueNotValidForInsert(dto.Path.ToString()));
            }

            if (string.IsNullOrEmpty(dto.Name))
            {
                throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Exceptions.ImportedStartValueMustHaveName);
            }

            if (string.IsNullOrEmpty(dto.ContainerPath.PathAsString))
            {
                throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Exceptions.ImportedStartValueMustHaveContainerPath);
            }

            if (quantityImporterDTO.QuantitDTOs.Any(x => Equals(x.Path, dto.Path)))
            {
                throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Exceptions.DuplicatedImportedStartValue(dto.Path.PathAsString));
            }
        }
        protected override void Context()
        {
            base.Context();
            _quantityImporterDTO = new QuantityImporterDTO();
            new List <ImportedQuantityDTO>
            {
                new ImportedQuantityDTO {
                    ContainerPath = new ObjectPath(new[] { "Path1" })
                },
                new ImportedQuantityDTO {
                    ContainerPath = new ObjectPath(new[] { "Path2" })
                },
                new ImportedQuantityDTO {
                    ContainerPath = new ObjectPath(new[] { "Path3" }), QuantityInBaseUnit = 0.0
                }
            }.Each(_quantityImporterDTO.QuantitDTOs.Add);

            A.CallTo(() => _dataTableToImportParameterQuantityDTOMapperForMolecules.MapFrom(A <DataTable> ._, A <IParameterStartValuesBuildingBlock> .Ignored)).Returns(_quantityImporterDTO);
            A.CallTo(() => _buildingBlock[_quantityImporterDTO.QuantitDTOs[0].ContainerPath]).Returns(null);
            A.CallTo(() => _buildingBlock[_quantityImporterDTO.QuantitDTOs[1].ContainerPath]).Returns(null);
            A.CallTo(() => _buildingBlock[_quantityImporterDTO.QuantitDTOs[2].ContainerPath]).Returns(new ParameterStartValue {
                Path = new ObjectPath(new[] { "Path3" })
            });
            A.CallTo(() => _view.Display()).Invokes(() =>
            {
                sut.StartImport();
                sut.TransferImportedQuantities();
            });

            sut.ImportStartValuesForBuildingBlock(_buildingBlock);
        }
        protected override void ValidateInContext(ImportedQuantityDTO dto, QuantityImporterDTO quantityImporterDTO, IStartValuesBuildingBlock <IParameterStartValue> buildingBlock, DataRow row, int rowIndex)
        {
            base.ValidateInContext(dto, quantityImporterDTO, buildingBlock, row, rowIndex);
            var builder = buildingBlock[dto.Path];

            if (builder != null)
            {
                ValidateDtoAgainstBuilderForUpdate(builder, dto, row, rowIndex);
            }
        }
예제 #5
0
        public void StartImport()
        {
            var tables = importedDataTableFromFile();

            _quantityImporterDTO = ConvertTableToImportedQuantities(tables);

            _view.BindTo(_quantityImporterDTO);
            UpdateLog(_quantityImporterDTO.Log);

            _quantityDTOs = GetQuantitiesFromDTO(_quantityImporterDTO.DowncastTo <QuantityImporterDTO>());
        }
 protected override void ValidateInContext(ImportedQuantityDTO dto, QuantityImporterDTO quantityImporterDTO, IStartValuesBuildingBlock <IMoleculeStartValue> buildingBlock, DataRow row, int rowIndex)
 {
     base.ValidateInContext(dto, quantityImporterDTO, buildingBlock, row, rowIndex);
     if (isDimensionRequired(dto) && !isCorrectDimensionForDimensionMode(_reactionDimensionRetriever.SelectedDimensionMode, dto))
     {
         throw new ImportQuantityDTOsFromDataTablesMapperException(
                   row, rowIndex,
                   AppConstants.Exceptions.ImportedDimensionNotRecognized(getDimensionConstantForProject(_reactionDimensionRetriever.SelectedDimensionMode),
                                                                          _dimensionFactory.Dimension(getDimensionConstantForProject(_reactionDimensionRetriever.SelectedDimensionMode)).GetUnitNames()));
     }
 }
        protected override void AddDTOToImportList(QuantityImporterDTO quantityImporterDTO, IStartValuesBuildingBlock <IMoleculeStartValue> importTarget, ImportedQuantityDTO dto)
        {
            quantityImporterDTO.QuantitDTOs.Add(dto);
            if (dto.HasWarning())
            {
                quantityImporterDTO.AddToLog(dto.GetWarning());
            }

            quantityImporterDTO.AddToLog(IsNewInsert(dto, importTarget)
            ? AppConstants.Captions.AddingMoleculeStartValue(dto.Path, dto.ConvertToDisplayUnit(dto.QuantityInBaseUnit), dto.DisplayUnit, dto.IsPresent, dto.Name, dto.NegativeValuesAllowed)
            : AppConstants.Captions.UpdatingMoleculeStartValue(dto.Path, dto.ConvertToDisplayUnit(dto.QuantityInBaseUnit), dto.DisplayUnit, dto.IsPresent, dto.Name, dto.NegativeValuesAllowed));
        }
예제 #8
0
        protected override void AddDTOToImportList(QuantityImporterDTO quantityImporterDTO, TImportTarget importTarget, ImportedQuantityDTO dto)
        {
            if (!dto.SkipImport)
            {
                quantityImporterDTO.QuantitDTOs.Add(dto);
                quantityImporterDTO.AddToLog(LogMessageFor(dto, importTarget));
            }

            if (dto.HasWarning())
            {
                quantityImporterDTO.AddToLog(dto.GetWarning());
            }
        }
예제 #9
0
        private QuantityImporterDTO convertTableToQuantityDTOs(DataTable table, TImportTarget buildingBlock)
        {
            var importerDTO = new QuantityImporterDTO();

            importerDTO.AddToLog(AppConstants.Captions.ConvertingExcelSheetToQuantities(table.TableName));
            var rowIndex = 0;

            foreach (DataRow row in table.Rows)
            {
                if (isRowEmpty(table, rowIndex))
                {
                    continue;
                }
                try
                {
                    var dto = MapQuantityFromRow(table, table.Rows[rowIndex], rowIndex);

                    ValidateInContext(dto, importerDTO, buildingBlock, row, rowIndex);

                    AddDTOToImportList(importerDTO, buildingBlock, dto);
                }
                catch (ImportQuantityDTOsFromDataTablesMapperException e)
                {
                    importerDTO.AddToLog(e.Message);
                    importerDTO.QuantitDTOs.Clear();
                    break;
                }
                catch (Exception e)
                {
                    importerDTO.AddToLog($"{AppConstants.Exceptions.FrameworkExceptionOccurred}, {e.Message}, {row.ToNiceString()}");
                    importerDTO.QuantitDTOs.Clear();
                    break;
                }

                rowIndex++;
            }

            return(importerDTO);
        }
예제 #10
0
        protected override void ValidateInContext(ImportedQuantityDTO dto, QuantityImporterDTO quantityImporterDTO, IMoBiSimulation simulation, DataRow row, int rowIndex)
        {
            // Skipping base call because the default validation is to stop import when first error occurs
            if (IsUpdate(dto, simulation))
            {
                if (!ValidateDTOForUpdate(dto))
                {
                    throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Validation.ValueNotValidForUpdate(dto.Path.ToString()));
                }

                ValidateDtoAgainstBuilderForUpdate(dto.Path.TryResolve <IParameter>(simulation.Model.Root), dto, row, rowIndex);
            }

            if (!IsNewInsert(dto, simulation))
            {
                return;
            }

            // +2 because there is a mandatory header row (+1) and this index is 0-based, while excel rows start at 1 (+1)
            dto.SetWarning(row, rowIndex + 2, AppConstants.Warnings.CannotAddNewParameterFromImportToSimulation(simulation.Name, dto.Path.ToString()));
            dto.SkipImport = true;
        }
예제 #11
0
 protected NotifyList <ImportedQuantityDTO> GetQuantitiesFromDTO(QuantityImporterDTO quantityImporterDTO)
 {
     return(quantityImporterDTO.QuantitDTOs);
 }
예제 #12
0
 protected override void Because()
 {
     _result = sut.MapFrom(new ConcentrationDataTableProvider().ImportTables(), _startValuesBuildingBlock);
 }
예제 #13
0
 protected override void Because()
 {
     _result = sut.MapFrom(_importTables, _startValuesBuildingBlock);
 }
예제 #14
0
 protected abstract void AddDTOToImportList(QuantityImporterDTO quantityImporterDTO, TImportTarget importTarget, ImportedQuantityDTO dto);
 public void BindTo(QuantityImporterDTO quantityImporterDTO)
 {
     _importStartValuesDTOScreenBinder.BindToSource(quantityImporterDTO);
 }
예제 #16
0
 protected override void Because()
 {
     _result = sut.MapFrom(_dataTable, _simulation);
 }