public Dictionary<string, object> GetByForeignId( string foreignId ) { LocationController controller = new LocationController( Service ); Location l = controller.GetByForeignId( foreignId ); return ToDictionary( l ); }
public void EditPost_CannotCreate_InvalidResponsibleID() { // Arrange - create the controller Location location = new Location { LocationID = 1, Title = "LDF", Address = "Kyiv, Shevchenka St.", ResponsibleForLoc = "dan" }; LocationController target = new LocationController(mock.Object); // Act - call the action method var result = target.Edit(location); string data = (string)(new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(((JsonResult)result).Data, "error")).Target; // Assert - check the result mock.Verify(m => m.SaveLocation(It.IsAny <Location>()), Times.Never); Assert.IsInstanceOf(typeof(JsonResult), result); Assert.AreEqual("Not existing Employee's EID", data); }
public static async Task UpdateLocationCountry(LocationId id, Country country) { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new LocationRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new LocationService(repository, unitOfWork); var locationController = new LocationController(service); var updateCommand = new Commands.ChangeCountry { Id = id, Country = country }; await locationController.Put(updateCommand); }
public void CreatePost_CanCreate_ValidLocationNullResponsibleID() { // Arrange - create the controller LocationController target = new LocationController(mock.Object); Location location = new Location { LocationID = 1, Title = "LDF", Address = "Kyiv, Shevchenka St." }; // Act - call the action method RedirectToRouteResult result = (RedirectToRouteResult)target.Create(location); // Assert - check the result mock.Verify(m => m.SaveLocation(location), Times.Once); Assert.IsFalse(result.Permanent); Assert.AreEqual("Home", result.RouteValues["controller"]); Assert.AreEqual("PUView", result.RouteValues["action"]); }
public void LocationControllerTest_ReturnsPageEditorErrorIfNoLocation() { var repository = Mock.Of <ISitecoreRepository>(); var pageContext = Mock.Of <IPageContext>(pc => pc.IsPageEditor == true); var rendering = Mock.Of <IRenderingWrapper>(); var renderingContext = Mock.Of <IRenderingContext>(rc => rc.Rendering == rendering); LocationDomain domain = new LocationDomain(repository); LocationController locationController = new LocationController(domain, pageContext, renderingContext); var result = locationController.Featured() as ViewResult; Assert.AreEqual("~/Views/Shared/_NoDatasource.cshtml", result.ViewName); }
public void LocationControllerTest_ReturnsEmptyIfNoLocation() { var repository = Mock.Of <ISitecoreRepository>(); var pageContext = Mock.Of <IPageContext>(); var rendering = Mock.Of <IRenderingWrapper>(); var renderingContext = Mock.Of <IRenderingContext>(rc => rc.Rendering == rendering); LocationDomain domain = new LocationDomain(repository); LocationController locationController = new LocationController(domain, pageContext, renderingContext); var result = locationController.Featured(); Assert.AreEqual("EmptyResult", result.GetType().Name); }
// === CONSTRUCTOR === public Find(ActionController actionController) { // Get references to other parts of game engine controller = actionController; parserState = controller.PS; gameController = controller.GC; playerController = controller.PC; itemController = controller.IC; locationController = controller.LC; dwarfController = controller.DC; playerMessageController = controller.PMC; textDisplayController = controller.TDC; // Define behaviour for getting a subject carryOverVerb = true; subjectOptional = false; }
public void GetConnections_SimpleTdb_ReturnsOneConnection() { var dt = new DateTime(2019, 09, 07, 10, 00, 00).ToUniversalTime(); var tdb = new TransitDb(0); var wr = tdb.GetWriter(); var stop0 = wr.AddOrUpdateStop("abc", 1.0, 1.0, new List <Attribute> { new Attribute("name", "abc") }); var stop1 = wr.AddOrUpdateStop("def", 1.5, 1.0, new List <Attribute> { new Attribute("name", "def") }); // To early wr.AddOrUpdateConnection(stop0, stop1, "conn3", dt.AddMinutes(-15), 1000, 0, 0, new TripId(0, 0), 0); // This one we are searching for wr.AddOrUpdateConnection(stop0, stop1, "conn0", dt.AddMinutes(5), 1000, 0, 0, new TripId(0, 0), 0); // Wrong departure station wr.AddOrUpdateConnection(stop1, stop0, "conn1", dt.AddMinutes(15), 1000, 0, 0, new TripId(0, 0), 0); // To late: falls out of the window of 1hr wr.AddOrUpdateConnection(stop0, stop1, "conn2", dt.AddMinutes(65), 1000, 0, 0, new TripId(0, 0), 0); wr.Close(); var transitDbs = new List <Operator> { { new Operator("", tdb, null, 0, null, null) } }; State.GlobalState = new State(transitDbs, null, null, null); var lc = new LocationController(); var result = lc.GetConnections("abc", dt); var returnedSegments = result.Value.Segments; Assert.NotNull(returnedSegments); Assert.Single(returnedSegments); Assert.Equal(dt.AddMinutes(5), returnedSegments[0].Departure.Time); }
public void LocationController_Post_AddsNewElement() { var newLocation = new Location { Id = Guid.NewGuid(), Latitude = -1, Longitude = -1, Name = string.Format("Location {0}", DateTime.Now.TimeOfDay), UserId = TestUser }; var controller = new LocationController(_service, null); controller.Post(newLocation); var location = controller.Get(newLocation.Id); Assert.AreEqual(location.Name, newLocation.Name); }
public void DeletePost_CannotDelete_ValidLocation() { // Arrange - create the controller LocationController target = new LocationController(mock.Object); mock.Setup(x => x.DeleteLocation(It.IsAny <int>())) .Callback(() => { throw new System.Data.Entity.Infrastructure.DbUpdateException(); }); // Act - call the action method RedirectToRouteResult result = (RedirectToRouteResult)target.DeleteConfirmed(2); // Assert - check the result mock.Verify(m => m.DeleteLocation(2), Times.Once); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); Assert.AreEqual("Home", result.RouteValues["controller"]); Assert.AreEqual("DataBaseDeleteError", result.RouteValues["action"]); }
public void CountriesDropDownList_Default_ListOfAllCountries() { //Arrange LocationController controller = new LocationController(mock.Object); //Act var result = controller.CountriesDropDownList(); var expected = result.ToArray(); //Asset Assert.IsInstanceOf(typeof(SelectList), result); Assert.AreEqual(5, expected.Length); Assert.AreEqual("Belarus", expected[0].Text); Assert.AreEqual("Poland", expected[1].Text); Assert.AreEqual("Sweden", expected[2].Text); Assert.AreEqual("Ukraine", expected[3].Text); Assert.AreEqual("Zimbabve", expected[4].Text); }
public async void Delete_Errors() { LocationControllerMockFacade mock = new LocationControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); LocationController controller = new LocationController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
public async Task Invalid_Id_Returns_Null() { var id = Guid.NewGuid(); var city = City.Create(Guid.NewGuid(), "city"); var country = Country.Create(Guid.NewGuid(), "country"); var location = Location.Create(id, city, country); var mockLocationService = new Mock <ILocationService>(); mockLocationService.Setup(s => s.GetLocationAsync(Guid.NewGuid())) .Returns(() => Task.FromResult(location)); var locationController = new LocationController(mockLocationService.Object); var result = await locationController.GetLocation(id); Assert.Null(result); }
public void EditPost_CannotEdit_InvalidLocation() { // Arrange - create the controller Location location = new Location { }; LocationController target = new LocationController(mock.Object); // Act - call the action method target.ModelState.AddModelError("error", "error"); var result = target.Edit(location); string data = (string)(new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(((JsonResult)result).Data, "error")).Target; // Assert - check the result mock.Verify(m => m.SaveLocation(location), Times.Never); Assert.IsInstanceOf(typeof(JsonResult), result); Assert.AreEqual("", data); //Assert.IsInstanceOf(typeof(Location), result.ViewData.Model); }
public async Task Index_ReturnsView_WithSingleLocationAndRooms() { int locationId = 1; // Setup service var mockLocationService = new Mock <ILocationService>(); mockLocationService.Setup(service => service.GetLocation(locationId)) .ReturnsAsync(GetTestLocation()); var mockRoomService = new Mock <IRoomService>(); mockRoomService.Setup(service => service.GetRoomsByLocation(locationId)) .ReturnsAsync(GetTestRooms()); var controller = new LocationController( mockLocationService.Object, mockRoomService.Object ); // Run action var result = await controller.Index(locationId); // Do we have the right view? var viewResult = Assert.IsType <ViewResult>(result); // Do we have the right model? var model = Assert.IsAssignableFrom <IndexViewModel>(viewResult.ViewData.Model); // Do we have the right location? Assert.Equal(GetTestLocation().Name, model.Location); // Do we have the correct number of rooms? Assert.Equal(GetTestRooms().Count(), model.Rooms.Count()); //Have the rooms been mapped accordingly? var expected = GetTestRooms().Select(r => new RoomViewModel() { ID = r.ID, Name = r.Name }).First(); var actual = model.Rooms.First(); Assert.Equal(expected.ID, actual.ID); }
public void EditPost_ValidModelConcurrency_ErrorReturned() { //Arrange LocationController controller = new LocationController(mock.Object); mock.Setup(m => m.SaveLocation(It.IsAny <Location>())).Throws(new DbUpdateConcurrencyException()); string modelError = "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled."; //Act JsonResult result = (JsonResult)controller.Edit(mock.Object.Locations.FirstOrDefault()); string data = (string)(new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(result.Data, "error")).Target; //Assert mock.Verify(d => d.SaveLocation(It.IsAny <Location>()), Times.Once()); Assert.AreEqual(typeof(JsonResult), result.GetType()); Assert.AreEqual(modelError, data); }
public async void All_Not_Exists() { LocationControllerMockFacade mock = new LocationControllerMockFacade(); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult <List <ApiLocationServerResponseModel> >(new List <ApiLocationServerResponseModel>())); LocationController controller = new LocationController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0, string.Empty); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiLocationServerResponseModel>; items.Should().BeEmpty(); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())); }
public async void Update_NotFound() { LocationControllerMockFacade mock = new LocationControllerMockFacade(); var mockResult = new Mock <UpdateResponse <ApiLocationServerResponseModel> >(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiLocationServerRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiLocationServerResponseModel> >(mockResult.Object)); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiLocationServerResponseModel>(null)); LocationController controller = new LocationController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiLocationServerModelMapper()); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Update(default(int), new ApiLocationServerRequestModel()); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public void CreatePost_CannotCreate_InvalidLocation() { // Arrange - create the controller Location location = new Location(); LocationController target = new LocationController(mock.Object); IEnumerable <Country> countriesList = from c in mock.Object.Countries orderby c.CountryName select c; // Act - call the action method target.ModelState.AddModelError("error", "error"); ViewResult result = target.Create(location) as ViewResult; // Assert - check the result mock.Verify(m => m.SaveLocation(It.IsAny <Location>()), Times.Never); Assert.AreEqual(countriesList.ToList(), ((ViewResult)result).ViewBag.CountryList.Items); Assert.IsInstanceOf(typeof(Location), result.ViewData.Model); Assert.IsInstanceOf(typeof(ViewResult), result); }
public void EditTest() { var controller = new LocationController(); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); var boundryPolygon = new List <BoundryPolygon>(); Location location = new Location() { Id = 10, StreetAddress = "Street Address 110 4545445454", LocalMunicipality = "test", Region = "JHB", Suburb = "Test", Province = "Gauteng", GPSCoordinates = new GPSCoordinate() { Id = 24, Latitude = "-26.325822222", Longitude = "28.3658 2222" }, //CreatedDate = DateTime.Now, //CreatedUserId = 1, //FacilityId = 5 }; boundryPolygon.Add(new BoundryPolygon() { Longitude = "25.3698", Latitude = "-25.3652" }); boundryPolygon.Add(new BoundryPolygon() { Longitude = "11.3698", Latitude = "-11.3652" }); boundryPolygon.Add(new BoundryPolygon() { Longitude = "2225.3698", Latitude = "-2225.3652" }); location.BoundryPolygon = boundryPolygon; var result = controller.CreateEdit(location); Assert.IsTrue(result.IsSuccessStatusCode); }
public void EditPost_CanEdit_ValidLocationWithResponsibleID() { // Arrange - create the controller LocationController target = new LocationController(mock.Object); Location location = new Location { LocationID = 1, Title = "LDF", Address = "Kyiv, Shevchenka St.", ResponsibleForLoc = "daol" }; // Act - call the action method var result = (RedirectToRouteResult)target.Edit(location); // Assert - check the result Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); Assert.IsFalse(result.Permanent); Assert.AreEqual("Home", result.RouteValues["controller"]); Assert.AreEqual("PUView", result.RouteValues["action"]); mock.Verify(m => m.SaveLocation(location), Times.Once); }
public static async Task <dynamic> CreateInvalidLocation(string invalidProp) { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new LocationRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new LocationService(repository, unitOfWork); var command = new Commands.Create { Id = null, CityId = invalidProp == "CityId" ? default : Guid.NewGuid(), CountryId = invalidProp == "CountryId" ? default : Guid.NewGuid() }; var locationController = new LocationController(service); return(await locationController.Post(command)); }
public static void showCandidate(CandidateData candidateData) { if (_instance == null || _instance._isShowingPopup) { return; } Vector3 playerLongLat = LocationController.getPlayerLongLat(); _instance._nameLabel.text = candidateData.placeName; _instance._addressLabel.text = candidateData.placeAddress; _instance._mapsButton.onClick.RemoveAllListeners(); _instance._mapsButton.onClick.AddListener(() => { Application.OpenURL(String.Format("https://www.google.com/maps/dir/'{0},{1}'/'{2},{3}'", playerLongLat.z, playerLongLat.x, candidateData.z, candidateData.x)); }); _instance._exitButton.onClick.RemoveAllListeners(); _instance._exitButton.onClick.AddListener(() => { _instance.hidePopup(); }); _instance._isShowingPopup = true; _instance._animator.SetTrigger("Show"); }
public void GivenNavigatorShowEditView() { INavigationRepository repository = GenerateRepository(); LocationController target = new LocationController(repository); Navigator navigator = GenerateNavigator(); ActionResult actual; actual = target.Edit(navigator); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(ViewResult)); ViewResult result = actual as ViewResult; Assert.AreEqual("Edit", result.ViewName); LocationViewModel model = result.Model as LocationViewModel; Assert.AreEqual(model.LocationId, navigator.LocationId); Assert.AreEqual(model.LocationName, navigator.LocationName); TestViewResult(navigator, result); }
public async Task Get_All_Locations() { List <LocationDto> mockLocations = MockLocations(); var mockRepository = new Mock <ILocationRepository>(); mockRepository.Setup(repo => repo.GetAllDtoAsync()) .Returns(() => Task.FromResult(mockLocations.AsEnumerable())); var mockUnitOfWork = new Mock <IUnitOfWork>(); var locationService = new LocationService(mockRepository.Object, mockUnitOfWork.Object); var locationController = new LocationController(locationService); var result = await locationController.GetLocations(); Assert.Equal(10, result.Count()); mockRepository.Verify(mock => mock.GetAllDtoAsync(), Times.Once()); }
public async void Get_Exists() { LocationControllerMockFacade mock = new LocationControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new ApiLocationServerResponseModel())); LocationController controller = new LocationController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Get(default(int)); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var record = (response as OkObjectResult).Value as ApiLocationServerResponseModel; record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public async Task LocationController_GetAllLocation_ReturnLocations() { //Arrange IEnumerable <Location> lstLocation = new List <Location> { new Location { LocationId = 1, LocationName = "Test" }, new Location { LocationId = 2, LocationName = "Test1" } }; locationRepository.Setup(x => x.GetAllLocations()).Returns(Task.FromResult(lstLocation)); LocationController locationController = new LocationController(locationRepository.Object); //Act var result = await locationController.GetAllLocations(); //Assert Assert.IsNotNull(result); }
public void GivenLocationViewModelCreateNewLocation() { INavigationRepository repository = GenerateRepository(); LocationController target = new LocationController(repository); LocationViewModel location = Utilities.ObjectFactory.CreateLocation(GenerateNavigator()); repository.Expect(r => r.SaveLocation(location)).Return(true); ActionResult actual; actual = target.Create(location); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(RedirectToRouteResult)); RedirectToRouteResult result = actual as RedirectToRouteResult; Assert.AreEqual("area_default", result.RouteName); Assert.AreEqual("Details", result.RouteValues["Action"]); Assert.AreEqual(location.RegionName, result.RouteValues["RegionName"]); Assert.AreEqual(location.AreaName, result.RouteValues["AreaName"]); repository.VerifyAllExpectations(); }
// Use this for initialization void Start() { symbolController = SymbolManager.instance; locationController = LocationController.instance; uiController = UIController.instance; /* * WebCamTexture webcamTexture = new WebCamTexture(); * cameraRender.texture = webcamTexture; * cameraRender.material.mainTexture = webcamTexture; * webcamTexture.Play(); */ /* * locationController.currentLocation.latitude = 39.913399f; * locationController.currentLocation.longitude = 32.834782f; * locationController.currentLocation.altitude = 0.0f; */ InvokeRepeating("LocateUserLocation", 0, 5); }
public async Task ReturnPredictiveList(BGBA.Models.N.Location.MapOptions value, BGBA.Models.N.Location.PredictionsResult expected) { var serviceTableMock = new Mock <ITableServices>(); var serviceMapMock = new Mock <IMapServices>(); serviceMapMock.Setup(x => x.GetPrediction(value)) .Returns(() => new TaskFactory <BGBA.Models.N.Location.PredictionsResult>().StartNew(() => expected)); var mapperMock = new Mock <IMapper>(); var loggerMock = new Mock <ILogger <LocationController> >(); var controller = new LocationController(serviceMapMock.Object, loggerMock.Object, serviceTableMock.Object, mapperMock.Object); var result = await controller.Predictive(value); var client = result.Should().BeOfType(typeof(ObjectResult)) .And.Should().BeAssignableTo <List <BGBA.Models.N.Location.PredictionsResult> >().Subject; client.Should().BeEquivalentTo(expected); }
public async void Patch_Record_Not_Found() { LocationControllerMockFacade mock = new LocationControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiLocationServerResponseModel>(null)); LocationController controller = new LocationController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var patch = new JsonPatchDocument <ApiLocationServerRequestModel>(); patch.Replace(x => x.GpsLat, 1); IActionResult response = await controller.Patch(default(int), patch); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
private int? SaveLocation( Location l ) { LocationController controller = new LocationController( Service ); if ( l.Id == 0 ) { l.CreatedByPersonAliasId = Service.LoggedInPerson.PrimaryAliasId; controller.Add( l ); } else { l.ModifiedByPersonAliasId = Service.LoggedInPerson.PrimaryAliasId; controller.Update( l ); } return controller.GetByGuid( l.Guid ).Id; }
public void Initialize() { InitRepoAndTwoLocations(); _controller = new LocationController(_repository); }
private Location GetLocationByAddress(string street1, string street2, string city, string state, string postalCode) { StringBuilder filterBuilder = new StringBuilder(); filterBuilder.AppendFormat( "Street1 eq '{0}'", street1 ); if ( String.IsNullOrWhiteSpace( street2 ) ) { filterBuilder.Append( " and ( Street2 eq null or Street2 eq '')" ); } else { filterBuilder.AppendFormat( " and Street2 eq '{0}'", street2 ); } filterBuilder.AppendFormat( " and City eq '{0}'", city ); filterBuilder.AppendFormat( " and State eq '{0}'", state ); filterBuilder.AppendFormat( " and PostalCode eq '{0}'", postalCode ); LocationController controller = new LocationController( Service ); return controller.GetByFilter( filterBuilder.ToString() ).FirstOrDefault(); }
private Location GetLocationById( int locationId ) { LocationController controller = new LocationController( Service ); return controller.GetById( locationId ); }