Beispiel #1
0
        public SpeciesObservationList GetSpeciesObservationBySearchCriteriaPage(IUserContext userContext,
                                                                                ISpeciesObservationSearchCriteria searchCriteria,
                                                                                ICoordinateSystem coordinateSystem,
                                                                                ISpeciesObservationPageSpecification pageSpecification)
        {
            SpeciesObservationList speciesObservationList = new SpeciesObservationList();
            IEnumerable <int>      taxonIds;

            if (searchCriteria.TaxonIds != null && searchCriteria.TaxonIds.Count > 0)
            {
                taxonIds = searchCriteria.TaxonIds;
            }
            else
            {
                taxonIds = AllTaxonIds;
            }

            foreach (int taxonId in taxonIds)
            {
                SpeciesObservation speciesObservation = CreateSpeciesObservation(taxonId);
                speciesObservationList.Add(speciesObservation);
            }

            return(speciesObservationList);
        }
Beispiel #2
0
        public void GetSpeciesObservationViewModel_ObservationWithProjectParameters_ProjectIsPopulatedInModel()
        {
            // Constants
            const string projectName                        = "My project";
            const int    observationId                      = 150;
            const string projectParameterName1              = "Degrees";
            const string projectParameterValue1             = "25";
            const string projectParamterPropertyIdentifier1 = "MyPropIdentifier1";

            // Arrange
            LoginApplicationUser();
            SpeciesObservationDataManager speciesObservationDataManager = new SpeciesObservationDataManager(SessionHandler.UserContext, SessionHandler.MySettings);

            // Arrange - Mock
            CoreData.SpeciesObservationManager.DataSource =
                new StubISpeciesObservationDataSource()
            {
                GetSpeciesObservationsIUserContextListOfInt64ICoordinateSystemISpeciesObservationSpecification =
                    (userContext, speciesObservationIds, coordinateSystem, speciesObservationSpecification) =>
                {
                    SpeciesObservationList speciesObservationList = new SpeciesObservationList();
                    ISpeciesObservation    speciesObservation     = new ArtDatabanken.Data.SpeciesObservation();
                    speciesObservation.Id = observationId;

                    speciesObservation.Project = new SpeciesObservationProject
                    {
                        ProjectName       = projectName,
                        ProjectParameters = new SpeciesObservationProjectParameterList
                        {
                            new SpeciesObservationProjectParameter
                            {
                                PropertyIdentifier = projectParamterPropertyIdentifier1,
                                ProjectName        = projectName,
                                Property           = projectParameterName1,
                                Value = projectParameterValue1
                            }
                        }
                    };

                    speciesObservationList.Add(speciesObservation);
                    return(speciesObservationList);
                }
            };

            // Act
            var speciesObservationViewModel = speciesObservationDataManager.GetSpeciesObservationViewModel(observationId);

            // Assert
            Assert.AreEqual(1, speciesObservationViewModel.Projects.Count);
            Assert.AreEqual(projectName, speciesObservationViewModel.Projects[0].Name);
            Assert.AreEqual(projectParameterName1, speciesObservationViewModel.Projects[0].ProjectParameters[projectParamterPropertyIdentifier1].Name);
            Assert.AreEqual(projectParameterValue1, speciesObservationViewModel.Projects[0].ProjectParameters[projectParamterPropertyIdentifier1].Value);
        }
        private SpeciesObservationsData CreateSpeciesObservationData(IUserContext userContext, AnalysisPortal.MySettings.MySettings mySettings)
        {
            SpeciesObservation speciesObservation = new SpeciesObservation();

            speciesObservation.Taxon         = new SpeciesObservationTaxon();
            speciesObservation.Taxon.TaxonID = "1";
            SpeciesObservationList speciesObservationList = new SpeciesObservationList();

            speciesObservationList.Add(speciesObservation);
            var fieldDescriptionViewManager = new SpeciesObservationFieldDescriptionViewManager(userContext, mySettings);
            var fieldDescriptionsViewModel  = fieldDescriptionViewManager.CreateSpeciesObservationFieldDescriptionsViewModel();
            SpeciesObservationsData speciesObservationsData = new SpeciesObservationsData(speciesObservationList, fieldDescriptionsViewModel);

            return(speciesObservationsData);
        }
