public static async Task TestRequestByIdentity(IAnalyticStore store) { foreach (var request in MatteoRequests) { await store.StoreWebRequestAsync(request); } foreach (var request in FrancoRequests) { await store.StoreWebRequestAsync(request); } Assert.Equal(MatteoRequests.Length, (await store.RequestByIdentityAsync("MATTEO")).Count()); Assert.Equal(FrancoRequests.Length, (await store.RequestByIdentityAsync("FRANCO")).Count()); }
internal async Task Run(HttpContext context, Func <Task> next) { //Pass the command to the next task in the pipeline await next.Invoke(); //This request should be filtered out ? if (_exclude?.Any(x => x(context)) ?? false) { return; } //Let's build our structure with collected data var req = new WebRequest { Timestamp = DateTime.Now, Identity = context.UserIdentity(), RemoteIpAddress = context.Connection.RemoteIpAddress, Method = context.Request.Method, UserAgent = context.Request.Headers["User-Agent"], Path = context.Request.Path.Value, IsWebSocket = context.WebSockets.IsWebSocketRequest, //Ask the store to resolve the geo code of gived ip address CountryCode = await _store.ResolveCountryCodeAsync(context.Connection.RemoteIpAddress) }; //Store the request into the store await _store.StoreWebRequestAsync(req); }
internal async Task Run(HttpContext context, Func <Task> next) { if (_exclude?.Any(x => x(context)) ?? false) { await next.Invoke(); return; } var req = new WebRequest { Timestamp = DateTime.Now, Identity = context.UserIdentity(), RemoteIpAddress = context.Connection.RemoteIpAddress, Method = context.Request.Method, UserAgent = context.Request.Headers["User-Agent"], Path = context.Request.Path.Value, IsWebSocket = context.WebSockets.IsWebSocketRequest, CountryCode = await _store.ResolveCountryCodeAsync(context.Connection.RemoteIpAddress) }; await _store.StoreWebRequestAsync(req); await next.Invoke(); }
public static async Task TestCountIdentities(IAnalyticStore store) { foreach (var request in MatteoRequests) { await store.StoreWebRequestAsync(request); } Assert.Equal(1, await store.CountUniqueIndentitiesAsync(DateTime.Today)); Assert.Equal(1, await store.CountUniqueIndentitiesAsync(DateTime.MinValue, DateTime.MaxValue)); foreach (var request in FrancoRequests) { await store.StoreWebRequestAsync(request); } Assert.Equal(2, await store.CountUniqueIndentitiesAsync(DateTime.Today)); Assert.Equal(2, await store.CountUniqueIndentitiesAsync(DateTime.MinValue, DateTime.MaxValue)); }
public static async Task TestCount(IAnalyticStore store) { foreach (var request in MatteoRequests) { await store.StoreWebRequestAsync(request); } Assert.Equal(MatteoRequests.Length, await store.CountAsync(DateTime.MinValue, DateTime.MaxValue)); }
public static async Task TestIpAddress(IAnalyticStore store) { foreach (var request in MatteoRequests) { await store.StoreWebRequestAsync(request); } var ips = (await store.IpAddressesAsync(DateTime.Today)); Assert.Single(ips); Assert.Single((await store.IpAddressesAsync(DateTime.MinValue, DateTime.MaxValue))); }
private static async Task LoadDemoData(IAnalyticStore analyticStore) { var countries = Enum.GetValues(typeof(CountryCode)).Cast <CountryCode>().ToArray(); var methods = new[] { "GET", "POST", "DELETE", "CHICKEN" }; var urls = new[] { "/", "/home", "/contact", "/about" }; var rand = new Random(); for (int i = 0; i < 250; i++) { await analyticStore.StoreWebRequestAsync(new WebRequest { CountryCode = countries[rand.Next(countries.Length - 1)], Identity = Guid.NewGuid().ToString("N"), IsWebSocket = rand.Next() % 2 == 0, Method = methods[rand.Next(methods.Length - 1)], Path = urls[rand.Next(urls.Length - 1)], Referer = "", RemoteIpAddress = IPAddress.Loopback, Timestamp = DateTime.Now - TimeSpan.FromSeconds(rand.Next(3600 * 24 * 12)), UserAgent = "Demo data" }); } }
public static async Task TestStorage(IAnalyticStore store) { await store.StoreWebRequestAsync(MatteoRequests[0]); }
public Task StoreWebRequestAsync(WebRequest request) { return(store.StoreWebRequestAsync(request)); }