public void AuthorizationTest() { //Arrange // TODO replace this with userManager respository in the future no need to test onion manager classer here IUserDataSource userDataSource = new ArtDatabanken.WebService.Client.UserService.Fakes.StubUserDataSource() { }; List <int> taxonIds = new List <int>(); TaxonList taxonList = new TaxonList(); ITaxonAlertStatus alertStatus = new TaxonAlertStatus() { Id = (int)TaxonAlertStatusId.Green }; taxonList.Add(new Taxon() { Id = 10007, ScientificName = "ScientificName", CommonName = "CommonName", Author = "Author", Category = new TaxonCategory(), AlertStatus = alertStatus }); ITaxonManager testTaxonManager = new ArtDatabanken.Data.Fakes.StubITaxonManager() { GetTaxaIUserContextListOfInt32 = (context, taxa) => { return(taxonList); } }; CoreData.TaxonManager = testTaxonManager; // Act MySettingsController controller = new MySettingsController(userDataSource, SessionHelper); var result = controller.TaxaSummary() as PartialViewResult; // Assert Assert.IsNotNull(result); // Check view data Assert.AreEqual("TaxaSummary", result.ViewName); // Check model data var listModel = result.ViewData.Model as List <TaxonViewModel>; Assert.IsNotNull(listModel); Assert.IsTrue(listModel.Count == 1); }
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(); } }