public void TableUnexpectedErrorTest()
        {
            // Arrange
            ResultController resultController = new ResultController();
            var taxaIds = new ObservableCollection <int> {
                100573
            };

            SessionHandler.MySettings = new MySettings();
            SessionHandler.MySettings.Filter.Taxa.TaxonIds        = taxaIds;
            SessionHandler.MySettings.Filter.Taxa.IsActive        = true;
            SessionHandler.MySettings.Presentation.Table.IsActive = true;

            // Act
            var result = resultController.SpeciesObservationTable();

            MakeGetCurrentUserFunctionCallThrowException();
            var obsResult = resultController.GetPagedObservationListAsJSON(1, 0, 25);

            JsonModel jsonResult = (JsonModel)obsResult.Data;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(obsResult);
            Assert.IsFalse(jsonResult.Success);
            Assert.IsNull(jsonResult.Data);
            Assert.AreEqual("Login to UserService or other service failed.", jsonResult.Msg);
        }
        public void TableGetNoDataTest()
        {
            // Arrange
            ResultController resultController = new ResultController();

            SessionHandler.MySettings = new MySettings();
            SessionHandler.MySettings.Filter.Taxa.AddTaxonId(2000000000);

            // Act
            var result = resultController.SpeciesObservationTable();

            Assert.IsNotNull(result);

            var obsResult = resultController.GetPagedObservationListAsJSON(1, 0, 25);

            Assert.IsNotNull(obsResult);

            JsonModel jsonResult = (JsonModel)obsResult.Data;
            List <Dictionary <string, string> > observationListResult = (List <Dictionary <string, string> >)jsonResult.Data;

            // Assert
            Assert.IsNotNull(jsonResult);
            Assert.IsTrue(jsonResult.Success);
            Assert.IsTrue(jsonResult.Total == 0);
            Assert.IsNotNull(observationListResult);
        }
