Пример #1
0
        public async Task WillSetMultipleFromEmptyGeo()
        {
            var plugin = new GeoPlugin(await GetResolverAsync(Log));

            var ev            = new PersistentEvent();
            var greenBayEvent = new PersistentEvent();

            greenBayEvent.SetEnvironmentInfo(new EnvironmentInfo {
                IpAddress = GREEN_BAY_IP
            });
            var irvingEvent = new PersistentEvent();

            irvingEvent.SetEnvironmentInfo(new EnvironmentInfo {
                IpAddress = IRVING_IP
            });
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev, OrganizationData.GenerateSampleOrganization(), ProjectData.GenerateSampleProject()),
                new EventContext(greenBayEvent, OrganizationData.GenerateSampleOrganization(), ProjectData.GenerateSampleProject()),
                new EventContext(irvingEvent, OrganizationData.GenerateSampleOrganization(), ProjectData.GenerateSampleProject())
            });

            Assert.Equal(GREEN_BAY_COORDINATES, greenBayEvent.Geo);
            var location = greenBayEvent.GetLocation();

            Assert.Equal("US", location?.Country);
            Assert.Equal("WI", location?.Level1);
            Assert.Equal("Green Bay", location?.Locality);

            Assert.Equal(IRVING_COORDINATES, irvingEvent.Geo);
            location = irvingEvent.GetLocation();
            Assert.Equal("US", location?.Country);
            Assert.Equal("TX", location?.Level1);
            Assert.Equal("Irving", location?.Locality);
        }
Пример #2
0
        public async Task WillSetLocationFromEnvironmentInfoInfo()
        {
            var resolver = await GetResolverAsync(Log);

            if (resolver is NullGeoIpService)
            {
                return;
            }

            var plugin = new GeoPlugin(resolver, _options);
            var ev     = new PersistentEvent();

            ev.SetEnvironmentInfo(new EnvironmentInfo {
                IpAddress = $"127.0.0.1,{GREEN_BAY_IP}"
            });
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev, OrganizationData.GenerateSampleOrganization(_billingManager, _plans), ProjectData.GenerateSampleProject())
            });

            Assert.NotNull(ev.Geo);

            var location = ev.GetLocation();

            Assert.Equal("US", location?.Country);
            Assert.Equal("WI", location?.Level1);
            Assert.Equal("Green Bay", location?.Locality);
        }
Пример #3
0
        public async Task WillSetFromSingleGeo()
        {
            var plugin = new GeoPlugin(await GetResolverAsync(Log));

            var contexts = new List <EventContext> {
                new EventContext(new PersistentEvent {
                    Geo = GREEN_BAY_IP
                }, OrganizationData.GenerateSampleOrganization(), ProjectData.GenerateSampleProject()),
                new EventContext(new PersistentEvent {
                    Geo = GREEN_BAY_IP
                }, OrganizationData.GenerateSampleOrganization(), ProjectData.GenerateSampleProject())
            };

            await plugin.EventBatchProcessingAsync(contexts);

            foreach (var context in contexts)
            {
                Assert.Equal(GREEN_BAY_COORDINATES, context.Event.Geo);

                var location = context.Event.GetLocation();
                Assert.Equal("US", location?.Country);
                Assert.Equal("WI", location?.Level1);
                Assert.Equal("Green Bay", location?.Locality);
            }
        }
Пример #4
0
        public async Task WillSetFromSingleGeo()
        {
            var resolver = await GetResolverAsync(Log);

            if (resolver is NullGeoIpService)
            {
                return;
            }

            var plugin = new GeoPlugin(resolver, _options);

            var contexts = new List <EventContext> {
                new EventContext(new PersistentEvent {
                    Geo = GREEN_BAY_IP
                }, OrganizationData.GenerateSampleOrganization(_billingManager, _plans), ProjectData.GenerateSampleProject()),
                new EventContext(new PersistentEvent {
                    Geo = GREEN_BAY_IP
                }, OrganizationData.GenerateSampleOrganization(_billingManager, _plans), ProjectData.GenerateSampleProject())
            };

            await plugin.EventBatchProcessingAsync(contexts);

            foreach (var context in contexts)
            {
                AssertCoordinatesAreEqual(GREEN_BAY_COORDINATES, context.Event.Geo);

                var location = context.Event.GetLocation();
                Assert.Equal("US", location?.Country);
                Assert.Equal("WI", location?.Level1);
                Assert.Equal("Green Bay", location?.Locality);
            }
        }
