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

            SessionHandler.MySettings = new MySettings();
            SessionHandler.MySettings.Filter.Taxa.TaxonIds                   = taxaIds;
            SessionHandler.MySettings.Filter.Taxa.IsActive                   = true;
            SessionHandler.MySettings.Presentation.Table.IsActive            = false;
            SessionHandler.MySettings.DataProvider.DataProviders.IsActive    = false;
            SessionHandler.MySettings.Calculation.GridStatistics.IsActive    = false;
            SessionHandler.MySettings.Calculation.SummaryStatistics.IsActive = false;
            SessionHandler.MySettings.Filter.Occurrence.IsActive             = false;
            SessionHandler.MySettings.Filter.Quality.IsActive                = false;
            SessionHandler.MySettings.Filter.Spatial.IsActive                = false;
            SessionHandler.MySettings.Filter.Temporal.IsActive               = false;
            SessionHandler.MySettings.Presentation.Map.IsActive              = false;
            SessionHandler.MySettings.Presentation.Report.IsActive           = false;
            SessionHandler.MySettings.DataProvider.MapLayers.IsActive        = false;

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

            Assert.IsNotNull(result);

            var taxonResult = resultController.GetTaxonGridCountAsJSON();

            Assert.IsNotNull(taxonResult);

            JsonModel       jsonResult      = (JsonModel)taxonResult.Data;
            TaxonGridResult taxonListResult = (TaxonGridResult)jsonResult.Data;

            // Add one taxa
            taxaIds.Add(100573);
            SessionHandler.MySettings.Filter.Taxa.TaxonIds = taxaIds;

            var taxonResult2 = resultController.GetTaxonGridCountAsJSON();

            Assert.IsNotNull(taxonResult2);

            JsonModel       jsonResult2      = (JsonModel)taxonResult2.Data;
            TaxonGridResult taxonListResult2 = (TaxonGridResult)jsonResult2.Data;

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

            // If no taxa is set then all taxa will be returned
            Assert.IsTrue(taxonListResult.Cells.Count > 0);
            Assert.IsTrue(taxonListResult2.Cells.Count > 0);
            Assert.IsTrue(taxonListResult.Cells.Count > taxonListResult2.Cells.Count);
        }
        public void SpeciesRichnessGridMapUnexpectedErrorTest()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                ResultController resultController = new ResultController();

                ShimControllerContextForLogin(true, 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.SpeciesObservationMap();

                MakeGetCurrentUserFunctionCallThrowException();

                var obsResult = resultController.GetTaxonGridCountAsJSON();

                JsonModel jsonResult = (JsonModel)obsResult.Data;

                // Assert
                Assert.IsNotNull(obsResult);
                Assert.IsNotNull(result);
                Assert.IsFalse(jsonResult.Success);
                Assert.IsNull(jsonResult.Data);
                Assert.AreEqual("Login to UserService or other service failed.", jsonResult.Msg);
            }
        }
        public void GridStatisticsTableOnSpeciesRichnessGetTest()
        {
            // 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;
            SessionHandler.MySettings.Calculation.GridStatistics.CalculateNumberOfObservations = false;
            SessionHandler.MySettings.Calculation.GridStatistics.CalculateNumberOfTaxa         = true;
            SessionHandler.MySettings.Calculation.GridStatistics.GridSize           = 50000;
            SessionHandler.MySettings.Calculation.GridStatistics.CoordinateSystemId = (int)GridCoordinateSystem.Rt90_25_gon_v;
            SessionHandler.MySettings.Calculation.GridStatistics.IsActive           = true;

            // Act
            // Get Views and model
            var viewResult = resultController.Tables();

            Assert.IsNotNull(viewResult);

            var result = resultController.GridStatisticsTableOnSpeciesRichness() as ViewResult;

            Assert.IsNotNull(result);
            var model = (ResultTaxonGridTableViewModel)result.ViewData.Model;

            // Get json result from server
            JsonNetResult   taxonResult     = resultController.GetTaxonGridCountAsJSON();
            JsonModel       jsonResult      = (JsonModel)taxonResult.Data;
            TaxonGridResult taxonListResult = (TaxonGridResult)jsonResult.Data;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(model.OriginalCoordinateSystemName.Equals("RT 90"));

            // Todo: should be fixed when naming convention of RT 90 and SWEREF99 is resolved.
            // Assert.IsTrue(model.OriginalCoordinateSystemName.Equals(GridCoordinateSystem.Rt90_25_gon_v.ToString()));
            Assert.IsTrue(model.CoordinateSystemName.Equals("Google Mercator"));

            Assert.IsNotNull(taxonResult);
            Assert.IsNotNull(jsonResult);
            Assert.IsTrue(jsonResult.Success);
            Assert.IsTrue(taxonListResult.Cells.Count > 0);
            Assert.IsTrue(taxonListResult.Cells[0].SpeciesCount > 0);
            Assert.IsTrue(taxonListResult.Cells[0].ObservationCount > 0);

            // Not used Assert.IsNotNull(taxonListResult.Cells[0].CentreCoordinate);
            Assert.IsNotNull(taxonListResult.Cells[0].CentreCoordinateX);
            Assert.IsNotNull(taxonListResult.Cells[0].CentreCoordinateY);
            Assert.IsNotNull(taxonListResult.Cells[0].BoundingBox);
            Assert.IsNotNull(taxonListResult.Cells[0].OriginalCentreCoordinateX);
            Assert.IsNotNull(taxonListResult.Cells[0].OriginalCentreCoordinateY);
        }
        public void SpeciesRichnessGridMapSuccessTest()
        {
            // 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;
            SessionHandler.MySettings.Calculation.GridStatistics.CalculateNumberOfObservations = false;
            SessionHandler.MySettings.Calculation.GridStatistics.CalculateNumberOfTaxa         = true;
            SessionHandler.MySettings.Calculation.GridStatistics.GridSize           = 50000;
            SessionHandler.MySettings.Calculation.GridStatistics.CoordinateSystemId = (int)GridCoordinateSystem.Rt90_25_gon_v;
            SessionHandler.MySettings.Calculation.GridStatistics.IsActive           = true;

            // Act
            // Get Views and model
            var viewResult = resultController.Maps();

            Assert.IsNotNull(viewResult);

            var result = resultController.SpeciesRichnessGridMap() as ViewResult;

            Assert.IsNotNull(result);
            var viewName = result.ViewName;

            // Get json result from server
            JsonNetResult   taxonResult    = resultController.GetTaxonGridCountAsJSON();
            JsonModel       jsonResult     = (JsonModel)taxonResult.Data;
            TaxonGridResult taxonMapResult = (TaxonGridResult)jsonResult.Data;

            // Assert
            Assert.IsNotNull(result);
            // Assert.IsTrue(viewName.Equals("SpeciesRichnessGridMap"));

            Assert.IsNotNull(taxonResult);
            Assert.IsNotNull(jsonResult);
            Assert.IsTrue(jsonResult.Success);
            Assert.IsNotNull(taxonMapResult);
            Assert.IsTrue(taxonMapResult.Cells.Count > 0);
            Assert.IsTrue(taxonMapResult.Cells[0].SpeciesCount > 0);
            Assert.IsTrue(taxonMapResult.Cells[0].ObservationCount > 0);

            // Not used Assert.IsNotNull(taxonListResult.Cells[0].CentreCoordinate);
            Assert.IsNotNull(taxonMapResult.Cells[0].CentreCoordinateX);
            Assert.IsNotNull(taxonMapResult.Cells[0].CentreCoordinateY);
            Assert.IsNotNull(taxonMapResult.Cells[0].BoundingBox);
            Assert.IsNotNull(taxonMapResult.Cells[0].OriginalCentreCoordinateX);
            Assert.IsNotNull(taxonMapResult.Cells[0].OriginalCentreCoordinateY);

            Assert.IsTrue(taxonMapResult.GridCellCoordinateSystem.Equals(GridCoordinateSystem.Rt90_25_gon_v.ToString()));
        }
        public void SpeciesRichnessGridMapNoTaxaSelectedTest()
        {
            ResultController resultController;
            JsonNetResult    result;
            JsonModel        jsonResult;
            TaxonGridResult  model;

            resultController = new ResultController();
            SessionHandler.MySettings.Filter.Taxa.TaxonIds = new ObservableCollection <int>();

            result     = resultController.GetTaxonGridCountAsJSON();
            jsonResult = (JsonModel)result.Data;
            model      = jsonResult.Data as TaxonGridResult;

            Assert.IsTrue(jsonResult.Success);
            Assert.IsNotNull(jsonResult.Data);
            Assert.IsNotNull(model);
            Assert.IsTrue(model.Cells.Count > 0);
        }