Ejemplo n.º 3
0
        public void TableGetTest()
        {
            //Arrange
            SetSwedishLanguage();
            ResultController presentationController = new ResultController();
            var taxaIds = new ObservableCollection <int>();

            taxaIds.Add(100573);
            SessionHandler.MySettings = new MySettings();
            SessionHandler.MySettings.Filter.Taxa.TaxonIds        = taxaIds;
            SessionHandler.MySettings.Filter.Taxa.IsActive        = true;
            SessionHandler.MySettings.Presentation.Table.IsActive = true;

            //Act

            var result = presentationController.SpeciesObservationTable();

            Assert.IsNotNull(result);

            var obsResult = presentationController.GetPagedObservationListAsJSON(1, 0, 25);

            Assert.IsNotNull(obsResult);

            JsonModel jsonResult = (JsonModel)obsResult.Data;
            List <Dictionary <string, string> > observationListResult = (List <Dictionary <string, string> >)jsonResult.Data;

            //Assert
            Assert.IsNotNull(jsonResult);
            Assert.IsTrue(jsonResult.Success);
            var data = jsonResult.Data as IList;

            Assert.IsTrue(data.Count > 0);
            Assert.IsTrue(observationListResult.Count > 0);

            BaseDataTest.VerifyObservationDataForGriffelblomfluga1000573(observationListResult);

            SetEnglishLanguage();
        }
        public void ViewObservationsForLoggedInUser()
        {
            using (ShimsContext.Create())
            {
                //Login user
                LoginTestUserAnalyser();
                ShimFilePath();

                // Add another role to user context
                base.AddSightingRoleToUserContext();

                UserRoleModel roleModel       = new UserRoleModel();
                IRole         newAnalyzerRole = SessionHandler.UserContext.CurrentRoles[0];
                AccountController.ChangeUserRole(Convert.ToString(newAnalyzerRole.Id), roleModel);

                // Verify role
                Assert.IsTrue(SessionHandler.UserContext.CurrentRole.Id == newAnalyzerRole.Id);

                // Set language to swedish since reference data is on that language
                SetSwedishLanguage();

                // Create controllers
                FilterController filterController = new FilterController();
                ResultController resultController = new ResultController();
                StubResultController(resultController);
                MySettingsController settingsController = new MySettingsController();

                // TODO Add tests for presentation controller data
                FormatController presentationController = new FormatController();

                //Check that no data is set to mysettings, except for map and table that should be checked by default
                Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.TaxonIds.Count == 0);
                Assert.IsTrue(SessionHandler.MySettings.Presentation.Map.IsActive);
                Assert.IsTrue(SessionHandler.MySettings.Presentation.Table.IsActive);
                Assert.IsFalse(SessionHandler.MySettings.Filter.Taxa.IsActive);

                //*********************************   Set and test filter data ***************************
                //Select to filter on taxa and select taxa ids
                //SessionHandler.MySettings.Filter.TaxaSetting.IsSelected = true;

                filterController.RemoveAllFilteredTaxon("Home/Index");
                Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.TaxonIds.Count == 0);

                //Use taxon 100573-Griffelblomfluga
                int[]  taxaIds = new int[] { 100573 };
                string strJson = JsonConvert.SerializeObject(taxaIds);
                filterController.AddTaxaToFilter(strJson, "Home/Index");
                Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.TaxonIds.Contains(100573));
                Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.TaxonIds.Count == 1);

                //****************************  Set spatial data ***************************************************
                Polygon polygon1 = CreateTestPolygon1();
                var     feature1 = new Feature(polygon1);
                var     features = new List <Feature> {
                    feature1
                };
                var    featureCollection = new FeatureCollection(features);
                string geojson           = JsonConvert.SerializeObject(featureCollection, JsonHelper.GetDefaultJsonSerializerSettings());

                // Update spatial filter
                JsonNetResult filterResult     = filterController.UpdateSpatialFilter(geojson);
                JsonModel     jsonFilterResult = (JsonModel)filterResult.Data;
                Assert.IsTrue(jsonFilterResult.Success);
                Assert.IsTrue(SessionHandler.MySettings.Filter.Spatial.IsActive == true);
                Assert.IsTrue(SessionHandler.MySettings.Filter.Spatial.Polygons.Count == 1);

                //**************************** Check map data *******************************************************
                // Sow map view for Griffelblomfluga
                int        numberOfObservations = 0;
                ViewResult result = resultController.SpeciesObservationMap();
                Assert.IsNotNull(result);

                //Get the map data to be shown
                JsonNetResult obsMap = resultController.GetObservationsAsGeoJSON();
                Assert.IsNotNull(obsMap.Data);
                var jsonMapResult = (JsonModel)obsMap.Data;
                var noObs         = (SpeciesObservationsGeoJsonModel)jsonMapResult.Data;
                numberOfObservations = noObs.Points.Features.Count;
                Assert.IsTrue(SessionHandler.MySettings.Presentation.Map.IsActive);
                Assert.IsTrue(SessionHandler.MySettings.Presentation.Table.IsActive);
                Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.IsActive);

                //************************ Check table data *********************************************
                //Select to show table data from observations
                result = resultController.SpeciesObservationTable() as ViewResult;
                Assert.IsNotNull(result);
                var viewModel = result.ViewData.Model as ViewTableViewModel;
                Assert.IsNotNull(viewModel);
                //Get observations
                var obsResult = resultController.GetPagedObservationListAsJSON(1, 0, 25);
                Assert.IsNotNull(obsResult);
                JsonModel jsonResult = (JsonModel)obsResult.Data;
                List <Dictionary <string, string> > observationListResult = (List <Dictionary <string, string> >)jsonResult.Data;

                //Check observations
                Assert.IsNotNull(jsonResult);
                Assert.IsTrue(jsonResult.Success);
                Assert.IsTrue(jsonResult.Total > 5);
                Assert.IsTrue(observationListResult.Count > 5);
                Assert.IsTrue(numberOfObservations == observationListResult.Count, "Number of observations differs between Map and ObsTable");
                //Verfy observations
                BaseDataTest.VerifyObservationDataForGriffelblomfluga1000573(observationListResult);

                //*********************** Check detailsPanel ****************************************************
                string            observationGUID   = observationListResult[5]["ObservationId"];
                DetailsController detailsController = new DetailsController();

                //Act
                // Returning "hard coded" value för first observation for griffelblomfluga
                var detailsResult = detailsController.ObservationDetail(observationGUID) as ViewResult;

                //Assert
                Assert.IsNotNull(detailsResult);

                //*********************** Verfy user settings, save and load *************************************

                // Save settings
                settingsController.SaveMySettings("Home/Index");

                Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.TaxonIds.Count > 0);

                //Logout TestUser
                LogoutTestUser();

                Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.TaxonIds.Count == 0);
                Assert.IsTrue(SessionHandler.MySettings.Presentation.Map.IsActive);
                Assert.IsTrue(SessionHandler.MySettings.Presentation.Table.IsActive);
                Assert.IsFalse(SessionHandler.MySettings.Filter.Taxa.IsActive);

                LoginTestUserAnalyser();
                //Use taxon 100573-Griffelblomfluga
                taxaIds = new int[] { 100573 };
                strJson = JsonConvert.SerializeObject(taxaIds);
                filterController.AddTaxaToFilter(strJson, "Home/Index");

                result = resultController.SpeciesObservationTable() as ViewResult;
                Assert.IsNotNull(result);

                // Check observations in table
                obsResult = resultController.GetPagedObservationListAsJSON(1, 0, 25);
                Assert.IsNotNull(obsResult);
                jsonResult            = (JsonModel)obsResult.Data;
                observationListResult = (List <Dictionary <string, string> >)jsonResult.Data;
                Assert.IsNotNull(jsonResult);
                Assert.IsTrue(jsonResult.Success);

                Assert.IsTrue(jsonResult.Total > 5);
                Assert.IsTrue(observationListResult.Count > 5);
                Assert.IsTrue(numberOfObservations == observationListResult.Count, "Number of observations differs between saved settings and not saved settings for ObsTable");

                BaseDataTest.VerifyObservationDataForGriffelblomfluga1000573(observationListResult);


                // Reset to english language
                SetEnglishLanguage();
            }
        }
        public void ViewObservations()
        {
            //Arrange
            // Set language to swedish since reference data is on that language
            SetSwedishLanguage();
            FilterController filterController = new FilterController();
            ResultController resultController = new ResultController();

            // TODO Add tests for presentation controller data
            FormatController presentationController = new FormatController();

            //Act and Assert
            Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.TaxonIds.Count == 0);

            filterController.RemoveAllFilteredTaxon("Home/Index");
            Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.TaxonIds.Count == 0);

            int[]  taxaIds = new int[] { 100573 };
            string strJson = JsonConvert.SerializeObject(taxaIds);

            filterController.AddTaxaToFilter(strJson, "Home/Index");
            Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.TaxonIds.Contains(100573));
            Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.TaxonIds.Count == 1);

            //****************************  Set spatial data ***************************************************

            Polygon polygon1 = CreateTestPolygon1();
            var     feature1 = new Feature(polygon1);
            var     features = new List <Feature> {
                feature1
            };
            var    featureCollection = new FeatureCollection(features);
            string geojson           = JsonConvert.SerializeObject(featureCollection, JsonHelper.GetDefaultJsonSerializerSettings());
            // Update spatial filter
            JsonNetResult filterResult     = filterController.UpdateSpatialFilter(geojson);
            JsonModel     jsonFilterResult = (JsonModel)filterResult.Data;

            Assert.IsTrue(jsonFilterResult.Success);
            Assert.IsTrue(SessionHandler.MySettings.Filter.Spatial.IsActive == true);
            Assert.IsTrue(SessionHandler.MySettings.Filter.Spatial.Polygons.Count == 1);

            //**************************** Check map data *******************************************************
            // Sow map view for Griffelblomfluga
            ViewResult pvResult = resultController.SpeciesObservationMap();

            Assert.IsNotNull(pvResult);
            // Test that correct view is returned, Todo: No view is returned, delete?
            // Assert.AreEqual("SpeciesObservationMap", pvResult.ViewName);
            //Get the map data to be shown
            JsonNetResult obsMap = resultController.GetObservationsAsGeoJSON();

            Assert.IsNotNull(obsMap.Data);
            var jsonMapResult        = (JsonModel)obsMap.Data;
            var noObs                = (SpeciesObservationsGeoJsonModel)jsonMapResult.Data;
            int numberOfObservations = noObs.Points.Features.Count;

            //Check settings
            Assert.IsTrue(SessionHandler.MySettings.Presentation.Map.IsActive);
            Assert.IsFalse(SessionHandler.MySettings.Presentation.Table.IsActive);
            Assert.IsTrue(SessionHandler.MySettings.Filter.Taxa.IsActive);

            //************************ Check table data *********************************************

            var result = resultController.SpeciesObservationTable() as ViewResult;

            Assert.IsNotNull(result);
            // Test that correct view is returned
            Assert.AreEqual("Table", result.ViewName);

            var viewModel = result.ViewData.Model as ViewTableViewModel;

            Assert.IsNotNull(viewModel);


            var obsResult = resultController.GetPagedObservationListAsJSON(1, 0, 25);

            Assert.IsNotNull(obsResult);

            JsonModel jsonResult = (JsonModel)obsResult.Data;
            List <Dictionary <string, string> > observationListResult = (List <Dictionary <string, string> >)jsonResult.Data;

            Assert.IsNotNull(jsonResult);
            Assert.IsTrue(jsonResult.Success);

            Assert.IsTrue(jsonResult.Total > 20);
            Assert.IsTrue(observationListResult.Count > 20);
            Assert.IsTrue(numberOfObservations == observationListResult.Count, "Number of observations differs between Map and ObsTable");


            BaseDataTest.VerifyObservationDataForGriffelblomfluga1000573(observationListResult);

            //*********************** Check detailsPanel ****************************************************
            string            observationGUID   = observationListResult[20]["ObservationId"];
            DetailsController detailsController = new DetailsController();

            //Act
            // Returning "hard coded" value för first observation for griffelblomfluga
            var detailsResult = detailsController.ObservationDetail(observationGUID) as ViewResult;

            //Assert
            Assert.IsNotNull(detailsResult);
            var detailsViewModel = detailsResult.ViewData.Model as ObservationDetailViewModel;

            Assert.IsNotNull(detailsViewModel);
            // Test that correct view is returned
            Assert.AreEqual("Detail", detailsResult.ViewName);

            //Check number of properties
            Assert.IsTrue(detailsViewModel.Fields.Count > 10);


            // Reset to english language
            SetEnglishLanguage();
        }
        public void TableGetTest()
        {
            // Arrange
            // Set language to swedish since reference data is on that language
            SetSwedishLanguage();

            ResultController resultController = new ResultController();
            var taxaIds = new ObservableCollection <int> {
                100573, Convert.ToInt32(TaxonId.Butterflies)
            };

            SessionHandler.MySettings = new MySettings();
            SessionHandler.MySettings.Filter.Taxa.TaxonIds        = taxaIds;
            SessionHandler.MySettings.Filter.Taxa.IsActive        = true;
            SessionHandler.MySettings.Presentation.Table.IsActive = true;

            // Act
            var viewResult = resultController.Tables();

            Assert.IsNotNull(viewResult);

            var result = resultController.SpeciesObservationTable();

            Assert.IsNotNull(result);

            var obsResult = resultController.GetPagedObservationListAsJSON(1, 0, 25);

            Assert.IsNotNull(obsResult);

            JsonModel jsonResult = (JsonModel)obsResult.Data;
            List <Dictionary <string, string> > observationListResult = (List <Dictionary <string, string> >)jsonResult.Data;

            // Assert
            Assert.IsNotNull(jsonResult, "jsonResult is null");
            Assert.IsTrue(jsonResult.Success, "jsonResult.Success is not true");
            var data = jsonResult.Data as IList;

            Assert.IsNotNull(data, "jsonResult.Data is null");
            Assert.IsTrue(data.Count >= 0, "jsonResult.Data.Count is not gerater than 0");
            Assert.IsTrue(observationListResult.Count >= 0, "List<Dictionary<string, string>> observationListResult.Count is not greater than 0");
            bool testPerformed = false;

            foreach (Dictionary <string, string> item in observationListResult)
            {
                if (item.ContainsKey("VernacularName"))
                {
                    if (item.Any(keyValuePair => keyValuePair.Key.Equals("VernacularName") && keyValuePair.Value.Equals("griffelblomfluga")))
                    {
                        BaseDataTest.VerifyObservationDataForGriffelblomfluga1000573(observationListResult);
                        testPerformed = true;
                    }
                }

                if (testPerformed)
                {
                    break;
                }
            }

            // Reset to english language
            SetEnglishLanguage();
        }