Beispiel #4
0
        private static SpeciesObservationsData CreateSpeciesObservationDataSample()
        {
            SpeciesObservation      speciesObservation;
            SpeciesObservationList  speciesObservationList;
            SpeciesObservationsData speciesObservationsData;

            speciesObservation               = new SpeciesObservation();
            speciesObservation.Taxon         = new SpeciesObservationTaxon();
            speciesObservation.Taxon.TaxonID = "27";
            speciesObservationList           = new SpeciesObservationList();
            speciesObservationList.Add(speciesObservation);
            var fieldDescriptionViewManager = new SpeciesObservationFieldDescriptionViewManager(SessionHandler.UserContext, SessionHandler.MySettings);
            var fieldDescriptionsViewModel  = fieldDescriptionViewManager.CreateSpeciesObservationFieldDescriptionsViewModel();

            speciesObservationsData = new SpeciesObservationsData(speciesObservationList, fieldDescriptionsViewModel);
            return(speciesObservationsData);
        }
Beispiel #5
0
        public void GetObservationsListDictionary_WhenOneProjectParameter_ThenProjectAndProjectParameterArePairedTogether()
        {
            // Constants
            const string projectName            = "My project";
            const int    observationId          = 150;
            const string projectParameterName1  = "Degrees";
            const string projectParameterValue1 = "25";

            //Arrange
            LoginApplicationUser();
            SpeciesObservationDataManager speciesObservationDataManager = new SpeciesObservationDataManager(
                SessionHandler.UserContext,
                SessionHandler.MySettings);
            List <SpeciesObservationViewModel> obsResultList = new List <SpeciesObservationViewModel>();
            IEnumerable <ViewTableField>       tableFields   = null;

            // Arrange - Mock
            CoreData.SpeciesObservationManager.DataSource =
                new StubISpeciesObservationDataSource()
            {
                GetSpeciesObservationsIUserContextListOfInt64ICoordinateSystemISpeciesObservationSpecification =
                    (userContext, speciesObservationIds, coordinateSystem, speciesObservationSpecification) =>
                {
                    SpeciesObservationList speciesObservationList = new SpeciesObservationList();
                    ISpeciesObservation    speciesObservation     = new ArtDatabanken.Data.SpeciesObservation();
                    speciesObservation.Id      = observationId;
                    speciesObservation.Project = new SpeciesObservationProject
                    {
                        ProjectName       = projectName,
                        ProjectParameters = new SpeciesObservationProjectParameterList
                        {
                            new SpeciesObservationProjectParameter
                            {
                                ProjectName = projectName,
                                Property    = projectParameterName1,
                                Value       = projectParameterValue1
                            }
                        }
                    };

                    speciesObservationList.Add(speciesObservation);
                    return(speciesObservationList);
                }
            };

            var viewManager = new SpeciesObservationTableViewManager(
                SessionHandler.UserContext,
                SessionHandler.MySettings);
            ViewTableViewModel viewModel = viewManager.CreateViewTableViewModel(
                SessionHandler.MySettings.Presentation.Table.SpeciesObservationTable.SpeciesObservationTableColumnsSetId);

            tableFields = viewModel.TableFields;

            obsResultList.Add(new SpeciesObservationViewModel
            {
                Id       = observationId.ToString(),
                Projects = new List <ProjectViewModel>
                {
                    new ProjectViewModel()
                    {
                        Name = projectName,
                        ProjectParameters = new Dictionary <string, ProjectParameterObservationDetailFieldViewModel>
                        {
                            { projectParameterIdentifer1, new ProjectParameterObservationDetailFieldViewModel()
                              {
                                  PropertyIdentifier = projectParameterIdentifer1,
                                  Name  = projectParameterName1,
                                  Label = projectParameterName1,
                                  Value = projectParameterValue1,
                              } }
                        }
                    }
                }
            });

            //Act
            List <Dictionary <ViewTableField, string> > result = speciesObservationDataManager.GetObservationsListDictionary(
                obsResultList,
                tableFields);


            //Assert
            bool foundProjectParameter = false;

            foreach (KeyValuePair <ViewTableField, string> pair in result.First())
            {
                string headerTitle = string.Format("[{0}].[{1}]", projectName, projectParameterName1);
                if (pair.Key.Title == headerTitle && pair.Key.DataField == headerTitle && pair.Value == projectParameterValue1)
                {
                    foundProjectParameter = true;
                }
            }
            Assert.IsTrue(foundProjectParameter, "Project parameter not found");
        }