Пример #5
0
        public async Task WillNotSetFromMultipleGeo()
        {
            var plugin = new GeoPlugin(await GetResolverAsync(Log));

            var ev            = new PersistentEvent();
            var greenBayEvent = new PersistentEvent {
                Geo = GREEN_BAY_IP
            };
            var irvingEvent = new PersistentEvent {
                Geo = IRVING_IP
            };
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev),
                new EventContext(greenBayEvent),
                new EventContext(irvingEvent)
            });

            Assert.Equal(GREEN_BAY_COORDINATES, greenBayEvent.Geo);
            var location = greenBayEvent.GetLocation();

            Assert.Equal("US", location?.Country);
            Assert.Equal("WI", location?.Level1);
            Assert.Equal("Green Bay", location?.Locality);

            Assert.Equal(IRVING_COORDINATES, irvingEvent.Geo);
            location = irvingEvent.GetLocation();
            Assert.Equal("US", location?.Country);
            Assert.Equal("TX", location?.Level1);
            Assert.Equal("Irving", location?.Locality);
        }
Пример #6
0
        public async Task WillNotSetFromMultipleGeo()
        {
            var plugin = new GeoPlugin(await GetResolverAsync(Log), _options);

            var ev            = new PersistentEvent();
            var greenBayEvent = new PersistentEvent {
                Geo = GREEN_BAY_IP
            };
            var irvingEvent = new PersistentEvent {
                Geo = IRVING_IP
            };
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev, OrganizationData.GenerateSampleOrganization(_billingManager, _plans), ProjectData.GenerateSampleProject()),
                new EventContext(greenBayEvent, OrganizationData.GenerateSampleOrganization(_billingManager, _plans), ProjectData.GenerateSampleProject()),
                new EventContext(irvingEvent, OrganizationData.GenerateSampleOrganization(_billingManager, _plans), ProjectData.GenerateSampleProject())
            });

            Assert.Equal(GREEN_BAY_COORDINATES, greenBayEvent.Geo);
            var location = greenBayEvent.GetLocation();

            Assert.Equal("US", location?.Country);
            Assert.Equal("WI", location?.Level1);
            Assert.Equal("Green Bay", location?.Locality);

            Assert.Equal(IRVING_COORDINATES, irvingEvent.Geo);
            location = irvingEvent.GetLocation();
            Assert.Equal("US", location?.Country);
            Assert.Equal("TX", location?.Level1);
            Assert.Equal("Irving", location?.Locality);
        }
Пример #7
0
        public async Task WillNotSetLocation()
        {
            var plugin = new GeoPlugin(await GetResolverAsync(Log));
            var ev     = new PersistentEvent {
                Geo = GREEN_BAY_COORDINATES
            };
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev, OrganizationData.GenerateSampleOrganization(), ProjectData.GenerateSampleProject())
            });

            Assert.Equal(GREEN_BAY_COORDINATES, ev.Geo);
            Assert.Null(ev.GetLocation());
        }
Пример #8
0
        public async Task WillNotSetLocation()
        {
            var plugin = new GeoPlugin(await GetResolverAsync());
            var ev     = new PersistentEvent {
                Geo = GREEN_BAY_COORDINATES
            };
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev)
            });

            Assert.Equal(GREEN_BAY_COORDINATES, ev.Geo);
            Assert.Null(ev.GetLocation());
        }
