public void Can_Get_Geolocation_Details_By_URL() { // Arrange GeolocationDetails sampleModel = new GeolocationDetails() { URL = "sample URL" }; GetGeolocationDetailsByUrlReturnModel sampleViewModel = new GetGeolocationDetailsByUrlReturnModel(sampleModel); Mock <IGeolocationDetailsManager> mockManager = new Mock <IGeolocationDetailsManager>(); mockManager.Setup(x => x.GetByUrl(It.IsAny <string>())).Returns(sampleViewModel); Mock <ILocationValidator> mockLocationValidator = new Mock <ILocationValidator>(); mockLocationValidator.Setup(x => x.IsValidUrl(It.IsAny <string>())).Returns(true); var controller = new GeolocationController(mockManager.Object, mockLocationValidator.Object); // Act var actionResult = controller.Get(null, "url") as OkNegotiatedContentResult <GetGeolocationDetailsByUrlReturnModel>; // Assert Assert.IsNotNull(actionResult); Assert.AreEqual("sample URL", actionResult.Content.URL); }
public void Can_Create_Geolocation_Details_With_URL() { // Arrange GeolocationDetails sampleDetails = new GeolocationDetails() { URL = "URL" }; CreateGeolocationDetailsWithUrlReturnModel sampleControllerModel = new CreateGeolocationDetailsWithUrlReturnModel(sampleDetails); Mock <IGeolocationDetailsManager> mockManger = new Mock <IGeolocationDetailsManager>(); mockManger.Setup(x => x.CreateWithUrlAsync(It.IsAny <string>())).Returns(Task.FromResult(sampleControllerModel)); Mock <ILocationValidator> mockLocationValidator = new Mock <ILocationValidator>(); mockLocationValidator.Setup(x => x.IsValidUrl(It.IsAny <string>())).Returns(true); var controller = new GeolocationController(mockManger.Object, mockLocationValidator.Object); // Act var actionResult = controller.PostAsync("test").Result as CreatedNegotiatedContentResult <CreateGeolocationDetailsWithUrlReturnModel>; // Assert Assert.IsNotNull(actionResult); Assert.AreEqual("URL", actionResult.Content.URL); }
public void Can_Get_Geolocation_Details_By_IP() { // Arrange GeolocationDetails sampleModel = new GeolocationDetails() { IP = "sample IP" }; GetGeolocationDetailsByIpReturnModel sampleViewModel = new GetGeolocationDetailsByIpReturnModel(sampleModel); Mock <IGeolocationDetailsManager> mockManager = new Mock <IGeolocationDetailsManager>(); mockManager.Setup(x => x.GetByIp(It.IsAny <string>())).Returns(sampleViewModel); Mock <ILocationValidator> mockLocationValidator = new Mock <ILocationValidator>(); mockLocationValidator.Setup(x => x.IsValidIpAddress(It.IsAny <string>())).Returns(true); var controller = new GeolocationController(mockManager.Object, mockLocationValidator.Object); // Act var actionResult = controller.Get("ip", null) as OkNegotiatedContentResult <GetGeolocationDetailsByIpReturnModel>; // Assert Assert.IsNotNull(actionResult); Assert.AreEqual("sample IP", actionResult.Content.IP); }
public LocationApiIntegrationTests(GeolocationControllerFixture fixture) { controller = fixture.Controller; geolocationsCollection = fixture.GeolocationsCollection; // clean collection before each test geolocationsCollection.DeleteMany(FilterDefinition <Geolocation> .Empty); }
public App() { InitializeComponent(); GeolocationController.StartListener(); var nav = new NavigationPage(new LocationsListPage()) { BarBackgroundColor = Color.LightGreen, BarTextColor = Color.White }; MainPage = nav; }
public void Can_Return_BadRequest_When_No_IP_URL_Provided() { // Arrange Mock <IGeolocationDetailsManager> mockManager = new Mock <IGeolocationDetailsManager>(); Mock <ILocationValidator> mockLocationValidator = new Mock <ILocationValidator>(); var controller = new GeolocationController(mockManager.Object, mockLocationValidator.Object); // Act var actionResult = controller.Get(null, null) as BadRequestErrorMessageResult; // Assert Assert.IsNotNull(actionResult); Assert.IsNotNull(actionResult.Message); }
public void Can_Reject_Create_Geolocation_Details_When_No_IP_Or_URL_Provided(string ipOrUrl) { // Arrange Mock <IGeolocationDetailsManager> mockManger = new Mock <IGeolocationDetailsManager>(); Mock <ILocationValidator> mockLocationValidator = new Mock <ILocationValidator>(); var controller = new GeolocationController(mockManger.Object, mockLocationValidator.Object); // Act var actionResult = controller.PostAsync(ipOrUrl).Result as BadRequestErrorMessageResult; // Assert Assert.IsNotNull(actionResult); Assert.IsNotNull(actionResult.Message); }
public GeolocationControllerTests() { // TODO(emile): Mock Request.HttpContext.Connection.RemoteIpAddress var data = new GeolocationInformations(IPAddress.Parse("192.168.0.1"), "Canada", "Quebec", "Montreal", null, null); _service = new Mock <IGeolocalizationService>(); _service.Setup(x => x.GetLocation(null)).Returns(data); _service.Setup(x => x.GetLocation(It.IsAny <IPAddress>())).Returns(data); _controller = new GeolocationController(_service.Object) { ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() } }; }
public void Can_Delete_Geolocation_Details_By_URL() { // Arrange Mock <IGeolocationDetailsManager> mockManger = new Mock <IGeolocationDetailsManager>(); Mock <ILocationValidator> mockLocationValidator = new Mock <ILocationValidator>(); mockLocationValidator.Setup(x => x.IsValidUrl(It.IsAny <string>())).Returns(true); var controller = new GeolocationController(mockManger.Object, mockLocationValidator.Object); // Act var actionResult = controller.Delete("test") as StatusCodeResult; // Assert Assert.IsNotNull(actionResult); Assert.AreEqual(HttpStatusCode.NoContent, actionResult.StatusCode); }
public void Can_Return_BadRequest_When_Invalid_URL_Provided() { // Arrange Mock <IGeolocationDetailsManager> mockManager = new Mock <IGeolocationDetailsManager>(); Mock <ILocationValidator> mockLocationValidator = new Mock <ILocationValidator>(); mockLocationValidator.Setup(x => x.IsValidUrl(It.IsAny <string>())).Returns(false); var controller = new GeolocationController(mockManager.Object, mockLocationValidator.Object); // Act var actionResult = controller.Get(null, "url") as BadRequestErrorMessageResult; // Assert Assert.IsNotNull(actionResult); Assert.IsNotNull(actionResult.Message); }
public void Can_Reject_Create_Geolocation_Details_When_Invalid_IP_Or_URL_Provided() { // Arrange Mock <IGeolocationDetailsManager> mockManger = new Mock <IGeolocationDetailsManager>(); Mock <ILocationValidator> mockLocationValidator = new Mock <ILocationValidator>(); mockLocationValidator.Setup(x => x.IsValidIpAddress(It.IsAny <string>())).Returns(false); mockLocationValidator.Setup(x => x.IsValidUrl(It.IsAny <string>())).Returns(false); var controller = new GeolocationController(mockManger.Object, mockLocationValidator.Object); // Act var actionResult = controller.PostAsync("test").Result as BadRequestErrorMessageResult; // Assert Assert.IsNotNull(actionResult); Assert.IsNotNull(actionResult.Message); }
public void Can_Return_NotFound_When_URL_Nonexistent() { // Arrange Mock <IGeolocationDetailsManager> mockManager = new Mock <IGeolocationDetailsManager>(); mockManager.Setup(x => x.GetByUrl(It.IsAny <string>())).Returns <GetGeolocationDetailsByUrlReturnModel>(null); Mock <ILocationValidator> mockLocationValidator = new Mock <ILocationValidator>(); mockLocationValidator.Setup(x => x.IsValidUrl(It.IsAny <string>())).Returns(true); var controller = new GeolocationController(mockManager.Object, mockLocationValidator.Object); // Act var actionResult = controller.Get(null, "url") as NotFoundResult; // Assert Assert.IsNotNull(actionResult); }
/// <summary> /// Constructor /// </summary> public App() { InitializeComponent(); // Create logger Log = DependencyService.Get <ILog>(); // Create notification helper NotificationHelper = DependencyService.Get <INotificationHelper>(); // Geolocation controller // Not user specific and takes some time so created early GeolocationController = new GeolocationController(); // Create master controller MasterController = new MasterController(); // Open Login View MainPage = new NavigationPage(new LoginView()); }
public async Task Post_GeolocationDoesNotExists_ShouldBeCreated() { var command = new CreateGeolocation() { Address = "8.8.8.8" }; var geolocationServiceMock = new Mock <IGeolocationService>(); var geolocationController = new GeolocationController(geolocationServiceMock.Object); var payload = GetPayload(command); var response = await Client.PostAsync("geolocation", payload); response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.Created); response.Headers.Location.ToString().Should().BeEquivalentTo($"geolocation/{command.Address}"); var details = await GetAsync(command.Address); details.Ip.Should().Be(command.Address); details.City.Should().Be("Mountain View"); details.Longitude.Should().Be(-122.07540893554688d); details.Latitude.Should().Be(37.419158935546875d); }
public GeolocationControllerTests() { _service = new GeolocationServiceFake(); _controller = new GeolocationController(_service, _mapper); }