public void GetGeocoding_傳入Null參數_回傳FailOutPutModel()
        {
            // arrange
            // 因為是UnitTest所以HttpContext.Current會是null,所以要假造 HttpContext.Current
            HttpContext.Current = GIS.Tests.Helpers.HttpContextHelper.FakeHttpContext();

            var controller = new GoogleGeoController(this.GoogleGisService)
            {
                Configuration = new HttpConfiguration(),
                Request = new HttpRequestMessage
                {
                    Method = HttpMethod.Get,
                    RequestUri = new Uri("http://localhost/gis/googlegeo/coding?geokey=&address=")
                }
            };

            var responseId = new Guid("431C5A69-6464-422E-B79D-8A206069145C");
            controller.ResponseId = responseId;

            var parameter = new Models.ParameterModels.GeoLocationParameter
            {
                GeoKey = null,
                Address = null
            };

            // act
            Action action = () => controller.GetGeocoding(parameter);

            // assert
            action.ShouldThrow<FluentValidation.ValidationException>();
        }
        public void GetGeocoding_傳入地址_回傳SuccessOutputModel()
        {
            // arrange
            // 因為是UnitTest所以HttpContext.Current會是null,所以要假造 HttpContext.Current
            HttpContext.Current = GIS.Tests.Helpers.HttpContextHelper.FakeHttpContext();

            // 模擬 service 吐出的資料
            var googleGeoDataDto = new Service.DTOs.GoogleGeoDataDto
            {
                AllResponse = "{\"Method\":\"Geocoding\",\"OtherParams\":{\"QueryAddress\":\"台北市大安區敦化南路二段77號\",\"FixingAddress\":\"臺北市大安區敦化南路二段77號\",\"GeoKey\":\"EEPS_AP_Geocoder\",\"Channel\":\"EEPS_AP_Geocoder\",\"APIUrl\":\"http://maps.google.com/maps/api/geocode/json?components=country%3atw\\u0026address=%e8%87%ba%e5%8c%97%e5%b8%82%e5%a4%a7%e5%ae%89%e5%8d%80%e6%95%a6%e5%8c%96%e5%8d%97%e8%b7%af%e4%ba%8c%e6%ae%b577%e8%99%9f\\u0026sensor=false\\u0026language=zh-tw\\u0026region=tw\"},\"Locate\":{\"GqId\":1,\"GeoId\":4279,\"City\":\"台北市\",\"Area\":\"大安區\",\"Road\":\"敦化南路二段\",\"No\":\"\",\"Address\":\"106台灣台北市大安區敦化南路二段77號\",\"Lat\":25.030284,\"Lng\":121.549201,\"LocationType\":\"ROOFTOP\",\"PoiName\":\"\",\"PoiTypes\":\"street_address\"},\"Success\":true,\"Status\":1,\"Message\":\"查詢成功\",\"Precise\":true,\"GeoSource\":\"Database\"}",
                ErrorMessage = string.Empty,
                QueryAddress = "台北市大安區敦化南路二段77號",
                QueryLatitude = 0,
                QueryLongitude = 0,
                Locate = new Service.DTOs.GoogleLocateDto
                {
                    County = "台北市",
                    District = "大安區",
                    Road = "敦化南路二段",
                    Address = "106台灣台北市大安區敦化南路二段77號",
                    Landmark = string.Empty,
                    Longitude = 121.549201,
                    Latitude = 25.030284,
                    IsPrecise = true
                },
                Status = Infrastructure.Enums.GoogleLocateStatus.Success
            };

            this.GoogleGisService.GetGeocoding(Arg.Any<Service.DTOs.GeoLocationParameterDto>())
                .Returns(googleGeoDataDto);

            var controller = new GoogleGeoController(this.GoogleGisService)
            {
                Configuration = new HttpConfiguration(),
                Request = new HttpRequestMessage
                {
                    Method = HttpMethod.Get,
                    RequestUri = new Uri("http://localhost/gis/googlegeo/coding?geokey=EEPS_AP_Geocoder&address=台北市大安區敦化南路二段77號")
                }
            };

            var responseId = new Guid("431C5A69-6464-422E-B79D-8A206069145C");
            controller.ResponseId = responseId;

            var parameter = new Models.ParameterModels.GeoLocationParameter
            {
                GeoKey = "EEPS_AP_Geocoder",
                Address = "台北市大安區敦化南路二段77號"
            };

            // 預期資料
            var expected = new SuccessOutputModel<Models.OutputModels.GoogleGeoDataViewModel>()
            {
                ApiVersion = "1.0.0",
                Method = "/gis/googlegeo/coding.GET",
                Data = new Models.OutputModels.GoogleGeoDataViewModel()
                {
                    AllResponse = "{\"Method\":\"Geocoding\",\"OtherParams\":{\"QueryAddress\":\"台北市大安區敦化南路二段77號\",\"FixingAddress\":\"臺北市大安區敦化南路二段77號\",\"GeoKey\":\"EEPS_AP_Geocoder\",\"Channel\":\"EEPS_AP_Geocoder\",\"APIUrl\":\"http://maps.google.com/maps/api/geocode/json?components=country%3atw\\u0026address=%e8%87%ba%e5%8c%97%e5%b8%82%e5%a4%a7%e5%ae%89%e5%8d%80%e6%95%a6%e5%8c%96%e5%8d%97%e8%b7%af%e4%ba%8c%e6%ae%b577%e8%99%9f\\u0026sensor=false\\u0026language=zh-tw\\u0026region=tw\"},\"Locate\":{\"GqId\":1,\"GeoId\":4279,\"City\":\"台北市\",\"Area\":\"大安區\",\"Road\":\"敦化南路二段\",\"No\":\"\",\"Address\":\"106台灣台北市大安區敦化南路二段77號\",\"Lat\":25.030284,\"Lng\":121.549201,\"LocationType\":\"ROOFTOP\",\"PoiName\":\"\",\"PoiTypes\":\"street_address\"},\"Success\":true,\"Status\":1,\"Message\":\"查詢成功\",\"Precise\":true,\"GeoSource\":\"Database\"}",
                    ErrorMessage = string.Empty,
                    QueryAddress = "台北市大安區敦化南路二段77號",
                    QueryLatitude = 0,
                    QueryLongitude = 0,
                    Locate = new Models.OutputModels.GoogleLocateViewModel()
                    {
                        County = "台北市",
                        District = "大安區",
                        Road = "敦化南路二段",
                        Address = "106台灣台北市大安區敦化南路二段77號",
                        Landmark = string.Empty,
                        Longitude = 121.549201,
                        Latitude = 25.030284,
                        IsPrecise = true
                    },
                    Status = Infrastructure.Enums.GoogleLocateStatus.Success
                },
                Id = responseId
            };

            // act
            HttpResponseMessage actual = controller.GetGeocoding(parameter);

            SuccessOutputModel<Models.OutputModels.GoogleGeoDataViewModel> actualResultModel;
            actual.TryGetContentValue(out actualResultModel).Should().BeTrue();

            // assert
            actualResultModel.ToExpectedObject().ShouldEqual(expected);
        }
        public void GetGeocoding_傳入地標_回傳SuccessOutputModel()
        {
            // arrange
            // 因為是UnitTest所以HttpContext.Current會是null,所以要假造 HttpContext.Current
            HttpContext.Current = GIS.Tests.Helpers.HttpContextHelper.FakeHttpContext();

            // 模擬 service 吐出的資料
            var googleGeoDataDto = new Service.DTOs.GoogleGeoDataDto
            {
                AllResponse = "{\"Method\":\"Geocoding\",\"OtherParams\":{\"QueryAddress\":\"台北火車站\",\"FixingAddress\":\"台北火車站\",\"GeoKey\":\"EEPS_AP_Geocoder\",\"Channel\":\"EEPS_AP_Geocoder\",\"APIUrl\":\"http://maps.google.com/maps/api/geocode/json?components=country%3atw\\u0026address=%e5%8f%b0%e5%8c%97%e7%81%ab%e8%bb%8a%e7%ab%99\\u0026sensor=false\\u0026language=zh-tw\\u0026region=tw\",\"TaskTime\":\"00:00:00.110\"},\"Locate\":{\"GqId\":52886,\"GeoId\":88081,\"City\":\"台北市\",\"Area\":\"中正區\",\"Road\":\"\",\"No\":\"\",\"Address\":\"100台灣台北市中正區台北車站\",\"Lat\":25.0477505,\"Lng\":121.5170599,\"LocationType\":\"APPROXIMATE\",\"PoiName\":\"台北車站\",\"PoiTypes\":\"train_station,transit_station,point_of_interest,establishment\"},\"Success\":true,\"Status\":1,\"Message\":\"查詢成功\",\"Precise\":false,\"GeoSource\":\"Google\"}",
                ErrorMessage = string.Empty,
                QueryAddress = "台北火車站",
                QueryLatitude = 0,
                QueryLongitude = 0,
                Locate = new Service.DTOs.GoogleLocateDto
                {
                    County = "台北市",
                    District = "中正區",
                    Road = string.Empty,
                    Address = "100台灣台北市中正區台北車站",
                    Landmark = "台北車站",
                    Longitude = 121.5170599,
                    Latitude = 25.0477505,
                    IsPrecise = false
                },
                Status = Infrastructure.Enums.GoogleLocateStatus.Success
            };

            this.GoogleGisService.GetGeocoding(Arg.Any<Service.DTOs.GeoLocationParameterDto>())
                .Returns(googleGeoDataDto);

            var controller = new GoogleGeoController(this.GoogleGisService)
            {
                Configuration = new HttpConfiguration(),
                Request = new HttpRequestMessage
                {
                    Method = HttpMethod.Get,
                    RequestUri = new Uri("http://localhost/gis/googlegeo/coding?geokey=EEPS_AP_Geocoder&address=台北市大安區敦化南路二段77號")
                }
            };

            var responseId = new Guid("431C5A69-6464-422E-B79D-8A206069145C");
            controller.ResponseId = responseId;

            var parameter = new Models.ParameterModels.GeoLocationParameter
            {
                GeoKey = "EEPS_AP_Geocoder",
                Address = "台北火車站"
            };

            // 預期資料
            var expected = new SuccessOutputModel<Models.OutputModels.GoogleGeoDataViewModel>()
            {
                ApiVersion = "1.0.0",
                Method = "/gis/googlegeo/coding.GET",
                Data = new Models.OutputModels.GoogleGeoDataViewModel()
                {
                    AllResponse = "{\"Method\":\"Geocoding\",\"OtherParams\":{\"QueryAddress\":\"台北火車站\",\"FixingAddress\":\"台北火車站\",\"GeoKey\":\"EEPS_AP_Geocoder\",\"Channel\":\"EEPS_AP_Geocoder\",\"APIUrl\":\"http://maps.google.com/maps/api/geocode/json?components=country%3atw\\u0026address=%e5%8f%b0%e5%8c%97%e7%81%ab%e8%bb%8a%e7%ab%99\\u0026sensor=false\\u0026language=zh-tw\\u0026region=tw\",\"TaskTime\":\"00:00:00.110\"},\"Locate\":{\"GqId\":52886,\"GeoId\":88081,\"City\":\"台北市\",\"Area\":\"中正區\",\"Road\":\"\",\"No\":\"\",\"Address\":\"100台灣台北市中正區台北車站\",\"Lat\":25.0477505,\"Lng\":121.5170599,\"LocationType\":\"APPROXIMATE\",\"PoiName\":\"台北車站\",\"PoiTypes\":\"train_station,transit_station,point_of_interest,establishment\"},\"Success\":true,\"Status\":1,\"Message\":\"查詢成功\",\"Precise\":false,\"GeoSource\":\"Google\"}",
                    ErrorMessage = string.Empty,
                    QueryAddress = "台北火車站",
                    QueryLatitude = 0,
                    QueryLongitude = 0,
                    Locate = new Models.OutputModels.GoogleLocateViewModel()
                    {
                        County = "台北市",
                        District = "中正區",
                        Road = string.Empty,
                        Address = "100台灣台北市中正區台北車站",
                        Landmark = "台北車站",
                        Longitude = 121.5170599,
                        Latitude = 25.0477505,
                        IsPrecise = false
                    },
                    Status = Infrastructure.Enums.GoogleLocateStatus.Success
                },
                Id = responseId
            };

            // act
            HttpResponseMessage actual = controller.GetGeocoding(parameter);

            SuccessOutputModel<Models.OutputModels.GoogleGeoDataViewModel> actualResultModel;
            actual.TryGetContentValue(out actualResultModel).Should().BeTrue();

            // assert
            actualResultModel.ToExpectedObject().ShouldEqual(expected);
        }
        public void GetGeocoding_傳入地址地標_找不到資料_回傳預設SuccessOutputModel()
        {
            // arrange
            // 因為是UnitTest所以HttpContext.Current會是null,所以要假造 HttpContext.Current
            HttpContext.Current = GIS.Tests.Helpers.HttpContextHelper.FakeHttpContext();

            // 模擬 service 吐出的資料
            var googleGeoDataDto = new Service.DTOs.GoogleGeoDataDto();
            googleGeoDataDto.Status = Infrastructure.Enums.GoogleLocateStatus.ZeroResult;

            this.GoogleGisService.GetGeocoding(Arg.Any<Service.DTOs.GeoLocationParameterDto>())
                .Returns(googleGeoDataDto);

            var controller = new GoogleGeoController(this.GoogleGisService)
            {
                Configuration = new HttpConfiguration(),
                Request = new HttpRequestMessage
                {
                    Method = HttpMethod.Get,
                    RequestUri = new Uri("http://localhost/gis/googlegeo/coding?geokey=EEPS_AP_Geocoder&address=xxx")
                }
            };

            var responseId = new Guid("431C5A69-6464-422E-B79D-8A206069145C");
            controller.ResponseId = responseId;

            var parameter = new Models.ParameterModels.GeoLocationParameter
            {
                GeoKey = "EEPS_AP_Geocoder",
                Address = "xxx"
            };

            // 預期資料
            var expected = new SuccessOutputModel<Models.OutputModels.GoogleGeoDataViewModel>()
            {
                ApiVersion = "1.0.0",
                Method = "/gis/googlegeo/coding.GET",
                Data = new Models.OutputModels.GoogleGeoDataViewModel()
                {
                    AllResponse = null,
                    ErrorMessage = null,
                    QueryAddress = null,
                    QueryLatitude = 0,
                    QueryLongitude = 0,
                    Locate = null,
                    Status = Infrastructure.Enums.GoogleLocateStatus.ZeroResult
                },
                Id = responseId
            };

            // act
            HttpResponseMessage actual = controller.GetGeocoding(parameter);

            SuccessOutputModel<Models.OutputModels.GoogleGeoDataViewModel> actualResultModel;
            actual.TryGetContentValue(out actualResultModel).Should().BeTrue();

            // assert
            actualResultModel.ToExpectedObject().ShouldEqual(expected);
        }