Пример #9
0
        public async Task WillResetLocation(string geo)
        {
            var plugin = new GeoPlugin(await GetResolverAsync(Log));

            var ev = new PersistentEvent {
                Geo = geo
            };
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev, OrganizationData.GenerateSampleOrganization(), ProjectData.GenerateSampleProject())
            });

            Assert.Null(ev.Geo);
            Assert.Null(ev.GetLocation());
        }
Пример #10
0
        public async Task WillResetLocation(string geo)
        {
            var plugin = new GeoPlugin(await GetResolverAsync());

            var ev = new PersistentEvent {
                Geo = geo
            };
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev)
            });

            Assert.Null(ev.Geo);
            Assert.Null(ev.GetLocation());
        }
Пример #11
0
        public async Task WillSetLocationFromGeo()
        {
            var plugin = new GeoPlugin(await GetResolverAsync(Log));
            var ev     = new PersistentEvent {
                Geo = GREEN_BAY_IP
            };
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev, OrganizationData.GenerateSampleOrganization(), ProjectData.GenerateSampleProject())
            });

            Assert.NotNull(ev.Geo);
            Assert.NotEqual(GREEN_BAY_IP, ev.Geo);

            var location = ev.GetLocation();

            Assert.Equal("US", location?.Country);
            Assert.Equal("WI", location?.Level1);
            Assert.Equal("Green Bay", location?.Locality);
        }
Пример #12
0
        public async Task WillResetLocation(string geo)
        {
            var resolver = await GetResolverAsync(Log);

            if (resolver is NullGeoIpService)
            {
                return;
            }

            var plugin = new GeoPlugin(resolver, _options);
            var ev     = new PersistentEvent {
                Geo = geo
            };
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev, OrganizationData.GenerateSampleOrganization(_billingManager, _plans), ProjectData.GenerateSampleProject())
            });

            Assert.Null(ev.Geo);
            Assert.Null(ev.GetLocation());
        }
Пример #13
0
        public async Task WillSetLocationFromRequestInfo()
        {
            var plugin = new GeoPlugin(await GetResolverAsync(Log), _options);
            var ev     = new PersistentEvent();

            ev.AddRequestInfo(new RequestInfo {
                ClientIpAddress = GREEN_BAY_IP
            });
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev, OrganizationData.GenerateSampleOrganization(_billingManager, _plans), ProjectData.GenerateSampleProject())
            });

            Assert.NotNull(ev.Geo);

            var location = ev.GetLocation();

            Assert.Equal("US", location?.Country);
            Assert.Equal("WI", location?.Level1);
            Assert.Equal("Green Bay", location?.Locality);
        }
Пример #14
0
        public async Task WillSetLocationFromEnvironmentInfoInfo()
        {
            var plugin = new GeoPlugin(await GetResolverAsync(Log));
            var ev     = new PersistentEvent();

            ev.SetEnvironmentInfo(new EnvironmentInfo {
                IpAddress = $"127.0.0.1,{GREEN_BAY_IP}"
            });
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev)
            });

            Assert.NotNull(ev.Geo);

            var location = ev.GetLocation();

            Assert.Equal("US", location?.Country);
            Assert.Equal("WI", location?.Level1);
            Assert.Equal("Green Bay", location?.Locality);
        }
Пример #15
0
        public async Task WillSetLocationFromRequestInfo()
        {
            var plugin = new GeoPlugin(await GetResolverAsync());
            var ev     = new PersistentEvent();

            ev.AddRequestInfo(new RequestInfo {
                ClientIpAddress = GREEN_BAY_IP
            });
            await plugin.EventBatchProcessingAsync(new List <EventContext> {
                new EventContext(ev)
            });

            Assert.NotNull(ev.Geo);

            var location = ev.GetLocation();

            Assert.Equal("US", location?.Country);
            Assert.Equal("WI", location?.Level1);
            Assert.Equal("Green Bay", location?.Locality);
        }