public void connection_fault_is_send_when_cannot_connect() { const string invalidUrl = "localhost:8080/InvalidUrl"; var location = Substitutes.GetLocationSubstitute(); var request = Substitutes.GetGooglePlacesApiRequestSubstitute(location, invalidUrl, KeysProvider.GooglePlacesApiKey); var requestSender = Substitute.For<IRequestsSender>(); requestSender.SendRequest(request).Returns(x => { throw new Exception(); }); IGoogleMapsInterfaceService service = new global::GoogleMapsInterfaceService.GoogleMapsInterfaceService(requestSender); Assert.Throws<FaultException<ConnectionFault>>(() => service.SendGooglePlacesApiRequest(request)); }
public void request_denied_fault_is_send_when_google_places_api_key_is_invalid() { string requestUrl = GetCorrectRequestUrl(); string requestResponse = GetRequestDeniedRequestResponse(); var location = Substitutes.GetLocationSubstitute(); var request = Substitutes.GetGooglePlacesApiRequestSubstitute(location, requestUrl, "invalid key"); var requestSender = Substitute.For<IRequestsSender>(); requestSender.SendRequest(request).Returns(requestResponse); IGoogleMapsInterfaceService service = new global::GoogleMapsInterfaceService.GoogleMapsInterfaceService(requestSender); Assert.Throws<FaultException<RequestDeniedFault>>(() => service.SendGooglePlacesApiRequest(request)); }
public void invalid_response_fault_is_send_when_reveived_invalid_response() { string requestUrl = GetCorrectRequestUrl(); const string requestResponse = "i.n.v.a.l.i.d...r.e.s.p.o.n.s.e."; var location = Substitutes.GetLocationSubstitute(); var request = Substitutes.GetGooglePlacesApiRequestSubstitute(location, requestUrl, KeysProvider.GooglePlacesApiKey); var requestSender = Substitute.For<IRequestsSender>(); requestSender.SendRequest(request).Returns(requestResponse); IGoogleMapsInterfaceService service = new global::GoogleMapsInterfaceService.GoogleMapsInterfaceService(requestSender); Assert.Throws<FaultException<InvalidResponseFault>>(() => service.SendGooglePlacesApiRequest(request)); }
public void user_can_receive_correct_response() { string requestUrl = GetCorrectRequestUrl(); string requestResponse = GetCorrectRequestResponse(); var location = Substitutes.GetLocationSubstitute(); var request = Substitutes.GetGooglePlacesApiRequestSubstitute(location, requestUrl, KeysProvider.GooglePlacesApiKey); var requestSender = Substitute.For<IRequestsSender>(); requestSender.SendRequest(request).Returns(requestResponse); IGoogleMapsInterfaceService service = new global::GoogleMapsInterfaceService.GoogleMapsInterfaceService(requestSender); GooglePlacesWcfResponse response = service.SendGooglePlacesApiRequest(request); Assert.IsNotNull(response.Results); Assert.IsNotEmpty(response.Results); Assert.AreEqual(Status.Ok, response.Status); Location responseLocation = response.Results.First().Location; Assert.AreNotEqual(0.0, responseLocation.Lat); Assert.AreNotEqual(0.0, responseLocation.Lng); }