Example #1
0
        public void TestGeoCodeWithAddress()
        {
            var logger  = new MemoryLogger(LogLevel.Debug);
            var process = GetTestProcess("google-geocode");

            if (process.Errors().Any())
            {
                foreach (var error in process.Errors())
                {
                    Console.WriteLine(error);
                }
                throw new Exception("The configuration has errors");
            }

            var input = new MasterRow(process.GetAllFields().Count());

            var address          = process.Entities.First().Fields.First(f => f.Name == "Address");
            var latitude         = process.Entities.First().CalculatedFields.First(f => f.Name == "Latitude");
            var longitude        = process.Entities.First().CalculatedFields.First(f => f.Name == "Longitude");
            var formattedAddress = process.Entities.First().CalculatedFields.First(f => f.Name == "FormattedAddress");
            var state            = process.Entities.First().CalculatedFields.First(f => f.Name == "State");
            var county           = process.Entities.First().CalculatedFields.First(f => f.Name == "County");
            var partialMatch     = process.Entities.First().CalculatedFields.First(f => f.Name == "PartialMatch");
            var locality         = process.Entities.First().CalculatedFields.First(f => f.Name == "Locality");

            input[address]          = "1009 Broad Street St. Joseph MI 49085";
            input[latitude]         = null;
            input[longitude]        = null;
            input[formattedAddress] = null;

            var context = new PipelineContext(logger, process, process.Entities.First(), address, address.Transforms.First());

            using (var gt = new GeocodeTransform(context)) {
                var output = gt.Operate(input);

                Assert.AreEqual("1009 Broad Street St. Joseph MI 49085", output[address]);
                Assert.AreEqual("MI", output[state]);
                Assert.AreEqual(false, output[partialMatch]);
                Assert.AreEqual("Berrien County", output[county]);
                Assert.AreEqual("St Joseph", output[locality]);
                Assert.IsNotNull(output[latitude]);
                Assert.IsNotNull(output[longitude]);
                Assert.IsNotNull(output[formattedAddress]);
            }
        }
Example #2
0
        public void TestGeoCodeWithPlaceId()
        {
            var logger  = new MemoryLogger(LogLevel.Debug);
            var process = GetTestProcess("google-geocode");

            if (process.Errors().Any())
            {
                foreach (var error in process.Errors())
                {
                    Console.WriteLine(error);
                }
                throw new Exception("The configuration has errors");
            }

            var input = new MasterRow(process.GetAllFields().Count());

            var address          = process.Entities.First().Fields.First(f => f.Name == "Address");
            var latitude         = process.Entities.First().CalculatedFields.First(f => f.Name == "Latitude");
            var longitude        = process.Entities.First().CalculatedFields.First(f => f.Name == "Longitude");
            var formattedAddress = process.Entities.First().CalculatedFields.First(f => f.Name == "FormattedAddress");

            input[address]          = "ChIJsxyoG5_GEIgRMN8IWvngddA";
            input[latitude]         = null;
            input[longitude]        = null;
            input[formattedAddress] = null;

            var context = new PipelineContext(logger, process, process.Entities.First(), address, address.Transforms.First());

            using (var gt = new GeocodeTransform(context)) {
                var output = gt.Operate(input);

                Assert.AreEqual("ChIJsxyoG5_GEIgRMN8IWvngddA", output[address]);
                Assert.IsNotNull(output[latitude]);
                Assert.IsNotNull(output[longitude]);
                Assert.IsNotNull(output[formattedAddress]);
            }
        }